• 大小: 950B
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: Matlab
  • 标签: matlab  图像合成  

资源简介

《MATLAB图像合成及其实现》 陶胜,[M] 智慧秘籍

资源截图

代码片段和文件信息

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   this program is based in the following article
% 《MATLAB图像合成及其实现》 陶胜,[M] 智慧秘籍       
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all;
 clear;
%读入第一个图像
filename1=‘test.bmp‘;
info=imfinfo(‘test.bmp‘)
width1=info.Width;
height1=info.Height;
if strcmp(info.ColorType‘grayscale‘)==1
    [AMAP]=gray2ind(imread(filename1));
    RGB1=ind2rgb(AMAP);
end
if strcmp(info.ColorType‘indexed‘)==1
    [AMAP]=imread(filename1);
    RGB1=ind2rgb(AMAP);
end
if strcmp(info.ColorType‘truecolor‘)==1
    RGB1=imread(filename1);
end
figureimshow(RGB1);
% 读入第二个图像scene.png
filename2=‘l.jpg‘;
info1=imfinfo(filename2);
width2=info1.Width;
height2=info1.Height;
if strcmp(info1.ColorType‘grayscale‘)==1
    [AMAP]=gray2ind(imread(filename2));
    RGB2=ind2rgb(AMAP);
end
if strcmp(info1.ColorType‘indexed‘)==1
    [AMAP]=imread(filename2);
    RGB2=ind2rgb(AMAP);
end
if strcmp(info1.ColorType‘truecolor‘)==1
    RGB2=imread(filename2);
end
figureimshow(RGB2);
%得到参考图像
BW=~im2bw(RGB1);
B=imfill(imfill(BW[11]4)[1width1]4);
B=~xor(BWB);
%对第一个图像进行预处理
A=im2double(RGB1);
D=zeros(height1width1);
k=3;
for i=1:1:height1
    for j=1:1:width1
        if B(ij)==0
            A(ij1)=0;
            A(ij2)=0;
            A(ij3)=1.0;
        else
            for k=1:1:k
                N(k)=B(ij+k-round(k/2));
            end
            if ~all(N)
                if ~isempty(find(N==1))
                    k1=1;k2=-1;
                    while 1
                        r=A(ij+k11);
                        g=A(ij+k12);
                        b=A(ij+k13);
                        if B(ij+k1)==1
                            break;
                        end
                        r=A(ij+k21);
                        g=A(ij+k22);
                        b=A(ij+k23);
                        if B(ij+k2)==1
                            break;
                        end
                        k1=k1+1;k2=k2-1;
                    end
                    A(ij1)=r;
                    A(ij2)=g;
                    A(ij3)=b;
                    D(ij)=1;
                end
            end
        end
    end
end
x=20;y=10;
RGB=im2double(RGB2);
%融合图像
for i=1:1:height1
    for j=1:1:width1
        if B(ij)==1
            if D(ij)==1
                RGB(y+ix+j1)=0.5*A(ij1)+0.5*RGB(y+ix+j1);
                RGB(y+ix+j2)=0.5*A(ij2)+0.5*RGB(y+ix+j2);
                RGB(y+ix+j3)=0.5*A(ij3)+0.5*RGB(y+ix+j3);
            else
                RGB(y+ix+j1)=A(ij1);
                RGB(y+ix+j2)=A(ij2);
                RGB(y+ix+j3)=A(ij3);
            end
        end
    end
end
figureimshow(RGB);
          
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2950  2009-05-10 10:47  imagecoin.m

----------- ---------  ---------- -----  ----

                 2950                    1


评论

共有 条评论