What is the difference between "dwt2()" and "wavedec2()"?

조회 수: 17 (최근 30일)
WanYu
WanYu 2020년 2월 5일
댓글: WanYu 2020년 2월 5일
Hi All,
I wish to know the difference between "dwt2()" and "wavedec2()", I have tried it on MATLAB yet it shows different value in each variables.
MATLAB Code as shown:
dwt2
[LL, LH, HL, HH] = dwt2(A, 'db1');
wavedec2
[C, L] = wavedec2(A, 1, 'db1');
Also, I am trying on 3-level DWT with "dwt2()" and "idwt2()", however I faced difficulties when converting it back to a RGB image.
This is how I do for "dwt" process as I want to see the difference on selecting different sub-bands may affects on the image output.
% 1-level dwt
[LL1, LH1, HL1, HH1] = dwt2(A, 'db1');
% 2-level dwt
[LL1_LL2, LL1_LH2, LL1_HL2, LL1_HH2] = dwt2(LL1, 'db1');
[LH1_LL2, LH1_LH2, LH1_HL2, LH1_HH2] = dwt2(LH1, 'db1');
[HL1_LL2, HL1_LH2, HL1_HL2, HL1_HH2] = dwt2(HL1, 'db1');
[HH1_LL2, HH1_LH2, HH1_HL2, HH1_HH2] = dwt2(HH1, 'db1');
% 3-level dwt
[LL1_LL2_LL3, LL1_LL2_LH3, LL1_LL2_HL3, LL1_LL2_HH3] = dwt2(LL1_LL2, 'db1');
[LL1_LH2_LL3, LL1_LH2_LH3, LL1_LH2_HL3, LL1_LH2_HH3] = dwt2(LL1_LH2, 'db1');
[LL1_HL2_LL3, LL1_HL2_LH3, LL1_HL2_HL3, LL1_HL2_HH3] = dwt2(LL1_HL2, 'db1');
[LL1_HH2_LL3, LL1_HH2_LH3, LL1_HH2_HL3, LL1_HH2_HH3] = dwt2(LL1_HH2, 'db1');
[LH1_LL2_LL3, LH1_LL2_LH3, LH1_LL2_HL3, LH1_LL2_HH3] = dwt2(LH1_LL2, 'db1');
[LH1_LH2_LL3, LH1_LH2_LH3, LH1_LH2_HL3, LH1_LH2_HH3] = dwt2(LH1_LH2, 'db1');
[LH1_HL2_LL3, LH1_HL2_LH3, LH1_HL2_HL3, LH1_HL2_HH3] = dwt2(LH1_HL2, 'db1');
[LH1_HH2_LL3, LH1_HH2_LH3, LH1_HH2_HL3, LH1_HH2_HH3] = dwt2(LH1_HH2, 'db1');
[HL1_LL2_LL3, HL1_LL2_LH3, HL1_LL2_HL3, HL1_LL2_HH3] = dwt2(HL1_LL2, 'db1');
[HL1_LH2_LL3, HL1_LH2_LH3, HL1_LH2_HL3, HL1_LH2_HH3] = dwt2(HL1_LH2, 'db1');
[HL1_HL2_LL3, HL1_HL2_LH3, HL1_HL2_HL3, HL1_HL2_HH3] = dwt2(HL1_HL2, 'db1');
[HL1_HH2_LL3, HL1_HH2_LH3, HL1_HH2_HL3, HL1_HH2_HH3] = dwt2(HL1_HH2, 'db1');
[HH1_LL2_LL3, HH1_LL2_LH3, HH1_LL2_HL3, HH1_LL2_HH3] = dwt2(HH1_LL2, 'db1');
[HH1_LH2_LL3, HH1_LH2_LH3, HH1_LH2_HL3, HH1_LH2_HH3] = dwt2(HH1_LH2, 'db1');
[HH1_HL2_LL3, HH1_HL2_LH3, HH1_HL2_HL3, HH1_HL2_HH3] = dwt2(HH1_HL2, 'db1');
[HH1_HH2_LL3, HH1_HH2_LH3, HH1_HH2_HL3, HH1_HH2_HH3] = dwt2(HH1_HH2, 'db1');
Please! Help me with this. Thanks lots!

채택된 답변

Subhadeep Koley
Subhadeep Koley 2020년 2월 5일
Basically dwt2() applies 2-D discreet wavelet transformation on the image and provides the approximation and detail coefficients matrices directly. Whereas, wavedec2() only provides the wavelet decomposition vector and the bookkeeping matrix, which contains the number of coefficients by level and orientation. And you can to get approximation and detail coefficients matrices from the wavelet decomposition vector and the bookkeeping matrix using the detcoef2() and appcoef2() function.
Exact same approximation and detail coefficients matrices can be generated using any of those (dwt2 or wavedec2) functions. See the example below
close all; clc;
% Decomposition using wavedec2 and appcoef2
load woman;
[c, s] = wavedec2(X, 1, 'db1');
A1 = appcoef2(c, s, 'db1', 1);
figure; imshow(A1, []); title('Using wavedec2 and appcoef2');
% Decomposition using dwt2
load woman;
[A2, ~, ~, ~] = dwt2(X, 'db1');
figure; imshow(A2, []); title('Using dwt2');
% Difference image between A1 and A2
diffImage = imabsdiff(A1, A2);
figure; imshow(diffImage, []); title('Difference Image');
Now, here is an example how you can display different sub-bands at different wavelet decomposition levels.
clc; close all;
load woman;
[c, s] = wavedec2(X, 3, 'haar');
% Extract the level 1 approximation and detail coefficients.
[H1, V1, D1] = detcoef2('all', c, s, 1);
A1 = appcoef2(c, s, 'haar', 1);
% Display images
figure; subplot(2, 2, 1); imshow(A1, []); title('Approximation Coef. of Level 1');
subplot(2, 2, 2); imshow(H1, []); title('Horizontal Detail Coef. of Level 1');
subplot(2, 2, 3); imshow(V1, []); title('Vertical Detail Coef. of Level 1');
subplot(2, 2, 4); imshow(D1, []); title('Diagonal Detail Coef. of Level 1');
% Extract the level 2 approximation and detail coefficients.
[H2, V2, D2] = detcoef2('all', c, s, 2);
A2 = appcoef2(c, s, 'haar', 2);
% Display images
figure; subplot(2, 2, 1); imshow(A2, []); title('Approximation Coef. of Level 2');
subplot(2, 2, 2); imshow(H2, []); title('Horizontal Detail Coef. of Level 2');
subplot(2, 2, 3); imshow(V2, []); title('Vertical Detail Coef. of Level 2');
subplot(2, 2, 4); imshow(D2, []); title('Diagonal Detail Coef. of Level 2');
% Extract the level 3 approximation and detail coefficients.
[H3, V3, D3] = detcoef2('all', c, s, 3);
A3 = appcoef2(c, s, 'haar', 3);
% Display images
figure; subplot(2, 2, 1); imshow(A3, []); title('Approximation Coef. of Level 3');
subplot(2, 2, 2); imshow(H3, []); title('Horizontal Detail Coef. of Level 3');
subplot(2, 2, 3); imshow(V3, []); title('Vertical Detail Coef. of Level 3');
subplot(2, 2, 4); imshow(D3, []); title('Diagonal Detail Coef. of Level 3');
Hope this helps!
  댓글 수: 1
WanYu
WanYu 2020년 2월 5일
Hi,
Thanks for the reply, it do helps! However, if I wish to change the value in one of the sub-bands aka do encryption, how can I achieve that?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by