display rescaled matrix as image: imagesc vs wcodemat

4 views (last 30 days)
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!
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');
% Display without scaling
axis image; colorbar;
title('Unscaled Image');
subplot(2,3,4); hist(cA1);
% rescale with wcodemat
axis image; colorbar;
title('Rescale w/ wcodemat');
subplot(2,3,5); hist(wcodemat(cA1,NBCOL));
% rescale with imagesc
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;
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);
contour2 = wcodemat(contour1, NBCOL);
image(contour2); axis image; colorbar;
title('Contour, rescaled w/ wcodemat');
subplot(2,3,6); hist(contour2);

Answers (0)


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!