Using wavelets for image decomposition / reconstruction

4 views (last 30 days)
I want to use wavelets decompose/reconstruct on images. If i try to read the mandrill image using rgb2ind command, the decompose/reconstructed image does not match the original. However this works well with MAtlab defined load mandrill command. Why ?
% Option 1
load mandrill;
% Option 2
% rgb = imread('mand_image.jpg'); [X,map] = rgb2ind(rgb, (2^4)-1) ;
% Below program is an example program from Matlab help for dwt2 command
% When this command is used, a image is decomposed to half its size
% and using idwt2 and the decomposed arrays, the original image can be re-constructed
%
% Option 1 : Run the below program with
% load mandrill statement uncommented and statement rgb = ... commented
% Option 2 : Run the below program with
% statement rgb = ... uncommented and load mandrill statement commented and
% In Option 1 i am able to match the input and output images
% In Option 2 it is not happening. I am not able to figure out how
% to create [X,map] arrays using rgb2ind command
% Perform single-level decomposition of X using db1.
[cA1,cH1,cV1,cD1] = dwt2(X,'db1');
figure; imshow(X,map);title('Original Image');
figure; imshow(cA1,map);title('Decompose L1 Image');
sX = size(X);
%Convert back
A3 = idwt2(cA1,cH1,cV1,cD1,'db1');
figure; imshow(A3,map);title('Re-composed Image');

Answers (2)

Wayne King
Wayne King on 29 Aug 2011
Hi Srikanth
load mandrill;
gives you an array of class double. What is the class of X in the output of rbg2ind?
Did you use imwrite to create the .jpg file from the array X in the workspace? If so, show us the code.
Also, please use the {} Code features in Answers, so that people can read your code more easily.
Wayne
  1 Comment
Srikanth
Srikanth on 5 Sep 2011
Dear Wayne
rgb2ind gives output of X as unit8.
I downloaded a mandrill image from internet. This image i read into Matlab using imread command.
Srikanth

Sign in to comment.


rudi setiawan
rudi setiawan on 4 Feb 2012
I think, you must change the value in rgb2ind(RGB, n), n = 256 or 128, it must suitable with your image size, if you want to show the decode image, you must convert first to uint8
[X, map] = rgb2ind(RGB, 256);
figure; imshow(X,map);title('Original Image');[cA1,cH1,cV1,cD1] = dwt2(X,'db1');
figure; imshow(cA1,map);title('Decompose L1 Image');
figure; imshow(X,map);title('Original Image');figure; imshow(uint8(cA1),map);title('Decompose L1 Image');
A3 = idwt2(cA1,cH1,cV1,cD1,'db1');
imshow(uint8(A3),map);title('Re-composed Image');

Categories

Find more on Wavelet Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!