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:
Output image:
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:
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:
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!