Problem with wavelet decomposit​ion-recosn​truction

6 views (last 30 days)
I've performed 3 level transform on 'lena.gif' image using 'wavedec2' function, then I performed reconstruction using 'waverec2' function. The reconstructed image is saved by naming it as 'lena2.gif'. After that,I again perform 3- level decomposition on 'lena2.gif' image and found that the wavelet coefficient of 'lena.gif' and 'lena2.gif' differs in values!!.. Why this is happening? How can I solve this problem.
Thanks in advance.

Answers (1)

Wayne King
Wayne King on 28 Aug 2011
Hi, you haven't told us whether you modified the coefficients at all before you reconstructed the image. Did you simply execute:
X = waverec2(C,S,'wname');
Did you verify that you had perfect reconstruction of the image in MATLAB?
Also, you have to take into consideration the class of the image before and after you create the gif file.
I suspect there were some differences introduced in the writing process. When you reread the new fig file in MATLAB, was it identical to the original? I'm guessing it wasn't and therefore the wavelet coefficients should not be the same.
For example:
load woman
[C,S] = wavedec2(X,3,'db2');
X1 = waverec2(C,S,'db2');
% verify perfect reconstruction
norm(X-X1,2)
Then if I write a new GIF file and read the data back in, the data will be in unsigned 8-bit integers.
imwrite(uint8(X1),'woman.gif','GIF')
newwoman = imread('woman.gif');
Now the data is uint8.
Wayne
  1 Comment
snake eyes
snake eyes on 29 Aug 2011
Mr.Wayne, thanks for the reply.I'm doing image watermarking project. I've wrote the following code to generate image from 'C' of wavelet decomposition.
function [img,s] = pro_wavedec(image)
[c,s] = wavedec2(image,3,'db1');
img = zeros(size(image,1),size(image,2));
st = 1;
nd = s(1,1)*s(1,2);
temp = reshape(c(st:nd),s(1,1),s(1,2));
img(1:s(1,1),1:s(1,2)) = temp;
for i = 2:size(s,1)-1
k = s(i,1);
pnt = [
1 k+1 k 2*k;
k+1 1 2*k k;
k+1 k+1 2*k 2*k
];
for j = 1:3
st = nd+1;
nd = nd+(k*k);
temp = reshape(c(st:nd),k,k);
img(pnt(j,1):pnt(j,3),pnt(j,2):pnt(j,4)) = temp;
end
end
And as in order to perform do reconstruction using 'waverec2',to generate 'C' from image,so i've wrote the following code:
function img = pro_waverec(image,s)
c = zeros(1,size(image,1)*size(image,1));\
st = 1;
nd = s(1,1)*s(1,2);
temp = reshape(image(1:s(1,1),1:s(1,2)),1,[]);
c(st:nd) = temp;
for i = 2:size(s,1)-1
k = s(i,1);
pnt = [
1 k+1 k 2*k;
k+1 1 2*k k;
k+1 k+1 2*k 2*k
];
for j = 1:3
st = nd+1;
nd = nd+(k*k); temp=reshape(image(pnt(j,1):pnt(j,3),pnt(j,2):pnt(j,4)),1,[]);
c(st:nd) = temp;
end
end
img = waverec2(c,s,'db1');
Hope,u can understand these code and find out what is the problem with them.
Thanks again.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!