The sample image used in my answer to this other question was an indexed image , so you need to make a few changes to make this code work for an RGB image .
First, I will consider the issue of the 'db1' argument passed to DWT2 . This indicates the type of wavelet that will be used for decomposition (in this case, the Daubechies wavelet ). For more information on the available bursts, see the documentation for the WFILTERS and WAVEINFO functions .
I will cover your first two questions, showing you how to change the code from my other answer to working with an RGB image. I will use the sample image 'peppers.png' . First you want to upload your image and determine the number of values ββthat each color component has. Since the sample image is an unsigned 8-bit integer type (the most common situation), nColors will be 256:
X = imread('peppers.png'); %# Load sample image nColors = 256; %# Number of values per color component
If your images are large unsigned integer types (for example, 'uint16' ), the general way to find the number of color values ββis to use the INTMAX function:
nColors = double(intmax(class(X)))+1;
The following code assumes an image type of 'uint8' .
The use of decompositions does not differ from the case with the indexed image. The matrices of coefficients are simply M-by-N-by-3 matrices instead of the M-by-N matrices:
nLevel = 3; %# Number of decompositions cA = cell(1,nLevel); %# Approximation coefficient storage cH = cell(1,nLevel); %# Horizontal detail coefficient storage cV = cell(1,nLevel); %# Vertical detail coefficient storage cD = cell(1,nLevel); %# Diagonal detail coefficient storage startImage = X; for iLevel = 1:nLevel, %# Apply nLevel decompositions [cA{iLevel},cH{iLevel},cV{iLevel},cD{iLevel}] = dwt2(startImage,'db1'); startImage = cA{iLevel}; end
The code for creating a tiled image to display horizontal, vertical and diagonal components for each decomposition will change due to the fact that we are now working with 3-D matrices and should use CAT instead of the concatenation operator [] :
tiledImage = wcodemat(cA{nLevel},nColors); for iLevel = nLevel:-1:1 tiledImage = cat(1,cat(2,tiledImage,... wcodemat(cH{iLevel},nColors)),... cat(2,wcodemat(cV{iLevel},nColors),... wcodemat(cD{iLevel},nColors))); end figure; imshow(uint8(tiledImage-1)); %
This will produce the following image showing the horizontal (top right), vertical (bottom left) and diagonal (bottom right) components for each decomposition step along with a thumbnail (top left):

Recovery steps are not changed compared to the other answer. Only the code needs to be changed to display the final images:
fullRecon = cA{nLevel}; for iLevel = nLevel:-1:1, fullRecon = idwt2(fullRecon,cH{iLevel},cV{iLevel},cD{iLevel},'db1'); end partialRecon = cA{nLevel}; for iLevel = nLevel:-1:1, partialRecon = idwt2(partialRecon,[],[],[],'db1'); end figure; tiledImage = cat(1,cat(2,X,uint8(fullRecon)),... cat(2,uint8(partialRecon),zeros(size(X),'uint8'))); imshow(tiledImage,'InitialMagnification',50);
And you get an image showing the original RGB image (top left), a fully restored image using all matrices of the stored part matrices (top right) and a partially restored image using none of the saved matrix detail coefficient (bottom left):
