Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Image wavelet reconstruction

Subject: Image wavelet reconstruction

From: Twilighter

Date: 17 May, 2011 19:26:03

Message: 1 of 11

i need to ask , i think it's a simple question i hope :D

i make a 3 level wavelet transform


X=imread('lenna512_gray.bmp');
[C,S]=wavedec2(X,3,'haar');
cA3=appcoef2(C,S,'bior4.4',3);
ccA3=cA3;
[cH3,cV3,cD3] = detcoef2('all',C,S,3);
[cH2,cV2,cD2] = detcoef2('all',C,S,2);
[cH1,cV1,cD1] = detcoef2('all',C,S,1);

then i embed a watermark in the cH3,cV3 coefficient

how can i reconstruct my image back ?

img = idwt2(cA3,cH3,cV3,cD3,haar'); this line seems to be wrong


any help thanx

Subject: Image wavelet reconstruction

From: Wayne King

Date: 17 May, 2011 19:46:05

Message: 2 of 11

"Twilighter " <mscmatlab@gmail.com> wrote in message <iqui4b$g4e$1@newscl01ah.mathworks.com>...
> i need to ask , i think it's a simple question i hope :D
>
> i make a 3 level wavelet transform
>
>
> X=imread('lenna512_gray.bmp');
> [C,S]=wavedec2(X,3,'haar');
> cA3=appcoef2(C,S,'bior4.4',3);
> ccA3=cA3;
> [cH3,cV3,cD3] = detcoef2('all',C,S,3);
> [cH2,cV2,cD2] = detcoef2('all',C,S,2);
> [cH1,cV1,cD1] = detcoef2('all',C,S,1);
>
> then i embed a watermark in the cH3,cV3 coefficient
>
> how can i reconstruct my image back ?
>
> img = idwt2(cA3,cH3,cV3,cD3,haar'); this line seems to be wrong
>
>
> any help thanx

Hi, You should imbed the watermark in the C output from wavedec2 and then use waverec2 to reconstruct the image.
The help for wavedec2() describes how the coefficients are organized in C.

Hope that helps,
Wayne

Subject: Image wavelet reconstruction

From: Twilighter

Date: 17 May, 2011 19:59:03

Message: 3 of 11

thank you for your reply ....

i need to limbed only in the HL , LH bands ...

and i need to use my final cA3, cH3, cV3, cD3 to recontruct back

i thought doing idwt it brings me one level up
but i dunno how can i go all the way back to get my original image

i saw wavrec ... it doesnt use the wavelet coeff it uses the C which is not my case,

any suggestion ??

Subject: Image wavelet reconstruction

From: Twilighter

Date: 17 May, 2011 20:55:04

Message: 4 of 11

X=imread('lenna512_gray.bmp');
> [C,S]=wavedec2(X,3,'haar');
> cA3=appcoef2(C,S,'bior4.4',3);
> ccA3=cA3;
> [cH3,cV3,cD3] = detcoef2('all',C,S,3);
> [cH2,cV2,cD2] = detcoef2('all',C,S,2);
> [cH1,cV1,cD1] = detcoef2('all',C,S,1);
>
> then i embed a watermark in the cH3,cV3 coefficient
>
> how can i reconstruct my image back ?

to embed my watermark i mad this

[m,n] = size(cA3)

% the location at which cH3 starts
k = m*n;
kH = k
% the location at which cV3 starts
kV= 2*k

then i made my loop

R is the final results of my watermark which i need to imbed

    for j=1:k
        % cH3
        C(1,j+kH)=C(1,j+kH)+double(R(1,j));
        %cV3
        C(1,j+kV)=C(1,j+kV)+double(R(1,j));
        k=k+1;
    end


it works fine the when it execute this next line
wimg = waverec2(C,S,'Haar');

i get this error

??? Error using ==> appcoef2 at 48
Invalid level value.

Error in ==> waverec2 at 34
x = appcoef2(c,s,varargin{:},0);

Error in ==> ImpCode at 82
wimg = waverec2(C,S,'Haar');
wimg = waverec2(C,S,'Haar');

Help plz


 

Subject: Image wavelet reconstruction

From: Twilighter

Date: 17 May, 2011 21:01:03

Message: 5 of 11

the code is without k = k+1
that was a typs at the end of the j loop


so what could i possible be doing wrong ?

Subject: Image wavelet reconstruction

From: Wayne King

Date: 17 May, 2011 21:28:03

Message: 6 of 11

"Twilighter " <mscmatlab@gmail.com> wrote in message <iquk27$n0k$1@newscl01ah.mathworks.com>...
> thank you for your reply ....
>
> i need to limbed only in the HL , LH bands ...
>
> and i need to use my final cA3, cH3, cV3, cD3 to recontruct back
>
> i thought doing idwt it brings me one level up
> but i dunno how can i go all the way back to get my original image
>
> i saw wavrec ... it doesnt use the wavelet coeff it uses the C which is not my case,
>
> any suggestion ??

Hi Yes, my suggestion was to use wavedec2() and then waverec2(). The C vector contains the wavelet coefficients, so to say it doesn't use the wavelet coefficients is not accurate. The documentation clearly explains which wavelet coefficients correspond to which indices in the C vector.

dwtmode('per');
load woman;
[C,S] = wavedec2(X,1,'db4');

C is 1x65536
C(1:16384) are the approximation coefficients,
C(16385:16385+16383) are the horizontal details and so on.

You should place your watermark in the C vector and use waverec2.

Wayne

Subject: Image wavelet reconstruction

From: Twilighter

Date: 17 May, 2011 22:08:03

Message: 7 of 11

thank you for your reply

yea ... i figured it out & i tried it but i got an error ,,, i posted it here earlier

here it's again

to embed my watermark i made this

[m,n] = size(cA3)

% the location at which cH3 starts
k = m*n;
kH = k
% the location at which cV3 starts
kV= 2*k

then i made my loop

R is the final results of my watermark which i need to embed

    for j=1:k
        % cH3
        C(1,j+kH)=C(1,j+kH)+double(R(1,j));
        %cV3
        C(1,j+kV)=C(1,j+kV)+double(R(1,j));
    end


it works fine the when it execute this next line
wimg = waverec2(C,S,'Haar');

i get this error

??? Error using ==> appcoef2 at 48
Invalid level value.

Error in ==> waverec2 at 34
x = appcoef2(c,s,varargin{:},0);

Error in ==> ImpCode at 82
wimg = waverec2(C,S,'Haar');
wimg = waverec2(C,S,'Haar');


what is wrong ,,,, it should be something in the indexing ??

Subject: Image wavelet reconstruction

From: Wayne King

Date: 17 May, 2011 22:25:03

Message: 8 of 11

"Twilighter " <mscmatlab@gmail.com> wrote in message <iqurk3$i95$1@newscl01ah.mathworks.com>...
> thank you for your reply
>
> yea ... i figured it out & i tried it but i got an error ,,, i posted it here earlier
>
> here it's again
>
> to embed my watermark i made this
>
> [m,n] = size(cA3)
>
> % the location at which cH3 starts
> k = m*n;
> kH = k
> % the location at which cV3 starts
> kV= 2*k
>
> then i made my loop
>
> R is the final results of my watermark which i need to embed
>
> for j=1:k
> % cH3
> C(1,j+kH)=C(1,j+kH)+double(R(1,j));
> %cV3
> C(1,j+kV)=C(1,j+kV)+double(R(1,j));
> end
>
>
> it works fine the when it execute this next line
> wimg = waverec2(C,S,'Haar');
>
> i get this error
>
> ??? Error using ==> appcoef2 at 48
> Invalid level value.
>
> Error in ==> waverec2 at 34
> x = appcoef2(c,s,varargin{:},0);
>
> Error in ==> ImpCode at 82
> wimg = waverec2(C,S,'Haar');
> wimg = waverec2(C,S,'Haar');
>
>
> what is wrong ,,,, it should be something in the indexing ??

Hi, I'm not sure why you're trying to do it that way:

dwtmode('per');
X = randn(8,8);
[C,S] = wavedec2(X,1,'db4');
[H,V,D] = detcoef2('all',C,S,1);
% H is equal to reshape(C(17:17+15),4,4)

So just modify H for example
and then reshape() H and fill C with your new H:
H = H+ones(size(H));
C(17:17+15) = reshape(H,16,1);
X = waverec2(C,S,'haar');

Wayne

Subject: Image wavelet reconstruction

From: Twilighter

Date: 19 May, 2011 01:59:03

Message: 9 of 11

thank you big time :D it worked

Subject: Image wavelet reconstruction

From: Wayne King

Date: 19 May, 2011 03:39:03

Message: 10 of 11

"Twilighter " <mscmatlab@gmail.com> wrote in message <ir1th7$a48$1@newscl01ah.mathworks.com>...
> thank you big time :D it worked

Good, I'm glad it worked!! Now, if you had just listened the first time I told you... :D
Wayne

Subject: Image wavelet reconstruction

From: Twilighter

Date: 19 May, 2011 18:52:05

Message: 11 of 11

yea ... thanks for your patience ... i didnt grab it the first time, i thought i know everything about this function already :D

i believe in this quote

The Greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. ~ Stephen Hawking

:))))))))))))

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us