简体   繁体   中英

Image Fusion using stationary wavelet transform (SWT) (MATLAB)

I'm trying to fuse two images using SWT. But I'm getting this error :

The level of decomposition 1
and the size of the image (1,5)
are not compatible.
Suggested size: (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. However, as what Ander said in his comment to you... I wouldn't call a 1 x 5 matrix an image.

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. FWIW, doing imshow(imf,[]); does this normalization for you and displays that result, but it doesn't modify the image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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