How to display second level dwt?

5 ビュー (過去 30 日間)
Ömer Faruk GÜNAYDIN
Ömer Faruk GÜNAYDIN 2021 年 12 月 23 日
コメント済み: Imtiyaz Ahmad 2023 年 8 月 7 日
Hi. I want to display second level dwt. If I display seperatly to frequency components, it works fine. But when I try to merge and display, It appears just black color. Here is my code
close all;
clear;
cd 'C:\Users\LENOVO\OneDrive\Masaüstü' %% Uploading picture to Matlab
X=imread('Coleen.jpg','jpg');%Reading picture by Matlab
[LoD,HiD] = wfilters('haar','d');
[cA,cH,cV,cD] = dwt2(X,LoD,HiD,'mode','symh');
[cA2,cH2,cV2,cD2]=dwt2(cA,LoD,HiD,'mode','symh');
subplot(2,2,1)
imagesc(cA)
colormap gray
title('Approximation')
subplot(2,2,2)
imagesc(cH)
colormap gray
title('Horizontal')
subplot(2,2,3)
imagesc(cV)
colormap gray
title('Vertical')
subplot(2,2,4)
imagesc(cD)
colormap gray
title('Diagonal')
figure
Level2=[cA2,cH2; cV2,cD2];
imagesc([Level2,cH; cV,cD]);
colormap gray
It appears like this. But I want to display it like below.
Please. Could you help me?

採用された回答

yanqi liu
yanqi liu 2021 年 12 月 24 日
編集済み: yanqi liu 2021 年 12 月 24 日
yes,sir,may be use the dimension information,such as
close all;
clear all; clc;
%Reading picture by Matlab
X=imread('cameraman.tif');
[LoD,HiD] = wfilters('haar','d');
[cA,cH,cV,cD] = dwt2(X,LoD,HiD,'mode','symh');
[cA2,cH2,cV2,cD2]=dwt2(cA,LoD,HiD,'mode','symh');
figure
Level2=[mat2gray(cA2),mat2gray(cH2); mat2gray(cV2),mat2gray(cD2)];
d = [Level2,mat2gray(cH); mat2gray(cV),mat2gray(cD)];
% get dimension
rects1 = [1 1 size(cA2)
1 2 size(cA2)
2 1 size(cV2)
2 2 size(cD2)];
rects2 = [1 1 size(Level2)
1 2 size(cH)
2 1 size(cV)
2 2 size(cD)];
rects = {rects1, rects2};
imagesc(d);
colormap gray
axis equal
axis off
hold on;
rectangle('position', [1 1 size(d,2)-1 size(d,1)-1], 'EdgeColor', 'y', 'LineWidth', 2)
for k = 1 : length(rects)
rectsk = rects{k};
for i = 1 : size(rectsk, 1)
recti = [zeros(1, 2) rectsk(i,3:4)];
% get location
rowi = rectsk(i,1);
coli = rectsk(i,2);
for j = 1 : coli-1
recti(1) = recti(1) + rectsk(j, 4);
end
for j = 1 : rowi-1
recti(2) = recti(2) + rectsk(j, 3);
end
rectangle('position', recti, 'EdgeColor', 'y', 'LineWidth', 2)
end
end
  1 件のコメント
Imtiyaz Ahmad
Imtiyaz Ahmad 2023 年 8 月 7 日
Hi,
I am facing an issue while using Daubechies wavelet , its says an error as ;Error using horzcat
Dimensions of arrays being concatenated are not consistent.... but its working fine while using haar wavelet, can you provide the solution for that also ..

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by