display rescaled matrix as image: imagesc vs wcodemat
2 views (last 30 days)
Show older comments
Hi I tried two ways to rescale a matrix and display as an image: imagesc and wcodemat.
Worded well in Fig 1. But in figure 2: wcodemat changes the distribution of the numbers.
Can somebody tell me what's the cause? Thanks a lot!
The cat data can be downloaded here http://spark-public.s3.amazonaws.com/compmethods/Lecture%20Note%20Packet/catData.mat
My code is here:
%%test with woman
load woman;
% Get the range of the colormap
NBCOL = size(map,1);
% Obtain the 2D dwt using the Haar wavelet
[cA1,cH1,cV1,cD1] = dwt2(X,'db1');
figure;
% Display without scaling
subplot(2,3,1);
image(cA1);
colormap(map);
axis image; colorbar;
title('Unscaled Image');
subplot(2,3,4); hist(cA1);
% rescale with wcodemat
subplot(2,3,2);
image(wcodemat(cA1,NBCOL));
colormap(map);
axis image; colorbar;
title('Rescale w/ wcodemat');
subplot(2,3,5); hist(wcodemat(cA1,NBCOL));
% rescale with imagesc
subplot(2,3,3);
imagesc(cA1); axis image; colorbar;
title('Rescale w/ imagesc');
%%test with cat
load catData % each column is a 64*64 pixel (greyscale) picture, reshaped
% source: http://spark-public.s3.amazonaws.com/compmethods/Lecture%20Note%20Packet/catData.mat
p = double( reshape(cat(:,2),64,64) );
[cA, cH, cV, cD] = dwt2(p,'haar');
% Discrete wavelet transform, 2D.
% ch, cv, and cd are not scale 0-255
% cA is 1st level wavelet, and cH, cV, cD are 2nd level
contour1 = cH + cV;
figure(2);
subplot(2,3,1); image(contour1); axis image; colorbar;
title('Contour, un-rescaled');
subplot(2,3,4); hist(contour1);
subplot(2,3,2); imagesc(contour1); axis image; colorbar;
title('Contour, rescaled w/ imagesc');
% iamgesc scales the matrix and display the image
% now rescale the matrix manually
NBCOL = size(colormap(gray),1);
subplot(2,3,3);
contour2 = wcodemat(contour1, NBCOL);
image(contour2); axis image; colorbar;
title('Contour, rescaled w/ wcodemat');
subplot(2,3,6); hist(contour2);
0 Comments
Answers (0)
See Also
Categories
Find more on Denoising and Compression in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!