• 大小: 62KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: Matlab
  • 标签:

资源简介

用Matlab实现的灰度图像转换成RGB图像,效果不错

资源截图

代码片段和文件信息

function R=gray2rgb(img1img2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This Program converts a gray image ro RGB image based on the colors of the destination image. The better the destination image match with the source   %
%gray image the better the coloring will be. The program takes some time  as the searching time is high. You can decrease the searching time by taking %
%only samples from the used color image but quality may decrease. U can use jittered sampling for improving running speed.                              %
%                                                                                                                                                       %
%  You can use also use the attahed test images Use the following combinations for better result nature1.jpg(as img1) and nature2.jpg(as img2)  or     % 
%  test1.jpg(as img1) and test2.jpg (as img2)
%                                                                                                                                                       %
%                                                                                                                                                       %
% Usage                                                                                                                                                 %
% gray2rgb(‘nature1.jpg‘‘nature2.jpg‘);  

%                                                                                                                                                       %
%               Authors : Jeny Rajan                                                                                                                    %
%                         Chandrashekar P.S                                                                                                             %                                     
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                    

% img1 - Source Image  (gray image)                                                                                                        
% img2 - Selected color image for coloring the gray image. 
tic
clc;
warning off;
imt=imread(img1);
ims=imread(img2);
[sx sy sz]=size(imt);
[tx ty tz]=size(ims);
if sz~=1
    imt=rgb2gray(imt);
end
if tz~=3
    disp (‘img2 must be a color image (not indexed)‘);
else
    imt(::2)=imt(::1);
    imt(::3)=imt(::1);
   
% Converting to ycbcr color space
    nspace1=rgb2ycbcr(ims);
    nspace2= rgb2ycbcr(imt);

    ms=double(nspace1(::1));
    mt=double(nspace2(::1));
    m1=max(max(ms));
    m2=min(min(ms));
    m3=max(max(mt));
    m4=min(min(mt));
    d1=m1-m2;
    d2=m3-m4;
% Normalization
    dx1=ms;
    dx2

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        3721  2005-08-09 11:03  gray2rgb.m
     文件       15994  2005-08-04 11:18  nature2.jpg
     文件        9730  2005-08-04 11:19  nature1.jpg
     文件       15141  2005-08-09 11:00  test2.jpg
     文件       23938  2005-08-09 11:00  test1.jpg

评论

共有 条评论

相关资源