how to apply dwt and inverse dwt for an image

hi all..im writing a code for getting an image and perform dwt for one level to get 4 sub bands and apply inverse dwt to reconstruct the image. The LL band should contain the intensity imformation of the image but for me the figure for LL is plain white and when tried for reconstructing image iam getting same white screen image. i am not sure what was the mistake i have done.. the code i have written is shown below,
clear all;
close all;
i=imread('image22.jpg');
sX=size(i);
[LL,LH,HL,HH]=dwt2(i,'db1');
figure(1)
subplot(2,2,1);imshow(LL);title('LL band of image');
subplot(2,2,2);imshow(LH);title('LH band of image');
subplot(2,2,3);imshow(HL);title('HL band of image');
subplot(2,2,4);imshow(HH);title('HH band of image');
X = idwt2(LL,LH,HL,HH,'db1',sX);
figure(2)
imshow(X);
kindly help me to fix the same.

6 comentarios

Arnab Banerjee
Arnab Banerjee el 4 de Dic. de 2016
Editada: Arnab Banerjee el 4 de Dic. de 2016
Sir, would you please send me the code mention above, but in 3 level, at arnab.banerjee20@gmail.com
YEPDIA LEE
YEPDIA LEE el 12 de Nov. de 2018
please sir,can you Dme the code mentionned above on decomposition and reconstruction of an image with 2D wavelet transform! you can send it at yepdiamariel26@gmail.com tanks.
send me the correct code for the above code u have mentioned .
send it at srinivasareddy878@gmail.com
omer hussain
omer hussain el 2 de Mzo. de 2019
Dear Dr.,
I am a scholar and i am trying to implement a paper and i stuck in implementing the 3 Level DWT of an grayscale image.
I will be very thankful to you if you can send me the code at ohosain@kku.edu.sa
mariena aloor
mariena aloor el 10 de Abr. de 2019
Hai Sir
I want to take the features from blood smear image.So how i will use discrete wavelet transform for feature extraction.
I want the code for second level dwt only for the LL band.Kindly give me the matlab code for feature extraction using discrete wavelet transform my mail id is : aloormariena@gmail.com

Iniciar sesión para comentar.

 Respuesta aceptada

Nawin K Sharma
Nawin K Sharma el 25 de Sept. de 2017
Editada: Nawin K Sharma el 25 de Sept. de 2017

1 voto

dwt2 results are in double (Integer) format. For double format, imshow treats non zero values as White and Zero values as Black. That's why you are getting full white screen.
Try this modification in your code
LL=uint8(LL);
uint8 converts double to unsigned integer of 8 bit format,which is used in gray scale or colored images.
If you want o retain double format, use this
imshow(uint8(LL))

7 comentarios

munipraveena rela
munipraveena rela el 29 de Dic. de 2017
yes, it is working . thank you
anuja dixit
anuja dixit el 2 de Mayo de 2018
Thank you so much. It's working.
Nitish Chandra
Nitish Chandra el 10 de Mzo. de 2019
Error in dw (line 6)
[LL,LH,HL,HH]=dwt2(i,'db1');
showing this error.
what i have to do??
send me the right code on nitishchandra008@gmail.com
Walter Roberson
Walter Roberson el 10 de Mzo. de 2019
What is the complete error message?
Sangeetha Kumar
Sangeetha Kumar el 16 de Sept. de 2019
Sir please kindly send the 3 level DWT for grey scale image .....geetha180596@gmail.com
lavanya valli
lavanya valli el 10 de Mzo. de 2020
sir plz send me the 2 level DWT for grey scale image .......vallilavanya04@gmail.com
Toon Tiam
Toon Tiam el 7 de Jun. de 2023
Had the same issues and your solution solveed it! Thank you!

Iniciar sesión para comentar.

Más respuestas (9)

chaitanya goteti
chaitanya goteti el 8 de Sept. de 2015

3 votos

Use uint8 while displaying the bands, like imshow(uint8(LL)). Hope this helps
umme kulsum
umme kulsum el 31 de Mzo. de 2017

1 voto

You can use imagesc instead of imshow command
Wayne King
Wayne King el 6 de Feb. de 2014
Editada: Wayne King el 6 de Feb. de 2014
Are you sure it is just not the scaling of the image in imshow() that is causing you problems?
For example, note:
load woman;
sX = size(X);
[LL,LH,HL,HH]=dwt2(X,'db1');
Xrec = idwt2(LL,LH,HL,HH,'db1',sX);
max(max(abs(X-Xrec)))
The above shows perfect reconstruction. The maximum absolute value of the difference between elements in the original matrix and the reconstructed matrix is on the order of 10^{-13}

4 comentarios

Sathish Kumar
Sathish Kumar el 6 de Feb. de 2014
'imshow' is to display the image...i dont think is might be a problem..because imshow of original image will display the input original image perfectly..
Wayne King
Wayne King el 6 de Feb. de 2014
Editada: Wayne King el 6 de Feb. de 2014
I understand what imshow() is used for, but did you verify that you get perfect reconstruction with your image?
Can you attach your image?
i get this error would you please help me? Error using - Integers can only be combined with integers of the same class, or scalar doubles.
Error in jpg4 (line 9) max(max(abs(X) - abs(Xrec)))
max(max(double(abs(X)) - double(abs(Xrec))))

Iniciar sesión para comentar.

Karbala'a Unvi. Science
Karbala'a Unvi. Science el 3 de Mayo de 2014

0 votos

Hi every one,... I worked on your code and I did some modification on it and I made it work because I have the same project on my PHD project so if you want the modified code I can send it to you when you send me your e-mail. and give me your opinion. yours Zeyad

3 comentarios

lavanya valli
lavanya valli el 10 de Mzo. de 2020
sir plz send me the code vallilavanya04@gmail.com
Tapaswini Hansdah
Tapaswini Hansdah el 17 de Abr. de 2020
sir can you send me aswell ? tapaswinihansdah1996@gmail.com
Madhu Oruganti
Madhu Oruganti el 26 de Mayo de 2020
Dear sir, I am also working for my phD course can you please share the code at oruganti.madhu@gmail.com

Iniciar sesión para comentar.

Sam
Sam el 24 de Nov. de 2014

0 votos

At the end of the program just modify it as "imshow(X,[])", and it will work.

1 comentario

Afeza Ajirah
Afeza Ajirah el 10 de Mzo. de 2017
I tried it, but it still display plain white. Hmm, anyone can help?

Iniciar sesión para comentar.

Ahmad Shaheen
Ahmad Shaheen el 17 de Dic. de 2016

0 votos

After i=imread('image22.jpg'); insert the following: i=im2double(i); and it will works.
Harmeet Kaur
Harmeet Kaur el 2 de En. de 2018
Editada: Harmeet Kaur el 2 de En. de 2018

0 votos

hello everyone the above code is not giving the reconstructed image. the output of reconstruction is as follows:

4 comentarios

Which above code?
Fatima Munvar
Fatima Munvar el 23 de Mzo. de 2018
Editada: Walter Roberson el 2 de Mayo de 2018
the following code not giving reconstructed image pls help me with this
close all;
clear all;
X=imread('Lilly_Closeup.bmp');
imshow(X);
i=imresize(X,[512 512]);
figure(1);
imshow(i);
sX=size(X);
[LL,LH,HL,HH]= dwt2(X,'db1');
figure(2)
subplot(2,2,1);imshow(LL);title('LL band of image');
subplot(2,2,2);imshow(LH);title('LH band of image');
subplot(2,2,3);imshow(HL);title('HL band of image');
subplot(2,2,4);imshow(HH);title('HH band of image');
Xrec=idwt2(LL,LH,HL,HH,'db1',sX);
% sx=size(X)
% A1=idwt2(LL,[],[],[],'db1',sX);
% H1=idwt2([],LH,[],[],'db1',sX);
% V1=idwt2(LL,[],HL,[],'db1',sX);
% D1=idwt2(LL,[],[],HH,'db1',sX);
max(max(abs(i-Xrec)));
figure(3);
imshow(Xrec);
I am getting error as below
Error using -
Integers can only be combined with integers of the same class, or scalar doubles.
Error in dwt21 (line 21)
max(max(abs(i-Xrec)));
The line
max(max(abs(i-Xrec)));
tries to calculate something abut then it throws away the results of the calculation. The easiest repair is to comment out the line.
Dear Sir,
Try this code and tell me is it working ornot..
clc, close all;
clear all;
X=imread('3.bmp');
imshow(X);
X= double(X);
i=imresize(X,[512 512]);
figure(1);
imshow(i);
sX=size(X);
[LL,LH,HL,HH]= dwt2(X,'db1');
figure(2)
subplot(2,2,1);imshow(LL);title('LL band of image');
subplot(2,2,2);imshow(LH);title('LH band of image');
subplot(2,2,3);imshow(HL);title('HL band of image');
subplot(2,2,4);imshow(HH);title('HH band of image');
%%
Xrec=idwt2(LL,LH,HL,HH,'db1',sX);
% sx=size(X)
% A1=idwt2(LL,[],[],[],'db1',sX);
% H1=idwt2([],LH,[],[],'db1',sX);
% V1=idwt2(LL,[],HL,[],'db1',sX);
% D1=idwt2(LL,[],[],HH,'db1',sX);
max(max(abs(X-Xrec)))
figure(3);
imshow(uint8(Xrec));

Iniciar sesión para comentar.

Ankita Bansal
Ankita Bansal el 1 de Jun. de 2018
Editada: Ankita Bansal el 1 de Jun. de 2018
Hi Fatima, in your code the sizes of X and i are not equal and you are using X as an input to dwt function. Hence whatever calculation will be done after [LL, LH, HL, HH] = dwt2(X,'db1'); will use X. So, when you try to calculate inverse dwt, the data you will get will be of same size as that of X. Also, the datatype of output of idwt is double whereas i is of uint8 datatype. So, the first reason of getting error is different data type and the second reason is size. To check whether the output you are getting is correct or not you can write max(max(abs(X-uint8(Xrec)))) instead of max(max(abs(i-Xrec))).
if true
% code
end
close all;
clear all;
X=imread('image.png');
imshow(X);
i=imresize(X,[512 512]);
figure;
imshow(i);
sX=size(X);
[LL,LH,HL,HH]= dwt2(X,'db1');
Figure;
subplot(2,2,1);imshow(LL);title('LL band of image');
subplot(2,2,2);imshow(LH);title('LH band of image');
subplot(2,2,3);imshow(HL);title('HL band of image');
subplot(2,2,4);imshow(HH);title('HH band of image');
Xrec=idwt2(LL,LH,HL,HH,'db1',sX);
max(max(abs(X-uint8(Xrec))));
figure;
imshow(Xrec);
Hope this helps

5 comentarios

Rahul Kumar Singh
Rahul Kumar Singh el 3 de Oct. de 2018
Editada: Rahul Kumar Singh el 3 de Oct. de 2018
max(max(abs(X-uint8(Xrec))));
having problem with this still the reconstructed image is turning out to be white kindly help!
imshow(uint8(Xrec))
yeah its working now thanks!
hello, i am currently working on image steganography in transform domain. As i am new to this i only the theoritical part . my question is after getting the subbands LL,LH,HL,HH how do we obtain the wavelet coeffients so that we can divide them into blocks of four and then choose m\2 blocks out of it(where m is the length of the secret message(in bits) to be embedded ) so that 2 bits can be embedded in each block by pattern matrix method.
i hope you understood my question. any suggestion will help.
try this one
clc, close all;
clear all;
X=imread('3.bmp');
imshow(X);
X= double(X);
i=imresize(X,[512 512]);
figure(1);
imshow(i);
sX=size(X);
[LL,LH,HL,HH]= dwt2(X,'db1');
figure(2)
subplot(2,2,1);imshow(LL);title('LL band of image');
subplot(2,2,2);imshow(LH);title('LH band of image');
subplot(2,2,3);imshow(HL);title('HL band of image');
subplot(2,2,4);imshow(HH);title('HH band of image');
%%
Xrec=idwt2(LL,LH,HL,HH,'db1',sX);
% sx=size(X)
% A1=idwt2(LL,[],[],[],'db1',sX);
% H1=idwt2([],LH,[],[],'db1',sX);
% V1=idwt2(LL,[],HL,[],'db1',sX);
% D1=idwt2(LL,[],[],HH,'db1',sX);
max(max(abs(X-Xrec)))
figure(3);
imshow(uint8(Xrec));

Iniciar sesión para comentar.

pallavi singh
pallavi singh el 11 de Ag. de 2020

0 votos

SIr,
Can u tell me the code of dwt ?

4 comentarios

At the MATLAB command prompt, command
type dwt
pallavi singh
pallavi singh el 12 de Ag. de 2020
how can apply dwt & idwt in an image
Walter Roberson
Walter Roberson el 12 de Ag. de 2020
You have a small number of choices:
  1. You can apply dwt for every row (of every color plane) independently;
  2. You can apply dwt for every column (of every color plane) independently;
  3. You can apply dwt for every row (of every color plane) independently, and transpose the result and apply dwt to every row (of every color plane) of the result. This is similar to the way that fft2() is fft(fft(IMAGE).')
  4. You can apply dwt for every column (of every color plane) independently, and transpose the result and apply dwt to every column (of every color plane) of the result. This is similar to the way that fft2() is fft(fft(IMAGE).'). In theory this should give the same result as #3
  5. You can reshape the image into a single continuous row and apply dwt to that
  6. You can reshape the image into a single continuous column and apply dwt to that
To be clear: dwt can only be used on one vector at a time, so you cannot just apply it to a 2D or 3D (RGB) array.
See also: dwt2()
pallavi singh
pallavi singh el 8 de Sept. de 2020
Sir , can u tell me the code of 2D-DWT?

Iniciar sesión para comentar.

Productos

Etiquetas

Preguntada:

el 6 de Feb. de 2014

Comentada:

el 7 de Jun. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by