简体   繁体   English

使用平稳小波变换(SWT)(MATLAB)的图像融合

[英]Image Fusion using stationary wavelet transform (SWT) (MATLAB)

I'm trying to fuse two images using SWT. 我正在尝试使用SWT融合两个图像。 But I'm getting this error : 但是我得到这个错误:

The level of decomposition 1 分解等级1
and the size of the image (1,5) 和图像的大小(1,5)
are not compatible. 不兼容。
Suggested size: (2,6) 建议尺寸:(2,6)

How to change the size of the image to make it compatible for transform? 如何更改图像的大小以使其兼容转换?

Code I've used is : 我使用的代码是:

        clc
        i=1;
        fol=1;
        n=0;          


      for fol=1:5
      f='folder';
      folder = strcat(f, num2str(fol)); 
      cd(folder)
      d= numel(D);
      i=(n+1);
      Fname1 = strcat(int2str(i),'.bmp');
      Fname2 = strcat(int2str(i+1),'.bmp');

      im1 = imread(Fname1);
      im2 = imread(Fname2);

      im1=double(im1);
      im2=double(im2);
      % image decomposition using discrete stationary wavelet transform
     [A1L1,H1L1,V1L1,D1L1] = swt2(im1,1,'sym2');
     [A2L1,H2L1,V2L1,D2L1] = swt2(im2,1,'sym2');

     %  fusion start
     AfL1 = 0.5*(A1L1+A2L1);
     D = (abs(H1L1)-abs(H2L1))>=0;
     HfL1 = D.*H1L1 + (~D).*H2L1;
      D = (abs(V1L1)-abs(V2L1))>=0;
     VfL1 = D.*V1L1 + (~D).*V2L1;
     D = (abs(D1L1)-abs(D2L1))>=0;
      DfL1 = D.*D1L1 + (~D).*D2L1;

      % fused image
     imf = iswt2(AfL1,HfL1,VfL1,DfL1,'sym2');
     figure; 
     imshow(imf,[]); 
     Iname= strcat(int2str(fol),'.bmp');  
     imwrite(imf,Iname);
     end

To address your first problem, that image is really small. 为了解决您的第一个问题,该图像很小。 I'm assuming that's an image of size 1 x 5. I would suggest changing your image so that it's larger, or perhaps do an imresize on the image. 我假设这是一张尺寸为1 x 5的图像。我建议您更改图像,使其更大,或者对图像进行imresize However, as what Ander said in his comment to you... I wouldn't call a 1 x 5 matrix an image. 但是,正如安德在对您的评论中所说的那样……我不会将1 x 5矩阵称为图像。

To address your second problem, once you finally load in an image, the wavelet transform will most likely give you floating point numbers that are beyond the dynamic range of any sensible floating point precision image. 为了解决第二个问题,一旦最终加载图像,小波变换很可能会为您提供超出任何有意义的浮点精度图像的动态范围的浮点数。 As such, it's good that you normalize the image first, then save it to file. 因此,最好先对图像进行标准化 ,然后再将其保存到文件中。

Therefore, do this right before you save the image: 因此,请在保存图像之前立即执行以下操作:

%// ...
%// Your code...
imshow(imf,[]); 

%// Normalize the image - Change
imf = (imf - min(imf(:))) / (max(imf(:)) - min(imf(:)));

%// Your code again
%// Now save
Iname= strcat(int2str(fol),'.bmp');  
imwrite(imf,Iname);

The above transformation normalizes an image so that the minimum is 0 and the maximum is 1. Once you do that, it should be visualized properly. 上面的转换对图像进行了归一化处理,因此最小值为0,最大值为1。执行此操作后,应将其正确可视化。 FWIW, doing imshow(imf,[]); FWIW,执行imshow(imf,[]); does this normalization for you and displays that result, but it doesn't modify the image. 为您执行此归一化并显示结果,但不会修改图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM