在MATLAB中使用wavedec2之后的子图无法显示

时间:2016-04-04 16:17:31

标签: image matlab image-processing

我在wavedec2上遵循了MathWorks教程,无法正确显示任何系数或近似子图。

有人可以建议我如何解决这个问题,以便正确显示近似和详细的子图吗?

这是我到目前为止所做的:

% Load image ‘Sample.tif’ and convert it into a grayscale image, denoted with ‘img1’ 
I = imread('Sample.tif');
img1 = rgb2gray(I);

% Decompose img1 with wavelet transform using function wavedec2 
% Perform decomposition at level 2 
% of X using haar.
[C,S] = wavedec2(I,2,'haar');

[H1,V1,D1] = detcoef2('all',C,S,1);
A1 = appcoef2(C,S,'haar',1);
V1img = wcodemat(V1,255,'mat',1);
H1img = wcodemat(H1,255,'mat',1);
D1img = wcodemat(D1,255,'mat',1);
A1img = wcodemat(A1,255,'mat',1);

[H2,V2,D2] = detcoef2('all',C,S,2);
A2 = appcoef2(C,S,'haar',2);
V2img = wcodemat(V2,255,'mat',1);
H2img = wcodemat(H2,255,'mat',1);
D2img = wcodemat(D2,255,'mat',1);
A2img = wcodemat(A2,255,'mat',1);

subplot(2,2,1);
imagesc(A1img);
colormap red(255);
title('Approximation Coef. of Level 1');

subplot(2,2,2);
imagesc(H1img);
title('Horizontal detail Coef. of Level 1');

subplot(2,2,3);
imagesc(V1img);
title('Vertical detail Coef. of Level 1');

subplot(2,2,4);
imagesc(D1img);
title('Diagonal detail Coef. of Level 1');

输出在这里,所有子图都是白色的:

enter image description here

Sample.tif在这里:

enter image description here

1 个答案:

答案 0 :(得分:1)

The datatype of your images is double but the range of value of your images is [0 255] so you have to cast your picture into the good datatype. [0 255] correspond to the range of the uint8 datatype, so you can simply write:

imagesc(uint8(A1img));

or

A1img = uint8(A1img);

enter image description here