www.gusucode.com > 红外图像增强及目标检测演示界面matlab源码程序 > code/ImFusion.m

    function  ImFusion
  H=msgbox('读入多光谱图像pan');
  waitfor(H);
  pan=U_Open;
  if (pan==0) errordlg('图像打开失败');break; end
  pan=im2double(pan);
  H=msgbox('读入高分辨率图像spot');
   waitfor(H);
   clear H;
  spot=U_Open;
  if (spot==0) errordlg('图像打开失败');break; end
  spot=im2double(spot);
  tic
  global FusionLabel
  if(FusionLabel==1)
       fusion=Fusion_HIS(spot,pan);
   elseif(FusionLabel==2)
       fusion=Fusion_wave(spot,pan);
   elseif(FusionLabel==3)
       fusion=Fusion_hsi_mwt(spot,pan);
   end
  time=toc;
  figure;
  subplot(2,2,1); 
  colormap(gray);
  imagesc(spot);
  title('origien spot image ');
  subplot(2,2,2); 
  image(pan);
  title('origien  pan image ');
  subplot(2,2,3); 
  image(fusion);
  title('fusion image');
  msgbox(['所用时间',num2str(time),'秒']);
 
  %=====================================================
  function fusion=Fusion_HIS(spot,pan)
  [x y ]=size(spot);
  hsv=rgb2hsv(pan);
  m1=mean2(hsv(:,:,3));
  v1=std2(hsv(:,:,3));
  m2=mean2(spot);
  v2=std2(spot);
  a=v1/v2;  b=m1-v1/v2*m2;
  spot=a*spot+b;
  hsv(:,:,3)=spot;
  fusion=abs(hsv2rgb(hsv)); 
 %=====================================================
function  fusion=Fusion_wave(spot,pan)
 %提取多光谱图像rgb三分量
 [x y z]=size(pan);
 r=pan(1:x,1:y,1);
 g=pan(1:x,1:y,2);
 b=pan(1:x,1:y,3);
 %对多光谱图像rgb三分量进行一次小波分解
 [Ar,Hr,Vr,Dr] = DWT2(r,'db4');
 [Ag,Hg,Vg,Dg] = DWT2(g,'db4');
 [Ab,Hb,Vb,Db] = DWT2(b,'db4');
 %对高分辨率图像进行一次小波分解
 [A,H,V,D] = DWT2(spot,'db4');
 %将分别rgb三高频分量用高分辨率的高频分量替换,进行图像融合
  r=IDWT2(Ar,H,V,D,'db4');
  g=IDWT2(Ag,H,V,D,'db4');
  b=IDWT2(Ab,H,V,D,'db4');
 
 fusion(1:x,1:y,1)=r;
 fusion(1:x,1:y,2)=g;
 fusion(1:x,1:y,3)=b;
 %确保融合图像数据在[0 1]之间,加绝对值,是因为小波变换可能将数据变成了负的
 fusion=abs(fusion/max(fusion(:)));
 %=====================================================
 function  fusion=Fusion_hsi_mwt(spot,pan)
 %多小波采用Cl小波
   hsv=rgb2hsv(pan);
   hsv=im2double(hsv);
    m1=mean2(hsv(:,:,3));
   v1=std2(hsv(:,:,3));
   m2=mean2(spot);
   v2=std2(spot);
   a=v1/v2;  b=m1-v1/v2*m2;
   spot=a*spot+b;
   fp=prep2D_appe(hsv(:,:,3),'clap');
   transfv=dec2D_pe(fp,'cl',1);
   fp=prep2D_appe(spot,'clap');
   transf1=dec2D_pe(fp,'cl',1);
   [row col]=size(transf1);
   transf=transf1;
   transf(1:row/4,1:col/4)=transf1(1:row/4,1:col/4);
   for x=2:(row-1)
       for y=2:(col-1)
           if (~((x<=row/4)&(y<=col/4)))
              e1=(transf1(x,y)*8+transf1(x,y-1)+transf1(x,y+1)+...
                  transf1(x-1,y-1)+transf1(x-1,y)+transf1(x-1,y+1)+...
                  transf1(x+1,y-1)+transf1(x+1,y)+transf1(x+1,y+1))/16;
             e2=(transfv(x,y)*8+transfv(x,y-1)+transfv(x,y+1)+...
                transfv(x-1,y-1)+transfv(x-1,y)+transfv(x-1,y+1)+...
                 transfv(x+1,y-1)+transfv(x+1,y)+transf1(x+1,y+1))/16;
             if(e1>=e2)
                transf(x,y)=transf1(x,y);
            end
         end
    end
 end
  fhatp=rec2D_pe(transf,'cl',1);
  fhat=postp2D_appe(fhatp,'clap');
  hsv(:,:,3)=fhat;
  fusion=abs(hsv2rgb(hsv));