Wavelet Toolbox |
Two-Dimensional Analysis Using the Command Line
In this example, we'll show how you can use two-dimensional stationary wavelet analysis to de-noise an image.
This example involves a image containing noise.
For the SWT, if a decomposition at level k
is needed, 2^k
must divide evenly into size(X,1)
and size(X,2)
. If your original image is not of correct size, you can use the Image Extension GUI tool or the function wextend
to extend it.
db1
wavelet. Type
This generates the coefficients matrices of the level-one approximation (swa
) and horizontal, vertical and diagonal details (swh
, swv
, and swd
, respectively). Both are of size-the-image size. Type
map = pink(size(map,1)); colormap(map) subplot(2,2,1), image(wcodemat(swa,192)); title('Approximation swa') subplot(2,2,2), image(wcodemat(swh,192)); title('Horiz. Detail swh') subplot(2,2,3), image(wcodemat(swv,192)); title('Vertical Detail swv') subplot(2,2,4), image(wcodemat(swd,192)); title('Diag. Detail swd').
A1
, H1
, V1
and D1
) from the coefficients swa
, swh
, swv
and swd
, type
db1
wavelet), type
This generates the coefficients of the approximations at levels 1, 2, and 3 (swa
) and the coefficients of the details (swh
, swv
and swd
). Observe that the matrices swa(:,:,i)
, swh(:,:,i)
, swv(:,:,i)
, and swd(:,:,i)
for a given level i
are of size-the-image size. Type
colormap(map) kp = 0; for i = 1:3 subplot(3,4,kp+1), image(wcodemat(swa(:,:,i),192)); title(['Approx. cfs level ',num2str(i)]) subplot(3,4,kp+2), image(wcodemat(swh(:,:,i),192)); title(['Horiz. Det. cfs level ',num2str(i)]) subplot(3,4,kp+3), image(wcodemat(swv(:,:,i),192)); title(['Vert. Det. cfs level ',num2str(i)]) subplot(3,4,kp+4), image(wcodemat(swd(:,:,i),192)); title(['Diag. Det. cfs level ',num2str(i)]) kp = kp + 4; end
To reconstruct the details at levels 1, 2 and 3, type
H = mzero; V = mzero; D = mzero; for i = 1:3 swcfs = mzero; swcfs(:,:,i) = swh(:,:,i); H(:,:,i) = iswt2(mzero,swcfs,mzero,mzero,'db1'); swcfs = mzero; swcfs(:,:,i) = swv(:,:,i); V(:,:,i) = iswt2(mzero,mzero,swcfs,mzero,'db1'); swcfs = mzero; swcfs(:,:,i) = swd(:,:,i); D(:,:,i) = iswt2(mzero,mzero,mzero,swcfs,'db1'); end
A(:,:,2) = A(:,:,3) + H(:,:,3) + V(:,:,3) + D(:,:,3); A(:,:,1) = A(:,:,2) + H(:,:,2) + V(:,:,2) + D(:,:,2);
To display the approximations and details at levels 1, 2, and 3, type
colormap(map) kp = 0; for i = 1:3 subplot(3,4,kp+1), image(wcodemat(A(:,:,i),192)); title(['Approx. level ',num2str(i)]) subplot(3,4,kp+2), image(wcodemat(H(:,:,i),192)); title(['Horiz. Det. level ',num2str(i)]) subplot(3,4,kp+3), image(wcodemat(V(:,:,i),192)); title(['Vert. Det. level ',num2str(i)]) subplot(3,4,kp+4), image(wcodemat(D(:,:,i),192)); title(['Diag. Det. level ',num2str(i)]) kp = kp + 4; end
wthresh
command to perform the actual thresholding of the detail coefficients, and then use the iswt2
command to obtain the de-noised image.
thr = 44.5; sorh = 's'; dswh = wthresh(swh,sorh,thr); dswv = wthresh(swv,sorh,thr); dswd = wthresh(swd,sorh,thr); clean = iswt2(swa,dswh,dswv,dswd,'db1');
To display both the original and de-noised images, type
colormap(map) subplot(1,2,1), image(wcodemat(X,192)); title('Original image') subplot(1,2,2), image(wcodemat(clean,192)); title('De-noised image')
A second syntax can be used for the swt2
and iswt2
functions, giving the same results:
lev = 4; swc = swt2(X,lev,'db1'); swcden = swc; swcden(:,:,1:end-1) = wthresh(swcden(:,:,1:end-1),sorh,thr); clean = iswt2(swcden,'db1');
You obtain the same plot by using the plot commands than in Step 14 above,
Two-Dimensional Discrete Stationary Wavelet Analysis | Two-Dimensional Analysis for De-Noising Using the Graphical Interface |
© 1994-2005 The MathWorks, Inc.