Clear Filters
Clear Filters

How to calculate discrete wavelet transform on an image with levels 2,4 and 6 using dwt2 function in matlab

13 views (last 30 days)
I have an image lena.pgm. I want to compute the dwt on the image using dwt2 function in matlab and i want to display all the coefficients diagrams concatenated as shown in the figure (that is the image for 2 level decomposition)
. Like that i want to display for level 4 and level 6. I'm sending the code for 2 level decomposition. Please help me code:
clc;
clear all
myimage=imread('lena512gray.pgm');
image = myimage;
wavename = 'haar';
[cA,cH,cV,cD] = dwt2(im2double(image),wavename);
[cAA,cAH,cAV,cAD] = dwt2(cA,wavename); % Recompute Wavelet of Approximation Coefs.
Level2=[cAA,cAH; cAV,cAD]; %contacinat
imshow([Level2,cH; cV,cD],'Colormap',gray); %2 level

Accepted Answer

Abhishek Ballaney
Abhishek Ballaney on 26 Feb 2018
https://in.mathworks.com/help/wavelet/ref/dwt2.html

More Answers (1)

Diwakar Diwakar
Diwakar Diwakar on 22 May 2023
Here's the complete MATLAB code for calculating the discrete wavelet transform (DWT) on an image with levels 2, 4, and 6 using the dwt2 function:
% Load the image
image = imread('your_image.jpg'); % Replace 'your_image.jpg' with the actual image file path
% Calculate the DWT at level 2
[LL2, LH2, HL2, HH2] = dwt2(image, 'haar');
% Calculate the DWT at level 4
[LL1, LH1, HL1, HH1] = dwt2(LL2, 'haar');
% Calculate the DWT at level 6
[LL, LH, HL, HH] = dwt2(LL1, 'haar');
% Access the coefficients at each level for further processing or analysis
% Level 2 coefficients
LL2 % Approximation coefficients at level 2
LH2 % Horizontal detail coefficients at level 2
HL2 % Vertical detail coefficients at level 2
HH2 % Diagonal detail coefficients at level 2
% Level 4 coefficients
LL1 % Approximation coefficients at level 4
LH1 % Horizontal detail coefficients at level 4
HL1 % Vertical detail coefficients at level 4
HH1 % Diagonal detail coefficients at level 4
% Level 6 coefficients
LL % Approximation coefficients at level 6
LH % Horizontal detail coefficients at level 6
HL % Vertical detail coefficients at level 6
HH % Diagonal detail coefficients at level 6
Make sure to replace 'your_image.jpg' with the actual path to your image file. Also, remember to adjust the wavelet type if desired by replacing 'haar' with the desired wavelet family, such as 'dbN', 'symN', 'coifN', etc.

Categories

Find more on Discrete Multiresolution Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!