Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

How to Display wavelet transformation function dwt2 results in matlab

Date: 2022-11-25 12:54:02

I am applying dwt2 function on an image to apply wavelet transformation which is giving four result images cA(low pass image),cH (Horizontal Detail image),cV(Vertical Detail Image),cD (Diagonal Detail Image). Every this fine till Now. I want to visualize those result images.

Present I am visualizing those four result images using this below code. 

 

image = imread(imagePath);
wavename = 'haar';
[cA,cH,cV,cD] = dwt2(im2double(iamge),wavename);
imshow([cA,cH; cV,cD],'Colormap',gray); 

when i run this code visualizing result look like this enter image description here

But i want my results should look like this can any one help me please.

enter image description here

Expert Answer:

s: 

In the second image of your question, the two-level wavelet transform is displayed. With your code example using dwt2, you are only doing a single-level decomposition. To do a two-level decomposition, you can use the wavedec2 function with N=2. To create the plot as shown, you have to take a closer look at the return values of wavedec2

data (Image by Mathworks, from [2])

The vector C contains all the approximation coefficients, stored in a column-wise fashion. S is the so-called "book-keeping" matrix, as it contains information on how the data is stored.

Now the first image, cA2 in the example above, is the first 32*32 entries of C. Using ii and jj as index variables, we can get the relevant parts of C and use reshape to get back to the image format: 

 

 ii = 1; jj = prod(S(1,:));
cA2 = reshape(C(ii:jj),S(1,:));

The other second-level coefficients are similarly obtained: 

 

ii = jj+1; jj = ii + prod(S(2,:)) - 1;
cH2 = reshape(C(ii:jj),S(2,:));

ii = jj+1; jj = ii + prod(S(2,:)) - 1;
cV2 = reshape(C(ii:jj),S(2,:));

ii = jj+1; jj = ii + prod(S(2,:)) - 1;
cD2 = reshape(C(ii:jj),S(2,:)); 

The first-level coefficients can also be obtained in the same way, using the third row of S

 

 ii = jj+1; jj = ii + prod(S(3,:)) - 1;
cH1 = reshape(C(ii:jj),S(3,:));

ii = jj+1; jj = ii + prod(S(3,:)) - 1;
cV1 = reshape(C(ii:jj),S(3,:));

ii = jj+1; jj = ii + prod(S(3,:)) - 1;
cD1 = reshape(C(ii:jj),S(3,:));

Now the plot can simply be created by arranging the images as desired: 

 

 imshow([[cA2,cH2; cV2,cD2],cH1;cV1,cD1],'Colormap',pink)

To add borders, you can use the rectangle function and the information from S

 

 % Small rectangles
rectangle('Position',[0,0,S(1,1),S(1,2)],'LineWidth',2,'EdgeColor','y');
rectangle('Position',[S(1,1),0,S(1,1),S(1,2)],'LineWidth',2,'EdgeColor','y');
rectangle('Position',[0,S(1,2),S(1,1),S(1,2)],'LineWidth',2,'EdgeColor','y');
rectangle('Position',[S(1,1),S(1,2),S(1,1),S(1,2)],'LineWidth',2,'EdgeColor','y');

% Large rectangles
rectangle('Position',[0,S(3,2),S(3,1),S(3,2)],'LineWidth',2,'EdgeColor','y');
rectangle('Position',[S(3,1),0,S(3,1),S(3,2)],'LineWidth',2,'EdgeColor','y');
rectangle('Position',[S(3,1),S(3,2),S(3,1),S(3,2)],'LineWidth',2,'EdgeColor','y');

 

Why Matlabhelpers ?

Looking for reliable MATLAB assignment help? Our expert MATLAB tutors deliver high-quality, easy-to-understand solutions tailored to your academic needs. Whether you're studying at Monash University, the University of Sydney, UNSW, or the University of Melbourne, we provide trusted MATLAB assistance to help you excel. Contact us today for the best MATLAB solutions online and achieve academic success!

MATLAB Assignment Help Services

Personalized Tutoring: Get one-on-one guidance from our MATLAB experts. Whether you're tackling basic concepts or advanced algorithms, we provide clear, step-by-step explanations to help you master MATLAB with confidence.

Assignment Assistance: Struggling with tight deadlines or complex assignments? Our team offers end-to-end support, from problem analysis to code development and debugging, ensuring your assignments meet the highest academic standards.

Project Development: Need expert help with your MATLAB research project? We assist in designing and implementing robust solutions, covering project planning, data collection, coding, simulation, and result analysis.

Coursework Support: Enhance your understanding of MATLAB with our comprehensive coursework assistance. We help you grasp lecture concepts, complete lab exercises, and prepare effectively for exams.

Thesis and Dissertation Guidance: Incorporate MATLAB seamlessly into your thesis or dissertation. Our experts provide support for data analysis, modeling, and simulation, ensuring your research is methodologically sound and impactful.

Contact us on WhatsApp for MATLAB help

Contact us on Telegram for MATLAB solutions