matlab - Wavelet Transform for N dimensions -
i came across amazing response applying matlab's idwt2
several times executed understand myself. however, unable how use same work rgb image. so, have 3 questions.
how code applied rgb image transformed image displayed in output along high , low frequency components along row , column,is possible view fusion of components single image? aware have put cat operator, cant understand how go it.
secondly, getting mazed image! perplexed since cannot seem follow reason. have attached same code statement showing how image has been generated.
3.what term
db1
in function signature ofdwt
imply?
code:
load woman; % load image data %startimage=imread('pic_rgb.jpg'); % if want work rgb image 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 startimage = x; ilevel = 1:nlevel, [ca{ilevel},ch{ilevel},cv{ilevel},cd{ilevel}] = dwt2(startimage,'db1'); startimage = ca{ilevel}; end figure;colormap(map); imagesc(dwt2(startimage,'db1')); %this gives mazed image instead of transformed image figure; tiledimage = wcodemat(ca{nlevel},ncolors); ilevel = nlevel:-1:1, tiledimage = [tiledimage wcodemat(ch{ilevel},ncolors); ... wcodemat(cv{ilevel},ncolors) wcodemat(cd{ilevel},ncolors)]; end figure; imshow(tiledimage,map); %reconstruct fullrecon = ca{nlevel}; ilevel = nlevel:-1:1, fullrecon = idwt2(fullrecon,ch{ilevel},cv{ilevel},cd{ilevel},'db1'); end partialrecon = ca{nlevel}; ilevel = nlevel:-1:1, partialrecon = idwt2(partialrecon,[],[],[],'db1'); end figure; imshow([x fullrecon; partialrecon zeros(size(x))],map,... 'initialmagnification',50);
the sample image used in my answer other question indexed image, there few changes need made code working rgb image.
i'll first address question 'db1'
argument passed dwt2. specifies type of wavelet use decomposition (in case, daubechies wavelet). more information available wavelets can found in documentation functions wfilters , waveinfo.
i'll address first 2 questions showing how modify code other answer work rgb image. i'll use sample 'peppers.png'
image. you'll first want load image , define number of values each color component has. since sample image unsigned 8-bit integer type (the common situation), ncolors
256:
x = imread('peppers.png'); %# load sample image ncolors = 256; %# number of values per color component
if images larger unsigned integer types (e.g. 'uint16'
), general way find number of color values use function intmax so:
ncolors = double(intmax(class(x)))+1;
for ensuing code, image type of 'uint8'
assumed.
applying decompositions no different in indexed image case. coefficient matrices m-by-n-by-3 matrices instead of 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; ilevel = 1:nlevel, %# apply nlevel decompositions [ca{ilevel},ch{ilevel},cv{ilevel},cd{ilevel}] = dwt2(startimage,'db1'); startimage = ca{ilevel}; end
the code create tiled image show horizontal, vertical, , diagonal components each decomposition change due fact working 3-d matrices , must use cat function instead of concatenation operator []
:
tiledimage = wcodemat(ca{nlevel},ncolors); 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)); %# convert unsigned 8-bit integer display
this give following image showing horizontal (top right), vertical (bottom left), , diagonal (bottom right) components each decomposition step, along reduced image (top left):
the reconstruction steps unchanged other answer. code displaying final images needs modified:
fullrecon = ca{nlevel}; ilevel = nlevel:-1:1, fullrecon = idwt2(fullrecon,ch{ilevel},cv{ilevel},cd{ilevel},'db1'); end partialrecon = ca{nlevel}; 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 image showing original rgb image (top left), fully-reconstructed image using of stored detail coefficient matrices (top right), , partially-reconstructed image using none of stored detail coefficient matrices (bottom left):
Comments
Post a Comment