I am having trouble understanding what is causing the problem to my Wavelet output when i am trying to display the image with the figure command.

I want to display both the Original image and its Wavelets decomposition, but when I'm using this code the original image is not displaying in a separate figure.

Here is my code,

im = imread('cameraman.tif');
imshow(im),title('Original Image')

[cA1,cH1,cV1,cD1] = dwt2(im,'bior3.7');
A1 = upcoef2('a',cA1,'bior3.7',1);
H1 = upcoef2('h',cH1,'bior3.7',1);
V1 = upcoef2('v',cV1,'bior3.7',1);
D1 = upcoef2('d',cD1,'bior3.7',1);

% To display the results of the level 1 decomposition, type:

subplot(2,2,1); image(wcodemat(A1,192));
title('Approximation A1')

subplot(2,2,2); image(wcodemat(H1,192));
title('Horizontal Detail H1')

subplot(2,2,3); image(wcodemat(V1,192));
title('Vertical Detail V1')

subplot(2,2,4); image(wcodemat(D1,192));
title('Diagonal Detail D1')

and the output of this code is just one figure with four plots (Digonal, Horizontal, Vertical details and Approximations)

enter image description here

but when I'm using figure command to display the original image in a separate figure,

 im = imread('cameraman.tif');
imshow(im),title('Original Image')

it messes up the wavelet output,

enter image description here

Why does it happens that my output is changed to blue and red color ?


The reasoning is simple. MATLAB defaults to a 'jetblue' colormap when you use imshow(im).

Typically you need to specify the colormap being used when you use imshow.

For this, add another command like:


to your current script.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.