基于小波变换的图像融合

  1. clc;  
  2. clear all;  
  3. close all;                        % 清理工作空间  
  4. clear  
  5. [imA,map1] = imread('A.tif');  
  6. M1 = double(imA) / 256;  
  7. [imB,map2] = imread('B.tif');  
  8. M2 = double(imB) / 256;  
  9.   
  10.   
  11. zt= 4;   
  12. wtype = 'haar';  
  13. %    M1 - input image A  
  14. %    M2 - input image B  
  15. %    wtype使用的小波类型  
  16. %    Y  - fused image     
  17. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
  18. %%  
  19. %%  小波变换图像融合  
  20. %%  
  21. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
  22. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
  23. %%   小波变换的绝对值大的小波系数,对应着显著的亮度变化,也就是图像中的显著特征。所以,选择绝对值大  
  24. %%   的小波系数作为我们需要的小波系数。【注意,前面取的是绝对值大小,而不是实际数值大小】  
  25. %%  
  26. %%   低频部分系数采用二者求平均的方法  
  27. %%  
  28. %%  
  29. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
  30.   
  31. [c0,s0] = wavedec2(M1, zt, wtype);%多尺度二维小波分解  
  32.   
  33. [c1,s1] = wavedec2(M2, zt, wtype);%多尺度二维小波分解  
  34.   
  35. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
  36. %%  后面就可以进行取大进行处理。然后进行重构,得到一个图像  
  37. %%  的小波系数,然后重构出总的图像效果。  
  38. %%  取绝对值大的小波系数,作为融合后的小波系数  
  39. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
  40. KK = size(c1);  
  41. Coef_Fusion = zeros(1,KK(2));  
  42. Temp = zeros(1,2);  
  43. Coef_Fusion(1:s1(1,1)) = (c0(1:s1(1,1))+c1(1:s1(1,1)))/2;  %低频系数的处理  
  44.                      %这儿,连高频系数一起处理了,但是后面处理高频系数的时候,会将结果覆盖,所以没有关系  
  45.   
  46.    %处理高频系数  
  47.     MM1 = c0(s1(1,1)+1:KK(2));  
  48.     MM2 = c1(s1(1,1)+1:KK(2));  
  49.     mm = (abs(MM1)) > (abs(MM2));  
  50.     Y  = (mm.*MM1) + ((~mm).*MM2);  
  51.     Coef_Fusion(s1(1,1)+1:KK(2)) = Y;  
  52.     %处理高频系数end  
  53.    
  54.  %重构  
  55.  Y = waverec2(Coef_Fusion,s0,wtype);  
  56.   
  57. %显示图像    
  58. subplot(2,2,1);imshow(M1);  
  59. colormap(gray);  
  60. title('input2');  
  61. axis square    
  62.    
  63. subplot(2,2,2);imshow(M2);  
  64. colormap(gray);  
  65. title('input2');  
  66. axis square    
  67.   
  68. subplot(223);imshow(Y,[]);  
  69. colormap(gray);  
  70. title('融合图像');  
  71. axis square;  
  72. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
  73.    

效果图:

基于小波变换的图像融合_第1张图片

你可能感兴趣的:(重构,matlab)