基于小波变换的图像融合

原理大家翻书去,最近做个小作业,做到了关于小波变换的图像融合。

clc;
clear all;
close all;                        % 清理工作空间
clear
[imA,map1] = imread('A.tif');
M1 = double(imA) / 256;
[imB,map2] = imread('B.tif');
M2 = double(imB) / 256;


zt= 4; 
wtype = 'haar';
%    M1 - input image A
%    M2 - input image B
%    wtype使用的小波类型
%    Y  - fused image   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%%  小波变换图像融合
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%   小波变换的绝对值大的小波系数,对应着显著的亮度变化,也就是图像中的显著特征。所以,选择绝对值大
%%   的小波系数作为我们需要的小波系数。【注意,前面取的是绝对值大小,而不是实际数值大小】
%%
%%   低频部分系数采用二者求平均的方法
%%
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[c0,s0] = wavedec2(M1, zt, wtype);%多尺度二维小波分解

[c1,s1] = wavedec2(M2, zt, wtype);%多尺度二维小波分解

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  后面就可以进行取大进行处理。然后进行重构,得到一个图像
%%  的小波系数,然后重构出总的图像效果。
%%  取绝对值大的小波系数,作为融合后的小波系数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
KK = size(c1);
Coef_Fusion = zeros(1,KK(2));
Temp = zeros(1,2);
Coef_Fusion(1:s1(1,1)) = (c0(1:s1(1,1))+c1(1:s1(1,1)))/2;  %低频系数的处理
                     %这儿,连高频系数一起处理了,但是后面处理高频系数的时候,会将结果覆盖,所以没有关系

   %处理高频系数
    MM1 = c0(s1(1,1)+1:KK(2));
    MM2 = c1(s1(1,1)+1:KK(2));
    mm = (abs(MM1)) > (abs(MM2));
  	Y  = (mm.*MM1) + ((~mm).*MM2);
    Coef_Fusion(s1(1,1)+1:KK(2)) = Y;
    %处理高频系数end
 
 %重构
 Y = waverec2(Coef_Fusion,s0,wtype);

%显示图像  
subplot(2,2,1);imshow(M1);
colormap(gray);
title('input2');
axis square  
 
subplot(2,2,2);imshow(M2);
colormap(gray);
title('input2');
axis square  

subplot(223);imshow(Y,[]);
colormap(gray);
title('融合图像');
axis square;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 


 

效果图:

你可能感兴趣的:(基于小波变换的图像融合)