2

I'm trying to implement a simple Image super resolution algorithm (DWT-Based Resolution Enhancement ) in the following paper

http://www.ripublication.com/aeee/52_pp%20%20%20405-412.pdf

I tried to implement the algorithm in figure 3 of this paper using Matlab.Code is given below.

img1 = imread('lena1.jpg'); %original High resolution image
[height, width, dim] = size(img1);

%%Downsampling the image by averaging
avgfilter = fspecial('average', [2 2]);
avgimg = filter2(avgfilter, img1);
img = avgimg(1:2:end,1:2:end); %Input low resolution image

[LL,LH,HL,HH] = dwt2(img,'haar'); %Decomposing

%Bicubic interpolation by factor 2 on each subbands
LL1 = imresize(LL,2,'bicubic');
LH1 = imresize(LH,2,'bicubic');
HL1 = imresize(HL,2,'bicubic');
HH1 = imresize(HH,2,'bicubic');

%% Calculating Difference image
for i=1:256
    for j=1:256
        img3(i,j,:) = img(i,j,:) - LL1(i,j,:);
    end
end


for i=1:256
    for j=1:256
        LH13(i,j,:) = img3(i,j,:) + LH1(i,j,:);
        HL13(i,j,:) = img3(i,j,:) + HL1(i,j,:);
        HH13(i,j,:) = img3(i,j,:) + HH1(i,j,:);
    end
 end

%bicubic interpolation(Here alpha = 2;Hence alpha/2 = 1) 
 img31 = imresize(img3,1,'bicubic');
 LH131 = imresize(LH13,1,'bicubic');
 HL131 = imresize(HL13,1,'bicubic');
 HH131 = imresize(HH13,1,'bicubic');

img4 = idwt2(img31,LH131,HL131,HH131,'haar'); %IDWT
t = uint8(img4)
imshow(t);
imsave;

But I'm getting a completely unexpected output image.Why this is happening.Please help.Thanks in advance.

Input image:

lena1

Output image:

output

Roger Rowland
  • 25,885
  • 11
  • 72
  • 113
Celine
  • 115
  • 1
  • 5
  • 13
  • 2
    *"But I'm getting a completely unexpected output image"* - so what are you expecting and what are you getting? Do you expect us to read the paper and check your code for you? – Roger Rowland Nov 06 '14 at 12:15
  • @RogerRowland I'm not having enough reputation to add the image.Thats why I couldn't add the images.Output that I'm getting is almost a dark image,not an image with good clarity. – Celine Nov 06 '14 at 12:33
  • Then perhaps you just need to do a stretch (histogram equalisation) before display? – Roger Rowland Nov 06 '14 at 12:46
  • 1
    Almost certainly your output is not of the combination of data type and data range that `imshow` expects. Try `imshow(t,[]);` – nkjt Nov 06 '14 at 13:28
  • 1
    Whenever I read "completely unexpected" I all ways think: Did he\she get a velocirraptor as an output? You cannot put an image, but you can ut a link to an image! ;) Upload it in imageshank or something – Ander Biguri Nov 06 '14 at 14:16
  • Please provide a URL to the image and one of us will update your post. – rayryeng Nov 06 '14 at 14:43
  • @rayryeng Input high resolution image (img1)is https://dl.dropboxusercontent.com/u/21297779/lena1.jpg and the output that I'm getting is https://dl.dropboxusercontent.com/u/21297779/12.png – Celine Nov 07 '14 at 08:25
  • @AnderBiguri Posted the links of the input and output images above – Celine Nov 07 '14 at 08:29
  • @RogerRowland Posted the links of the input and output images above – Celine Nov 07 '14 at 08:30
  • @Celine very good! now, did you tried imshow(t,[]); ? – Ander Biguri Nov 07 '14 at 09:54
  • @AnderBiguri Yes sir.I tried the ranges 0-255 and 0-1.But I'm getting the same result – Celine Nov 07 '14 at 12:33
  • @Celine I dont understand. if you do imshow(t,[]); you should see an image quite decently. Whts your problem? that image is not what you want? what do you want? – Ander Biguri Nov 07 '14 at 12:38
  • No.The expected output should be almost similar to the input image.The algorithm first construct a low resolution Lena image(by downsampling) and tries to recostruct a high resolution image.Hence the output should be somewhat similar to the first image – Celine Nov 07 '14 at 12:44

1 Answers1

4

I took a look at the block diagram that's in the paper. You are reconstructing with the wrong image. At the final step, you should be using the original downsampled image as part of the IDWT - not the difference image. Here's the diagram for self containment:

enter image description here

Look at the final step of the algorithm. You are to use the low-resolution image, in conjunction with the LH, HL and HH components from the previous step. From the previous step, you obtain each of those subbands by adding the DWT components from the previous step (without the LL component) with the difference image, so you have this correct.

A couple of other comments I'll suggest is to change your image so that its dynamic range goes from [0,1]. You can do this with im2double. You also are using for loops to inefficiently calculate the difference when vectorized operations will do. Finally, you are performing interpolation with a factor of 1 towards the end of your code. This is a useless operation because you'll simply get the same image back. I removed this from your code for speedups. As such, this is the code that I have. Bear in mind that you didn't include your Lena image, so I pulled one from the Internet.

Without further ado, here's your modified code:

clear all;
close all;
img1 = imread('http://www.ece.rice.edu/~wakin/images/lenaTest3.jpg'); %original High resolution image
[height, width, dim] = size(img1);

%// Change - convert to [0,1]
img1 = im2double(img1);

%%Downsampling the image by averaging
avgfilter = fspecial('average', [2 2]);
avgimg = filter2(avgfilter, img1);
img = avgimg(1:2:end,1:2:end); %Input low resolution image

[LL,LH,HL,HH] = dwt2(img,'haar'); %Decomposing

%Bicubic interpolation by factor 2 on each subbands
LL1 = imresize(LL,2,'bicubic');
LH1 = imresize(LH,2,'bicubic');
HL1 = imresize(HL,2,'bicubic');
HH1 = imresize(HH,2,'bicubic');

% // Change - Vectorized operations
img3 = img - LL1;
LH13 = img3 + LH1;
HL13 = img3 + HL1;
HH13 = img3 + HH1;

%bicubic interpolation(Here alpha = 2;Hence alpha/2 = 1) 
%// Change - commented out
%// Also, used ORIGINAL downsampled image, not the difference image
 %img31 = imresize(img,1,'bicubic');
 %LH131 = imresize(LH13,1,'bicubic');
 %HL131 = imresize(HL13,1,'bicubic');
 %HH131 = imresize(HH13,1,'bicubic');

%// Change - used original downsampled image
img4 = idwt2(img,LH13,HL13,HH13,'haar'); %IDWT
t = im2uint8(img4); %// Change - Convert back to uint8 when finished
imshow(t,[]);

This is the image I get:

enter image description here


I don't get anything close to the original Lena image. As such, I suspect that either you have to tweak some parameters, or the algorithm is flawed. Given that the method was published in a no-name journal, I suspect the latter.

This should get you started. Good luck!

rayryeng
  • 102,964
  • 22
  • 184
  • 193