Académique Documents
Professionnel Documents
Culture Documents
Search:
Go
Log In
File Exchange
Answers
Newsgroup
Link Exchange
Blogs
Trendy
Cody
Contest
MathWorks.com
Download Submission
by Gabriel Peyre A set of Matlab experiments that illustrates advanced computational signal and image processing.
Highlights from
Contents
Installing toolboxes and setting up the path. Noise in Signal and Image Linear Signal Denoising Linear Image Denoising Wiener filtering
compute_conditional_histo... compute_conditional_histogram compute conditional histograms compute_entropy(M,T) compute_entropy - compute the entropy of a signal compute_gaussian_filter(n... compute_gaussian_filter - compute a 1D or 2D Gaussian filter. compute_histogram(M, opti... compute_histogram - compute the (symmetric) histogram of a vector after threshold. compute_hufftree(p) compute_hufftree - build a huffman tree compute_l2err(MF, donorma... compute_l2err - non linear approximation error compute_max(X,d) compute_max - compute maximum along dimension d compute_min(X,d) compute_min - compute min along dimension d compute_quadsel(j,q, opti... compute_quadsel - compute the indices for selecting subband of a wavelet transform. compute_shape_boundary(M) compute_shape_boundary - extract boundary points of a shape compute_total_variation(y... compute_total_variation - compute the total variation of an image compute_wavelet_filter(Ty... compute_wavelet_filter - Generate Orthonormal QMF Filter for Wavelet Transform crop(M,n,c) crop - crop an image to reduce its size det3(A) det3 - 3x3 determinant div(Px,Py, options) div - divergence operator extend_stack_size(mult) does nothing gamrnd(a,b,m,n); GAMRND Random matrices from
Then you can add these toolboxes to the path. % Add some directories to the path getd('toolbox_signal/'); getd('toolbox_general/');
We add some noise to it. sigma = .04; % noise level x = x0 + sigma*randn(size(x0)); clf; subplot(2,1,1); plot(x0); axis([1 n -.05 1.05]); subplot(2,1,2); plot(x); axis([1 n -.05 1.05]);
A Numerical Tour of Signal Processing: Image Denoising with Linear Methods - File Exchange - MATLAB Central
gamma distribution. getoptions(options, name,... getoptions - retrieve options parameter grad(M, options) grad - gradient, forward differences huffman_gencode(T) huffman_gencode - generate a code associated to a Hufmann tree T idct(b,n) IDCT Inverse discrete cosine transform. We load an image. name = 'boat'; n = 256; M0 = load_image(name,n); M0 = rescale( M0, .05, .95 ); idct2(arg1,mrows,ncols) IDCT2 Compute 2-D inverse discrete cosine transform. image_resize(M,p1,q1,r1) image_resize - resize an image using bicubic interpolation imageplot(M,str, a,b,c) Then we add some gaussian noise to it. sigma = .08; % noise level M = M0 + sigma*randn(size(M0)); clf; imageplot(M0, 'Original', 1,2,1); imageplot(clamp(M), 'Noisy', 1,2,2); imageplot - diplay an image and a title iradon(varargin) IRADON Compute inverse Radon transform. load_image(type, n, optio... load_image - load benchmark images. load_signal(name, n, opti... load_signal - load a 1D signal load_sound(name, n0, opti... mad(x,flag) MAD Mean/median absolute deviation. make_sparse(i,j,x) make_sparse - synonymous with sparse(i,j,x) max3(x,v) max3 - synonymouse with max nb_dims(x) nb_dims - debugged version of ndims. peform_wiener_filtering(x... peform_wiener_filtering - perform Wiener filtering perform_arith_coding(xC, ... perform_arithmetic_coding_slow perform adaptive arithmetic coding perform_arith_fixed(x, h, n) perform_arith_fixed - arithmetic coding perform_blurring(M, sigma... perform_blurring - gaussian blurs an image
perform_cg(A,y,options) perform_convolution(x,h, ... perform_convolution - compute convolution with centered filter. perform_faces_reorientati... perform_faces_reorientation reorient the faces with respect to the center of the mesh perform_haar_transf(f, Jm... perform_haar_transf - peform fast Haar transform perform_hist_eq(x,y,options) perform_histogram_equalization perform histogram equalization
The Fourier transform of a Gaussian discrete filter is nearly a Gaussian whose width is proportional to 1/mu . % Fourier transform of the (centered) filter hf = real( fft(fftshift(h)) ); hf = fftshift(hf); % display clf; subplot(2,1,1); plot( t,h ); axis('tight'); title('Filter h');
perform_homotopy(D,y,opti... perform_homotopy - compute the L1 regularization path perform_huffcoding(x,T,dir) perform_huffcoding - perform huffman coding perform_median_filtering(... perform_median_filtering - perform moving average median perform_omp(D,Y,options)
A Numerical Tour of Signal Processing: Image Denoising with Linear Methods - File Exchange - MATLAB Central
subplot(2,1,2); plot( t,hf ); axis('tight'); title('Fourier transform');
perform_omp - perform orthogonal matching pursuit perform_saturation(x,tau,... perform_saturation - saturate a vector for better contrast perform_stft(x, w,q, opti... perform_stft - compute a local Fourier transform perform_tensor_decomp(T,o... perform_tensor_decomp - perform an eigendecomposition. perform_tensor_recomp(e1,... perform_tensor_recomp - create the tensor field corresponding to the given eigendecomposition. perform_thresholding(x, t... perform_thresholding - perform hard or soft thresholding perform_tv_denoising(x,op... perform_tv_denoising - denoising with TV minimization perform_wavelet_transf(x,... perform_wavelet_transf - peform fast lifting transform perform_wavortho_transf(f... perform_wavortho_transf - compute orthogonal wavelet transform plot_dictionnary(D,X,nb, ...
Since we use periodic boundary condition, the convolution of x with h can be computer over the Fourier domain. % Fourier coefficients of the noisy signal xf = fft(x); % Fourier coefficients of the denoised signal xhf = xf .* fft(fftshift(h)); % Denoised signal xh = real( ifft(xhf) );
plot_dictionnary - display a dictionary of images plot_hufftree(T,p) plot_hufftree - plot a huffman tree plot_levelset(M,t,A) plot_levelset - display the level set of an image plot_sparse_diracs(x, opt... plot_sparse_diracs - plot sparse sets of diracs
We display the denoised signal. Although most of the noise is removed, the singularity have been blurred. clf; subplot(2,1,1); plot( t,x ); axis('tight'); title('Noisy'); subplot(2,1,2); plot( t,xh ); axis('tight'); title('Denoised');
plot_spectrogram(S,f, opt... plot_spectrogram - display the spectrogram plot_vf(vf, M, options) plot_vf - plot a vector field with plot_wavelet(M, Jmin, opt... plot_wavelet - plot 2D wavelet transform stored using Mallat's ordering. poissrnd(lambda,m,n) POISSRND Random matrices from Poisson distribution. progressbar(n,N,w) progressbar - display a progress bar psnr(x,y, vmax) psnr - compute the Peack Signal to Noise Ratio r=binornd(n,p,mm,nn) BINORND Random matrices from a binomial distribution. radon(IMG, THETA) This MATLAB function takes an image matrix and vector of angles and then rand_discr(p, m) rand_discr - discrete random generator read_bin(name,options) read_bin - read bin file rescale(x,a,b) reverse(x) flip a vector set_axis(v) set_axis - draw axis on/off set_colormap(a) set_colormap - set colors for display set_graphic_sizes(h,fs,lw) set_graphic_sizes - enlarge the size of the fonts set_label(xstr,ystr,zstr) set_label - set the label for a plot set_linewidth(h,lw) set_rand_seeds(a,b) set_rand_seeds - initialize rand and randn snr(x,y) snr - signal to noise ratio subsampling(x,d,p)
We display the noisy and denoised Fourier coefficients. One can see that the denoising remove the high frequency coefficients. % log of Fourier transforms epsilon = 1e-10; L0 = log10(epsilon+abs(fftshift(fft(x0)))); L = log10(epsilon+abs(fftshift(xf))); Lh = log10(epsilon+abs(fftshift(xhf))); % display Fourier transforms clf; subplot(2,1,1); plot( t, L, '-' ); axis([-length(x)/2 length(x)/2 -4 max(L)]); title('log of noisy Fourier coefs.'); subplot(2,1,2); plot( t, Lh, '-' ); axis([-length(x)/2 length(x)/2 -4 max(L)]); title('log of denoised Fourier coefs.');
A Numerical Tour of Signal Processing: Image Denoising with Linear Methods - File Exchange - MATLAB Central
downsampling - subsampling along dimension d subselectdim(f,sel,d) subselectdim - select along a dimension sum3(M,k) for Scilab compatibility tet2tri(facet, vertex, ke... tet2tri - convert a tet mesh to a tri mesh upsampling(x,d,p) upsampling - add p zeros between samples along dimension d using_matlab() using_matlab - return 1 for Matlab, 0 for Scilab write_bin(M, name) write_bin - write a file to .bin format readable by scilab. batch_convert_bin.m View all files
It is non-trivial to select the width parameter mu to minimize the denoising error. It should account for both the variance of the noise and the power spectrum of the image. We display the blurring for an increasing value of mu . mulist = linspace(.5,4,4); clf; for i=1:length(mulist) mu = mulist(i); % compute the filter h = exp( -(t.^2)/(2*mu^2) ); h = h/sum(h(:)); % perform the blurring xh = real( ifft( fft(x) .* fft(fftshift(h)) )); subplot( 4,1,i ); plot(t, clamp(xh) ); axis('tight'); title(strcat(['\mu=' num2str(mu)])); end
Exercice 1: (the solution is exo1.m) Try for various Gaussian variance mu to compute the denoising xh . Compute, in an oracle manner, the best variance muopt by computing the residual error snr(x0,xh) . exo1;
A Numerical Tour of Signal Processing: Image Denoising with Linear Methods - File Exchange - MATLAB Central
Display the results. % compute the optimal filter h = exp( -(t.^2)/(2*muopt^2) ); h = h/sum(h(:)); % perform blurring xh = real( ifft( fft(x) .* fft(fftshift(h)) )); % display clf; subplot(2,1,1); plot(t, clamp(x)); axis('tight'); title('Noisy'); subplot(2,1,2); plot(t, clamp(xh)); axis('tight'); title('Denoised');
A Numerical Tour of Signal Processing: Image Denoising with Linear Methods - File Exchange - MATLAB Central
We display the blurring for an increasing value of mu . mulist = linspace(3,15,6); clf; for i=1:length(mulist) mu = mulist(i); Mh = perform_blurring(M,mu,options); imageplot(clamp(Mh), strcat(['\mu=' num2str(mu)]), 2,3,i); end
Exercice 2: (the solution is exo2.m) Try for various Gaussian variance to compute the denoising Mh . Compute, in an oracle manner, the best variance muopt by computing the residual error snr(M0,Mh) . exo2;
A Numerical Tour of Signal Processing: Image Denoising with Linear Methods - File Exchange - MATLAB Central
Display the results % optimal filter Mgauss = perform_blurring(M,muopt,options); % display clf; imageplot(M, strcat(['Noisy, SNR=' num2str(snr(M0,M)) 'dB']), 1,2,1); imageplot(Mgauss, strcat(['Gaussian denoise, SNR=' num2str(snr(M0,Mgauss)) 'dB']), 1,2,2);
Wiener filtering
In a probabilistic setting, for translation invariant signal distributions, the Wiener filtering is the optimal filtering. Perform the wiener filtering [Mwien,Hwien] = peform_wiener_filtering(M0,M,sigma);
A Numerical Tour of Signal Processing: Image Denoising with Linear Methods - File Exchange - MATLAB Central
display the result % display clf; imageplot( clamp(Mgauss), strcat(['Gaussian denoise, SNR=' num2str(snr(M0,Mgauss)) 'dB']), 1,2,1); imageplot( clamp(Mwien), strcat(['Wiener denoise, SNR=' num2str(snr(M0,Mwien)) 'dB']), 1,2,2);
Contact us
1994-2013 The MathWorks, Inc. Featured MathWorks.com Topics: Site Help Patents Trademarks Support Privacy Policy Preventing Piracy Webinars Terms of Use Newsletters MATLAB Trials Careers
New Products
Documentation
Training