Looking at the documentation for dwt2
and idwt2
, it appears that you have 2 general options for reconstructing your multiply-decomposed images:
- Store all of the horizontal, vertical, and diagonal detail coefficient matrices from each decomposition step and use them in the reconstruction.
- Enter an empty matrix (
[]
) for any detail coefficient matrices that you didn't save from previous decomposition steps.
Since it was a slow day, here's some code showing how to do this and what the results look like for each case...
First, load a sample image and initialize some variables:
load woman; % Load image data
nLevel = 3; % Number of decompositions
nColors = size(map, 1); % Number of colors in colormap
cA = cell(1, nLevel); % Approximation coefficients
cH = cell(1, nLevel); % Horizontal detail coefficients
cV = cell(1, nLevel); % Vertical detail coefficients
cD = cell(1, nLevel); % Diagonal detail coefficients
Now, apply the decompositions (in this case 3) and store the detail coefficient matrices from each step in a cell array:
startImage = X;
for iLevel = 1:nLevel,
[cA{iLevel}, cH{iLevel}, cV{iLevel}, cD{iLevel}] = dwt2(startImage, 'db1');
startImage = cA{iLevel};
end
To see what the final decomposed image looks like, along with all the detail coefficient matrices along the way, run the following code (which makes use of wcodemat
):
tiledImage = wcodemat(cA{nLevel}, nColors);
for iLevel = nLevel:-1:1,
tiledImage = [tiledImage wcodemat(cH{iLevel}, nColors); ...
wcodemat(cV{iLevel}, nColors) wcodemat(cD{iLevel}, nColors)];
end
figure;
imshow(tiledImage, map);
You should see something like this:
Now it's time to reconstruct! The following code performs a "full" reconstruction (using all of the stored detail coefficient matrices) and a "partial" reconstruction (using none of them), then it plots the 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;
imshow([X fullRecon; partialRecon zeros(size(X))], map, ...
'InitialMagnification', 50);
Notice that the original (top left) and the "full" reconstruction (top right) look indistinguishable, but the "partial" reconstruction (lower left) is very pixelated. The difference wouldn't be as severe if you applied fewer decomposition steps, like just 1 or 2.