Sunteți pe pagina 1din 3

Lecture 2 - Linear and Non-Linear Image Wavelet Approximation

Abstract : The goals of this lecture is to manipulate wavelet transform of 2D images. We will thus learn how to apply this transform and to discover its structure. At last, we will perform linear and non-linear approximation by keeping only a few coefficients.

Computation and visualization of wavelet transforms.

2D wavelet transform (download the functions plot_wavelet and load_image.m and the images lena.png, boat.png et mandrill.png) % loading a 2D image n = 256; Jmin = 5; I = load_image('lena',n); % 2D wavelet transform Iw = perform_wavelet_transform(I,Jmin,+1); % computation until scale Jmin clf; subplot(1,2,1); imagesc(I); axis image; axis off; colormap gray(256); title('Original image'); subplot(1,2,2); plot_wavelet(Iw, Jmin); colormap gray(256); title('Transformed image');

Example of a 2D image and its wavelet transform. Large coefficients (in black or white) are located, at each scale, along edges of the image. In regular areas (for example on the shoulder) wavelet coefficients are very small (gray). Fine scale are in the bottom right. There is three kinds of coefficients (Horizontal / Vertical / Diagonal) per scale.

Inverse transform I1 = perform_wavelet_transform(Iw,Jmin,-1); % should recover the same image

Linear and non-linear approximation of a 2D image.

Linear approximation. % keep the first M coefficients M = 3000; [Y,X] = meshgrid(1:n,1:n); t = max(X,Y); [tmp,t] = sort(t(:)); % ordering of the coefficient, not that easy IwM = Iw; IwM( t(M+1:end) ) = 0; % reconstruction IM = perform_wavelet_transform(IwM,Jmin,-1);

Non-linear approximation % You have to find the threshold that allows to keep M coefficients T = ???; % perform thresholding IwT = Iw .* (abs(Iw)>T); % reconstruction IT = perform_wavelet_transform(IwT,Jmin,-1);

Display of the approximated images clf; subplot(1,3,1); imagesc(I); axis image; axis off; title('Original image'); subplot(1,3,2); imagesc(IM); axis image; axis off; title( ['Linear ' num2str(M) ' coef']); subplot(1,3,3); imagesc(IT); axis image; axis off; title( ['Non-linear ' num2str(M) ' coef']); colormap gray(256);

Comparison of linear and non-linear approximation. The linear wavelet approximation is not efficient because of the presence of discontinuities. One can see Gibbs oscilations near the discontinuities in the linear case. Non linear approximation performs better because it adapts to the discontinuities.

Comparison with the Fourier transform.

Linear approximation of a 2D image in the Fourier basis % 2D fourier transform If = fft2(I); % approximation If = fftshift(If); % recenter frequencies M = 50^2; mask = If*0; mask( end/2-sqrt(M)/2+1:end/2+sqrt(M)/2, end/2-sqrt(M)/2+1:end/2+sqrt(M)/2 ) = 1; IfM = If .* mask; If = fftshift(If); IfM = fftshift(IfM); % reconstruction IM = real(ifft2(IfM)); % inverse transform % dessin clf; % recenter frequencies subplot(1,3,1); imagesc(I); axis image; axis off; title('Image'); subplot(1,3,2); imagesc(-length(I)/2+1:length(I)/2, -length(I)/2+1:length(I)/2, log(abs(fftshift(If)))); axis image; title('log(Fourier)'); subplot(1,3,3); imagesc(IM); axis image; axis off; title(['Approx. lin. ' num2str(M) 'coef']); colormap gray(256);

Linear approximation in the Fourier basis performs poorly because of the edges that are present in natural images. Fourier approximation leads to "ghost edges" (Gibbs oscillations).

Copyright 2006 Gabriel Peyr

S-ar putea să vă placă și