signal and image noise models

16
11/12/13 Signal and Image Noise Models https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 1/16 Signal and Image Noise Models This numerical tour show several models for signal and image noise. It shows how to estimate the noise level for a Gaussian additive noise on a natural image. It also shows the relevance of thresholding to remove Gaussian noise contaminating sparse data. Contents Installing toolboxes and setting up the path. Additive Gaussian Noise Model Additive Uniform Noise Impulse Noise Thresholding Estimator and Sparsity Estimating the noise level Installing toolboxes and setting up the path. You need to download the following files: signal toolbox and general toolbox. You need to unzip these toolboxes in your working directory, so that you have toolbox_signal and toolbox_general in your directory. For Scilab user: you must replace the Matlab comment '%' by its Scilab counterpart '//'. Recommandation: You should create a text file named for instance numericaltour.sce (in Scilab) or numericaltour.m (in Matlab) to write all the Scilab/Matlab command you want to execute. Then, simply run exec('numericaltour.sce'); (in Scilab) or numericaltour; (in Matlab) to run the commands. Execute this line only if you are using Matlab. getd = @(p)path(p,path); % scilab users must *not* execute this Then you can add the toolboxes to the path. getd( 'toolbox_signal/' ); getd( 'toolbox_general/' ); Additive Gaussian Noise Model

Upload: papersaint

Post on 14-Sep-2015

254 views

Category:

Documents


3 download

DESCRIPTION

Noise models for image processing and implementation in MATLAB.

TRANSCRIPT

  • 11/12/13 Signal and Image Noise Models

    https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 1/16

    Signal and Image Noise Models

    This numerical tour show several models for signal and image noise. It showshow to estimate the noise level for a Gaussian additive noise on a naturalimage. It also shows the relevance of thresholding to remove Gaussian noisecontaminating sparse data.

    Contents

    Installing toolboxes and setting up the path.Additive Gaussian Noise ModelAdditive Uniform NoiseImpulse NoiseThresholding Estimator and SparsityEstimating the noise level

    Installing toolboxes and setting up the path.

    You need to download the following files: signal toolbox and general toolbox.

    You need to unzip these toolboxes in your working directory, so that you havetoolbox_signal and toolbox_general in your directory.

    For Scilab user: you must replace the Matlab comment '%' by its Scilabcounterpart '//'.

    Recommandation: You should create a text file named for instancenumericaltour.sce (in Scilab) or numericaltour.m (in Matlab) to write all theScilab/Matlab command you want to execute. Then, simply runexec('numericaltour.sce'); (in Scilab) or numericaltour; (in Matlab) to run thecommands.

    Execute this line only if you are using Matlab.

    getd = @(p)path(p,path); % scilab users must *not* execute this

    Then you can add the toolboxes to the path.

    getd('toolbox_signal/');getd('toolbox_general/');

    Additive Gaussian Noise Model

  • 11/12/13 Signal and Image Noise Models

    https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 2/16

    The simplest noise model consist in adding a realization of a zero meanrandom vector to a clean signal or image.

    Load a clean image.

    N = 128;name = 'boat';M0 = load_image(name,256);M0 = rescale(crop(M0,N));

    Load a clean signal.

    n = 1024;name = 'piece-regular';f0 = rescale( load_signal(name,n) );

    The simplest noise model is Gaussian white noise. Here we generate a noisysignal or image.

    sigma = .1;M = M0 + randn(N,N)*sigma;f = f0 + randn(n,1)*sigma;

    Display the signals.

    clf;subplot(3,1,1);plot(f0); axis([1 n 0 1]);title('Clean signal');subplot(3,1,2);plot(f-f0); axis([1 n -3*sigma 3*sigma]);title('Noise');subplot(3,1,3);plot(f); axis([1 n 0 1]);title('Noisy signal');

  • 11/12/13 Signal and Image Noise Models

    https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 3/16

    Display the images.

    clf;imageplot(M0, 'Clean image', 1,3,1);imageplot(M-M0, 'Noise', 1,3,2);imageplot(clamp(M), 'Noisy image', 1,3,3);

  • 11/12/13 Signal and Image Noise Models

    https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 4/16

    Display the statistics of the noise

    nbins = 51;[h,t] = hist( M(:)-M0(:), nbins ); h = h/sum(h);subplot(3,1,2);bar(t,h);axis([-sigma*5 sigma*5 0 max(h)*1.01]);

  • 11/12/13 Signal and Image Noise Models

    https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 5/16

    Additive Uniform Noise

    A slightly different kind of noise is uniform in a given interval.

    Generate noisy data with uniform noise distribution in [-a,a], with a chosen sothat the variance is sigma.

    a = sqrt(3)*sigma;M = M0 + 2*(rand(N,N)-.5)*a;f = f0 + 2*(rand(n,1)-.5)*a;

    Display the signals.

    clf;subplot(3,1,1);plot(f0); axis([1 n 0 1]);title('Clean signal');subplot(3,1,2);plot(f-f0); axis([1 n -3*sigma 3*sigma]);title('Noise');subplot(3,1,3);plot(f); axis([1 n 0 1]);title('Noisy signal');

  • 11/12/13 Signal and Image Noise Models

    https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 6/16

    Display the images.

    clf;imageplot(M0, 'Clean image', 1,3,1);imageplot(M-M0, 'Noise', 1,3,2);imageplot(clamp(M), 'Noisy image', 1,3,3);

  • 11/12/13 Signal and Image Noise Models

    https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 7/16

    Display the statistics of the noise

    nbins = 51;[h,t] = hist( M(:)-M0(:), nbins ); h = h/sum(h);subplot(3,1,2);bar(t,h);axis([-sigma*5 sigma*5 0 max(h)*1.01]);

  • 11/12/13 Signal and Image Noise Models

    https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 8/16

    Impulse Noise

    A very different noise model consist in sparse impulsions, generate by arandom distribution with slowly decaying probability.

    Generate noisy image with exponential distribution, with variance sigma.

    W = log(rand(N,N)).*sign(randn(N,N));W = W/std(W(:))*sigma;M = M0 + W;

    Generate noisy signal with exponential distribution, with variance sigma.

    W = log(rand(n,1)).*sign(randn(n,1));W = W/std(W(:))*sigma;f = f0 + W;

    Display the signals.

    clf;subplot(3,1,1);plot(f0); axis([1 n 0 1]);title('Clean signal');subplot(3,1,2);

  • 11/12/13 Signal and Image Noise Models

    https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 9/16

    plot(f-f0); axis([1 n -3*sigma 3*sigma]);

    title('Noise');subplot(3,1,3);plot(f); axis([1 n 0 1]);title('Noisy signal');

    Display the images.

    clf;imageplot(M0, 'Clean image', 1,3,1);imageplot(M-M0, 'Noise', 1,3,2);imageplot(clamp(M), 'Noisy image', 1,3,3);

  • 11/12/13 Signal and Image Noise Models

    https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 10/16

    Display the statistics of the noise

    nbins = 51;[h,t] = hist( M(:)-M0(:), nbins ); h = h/sum(h);subplot(3,1,2);bar(t,h);axis([-sigma*5 sigma*5 0 max(h)*1.01]);

  • 11/12/13 Signal and Image Noise Models

    https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 11/16

    Thresholding Estimator and Sparsity

    The idea of non-linear denoising is to use an orthogonal basis in which thecoefficients x of the signal or image M0 is sparse (a few large coefficients). Inthis case, the noisy coefficients x of the noisy data M (perturbated withGaussian noise) are x0+noise where noise is Gaussian. A thresholding set to 0the noise coefficients that are below T. The threshold level T should be chosenjudiciously to be just above the noise level.

    First we generate a spiky signal.

    % dimensionn = 4096;% probability of spikingrho = .05;% location of the spikex0 = rand(n,1)

  • 11/12/13 Signal and Image Noise Models

    https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 12/16

    Display.

    clf;subplot(2,1,1);plot(x0); axis([1 n -1 1]);set_graphic_sizes([], 20);title('Original signal');subplot(2,1,2);plot(x); axis([1 n -1 1]);set_graphic_sizes([], 20);title('Noisy signal');

    Exercice 1: (the solution is exo1.m) What is the optimal threshold T to removeas much as possible of noise ? Try several values of T.

    exo1;

  • 11/12/13 Signal and Image Noise Models

    https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 13/16

    In order to be optimal without knowing in advance the amplitude of thecoefficients of x0, one needs to set T just above the noise level. This meansthat T should be roughly equal to the maximum value of a Gaussian whitenoise of size n.

    Exercice 2: (the solution is exo2.m) The theory predicts that the maximum ofn Gaussian variable of variance sigma^2 is smaller than sqrt(2*log(n)) with largeprobability (that tends to 1 when n increases). This is also a sharp result.Check this numerically by computing with Monte Carlo sampling the maximumwith n increasing (in power of 2). Check also the deviation of the maximumwhen you perform several trial with n fixed.

    exo2;

  • 11/12/13 Signal and Image Noise Models

    https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 14/16

    Estimating the noise level

    In practice, the noise level sigma is unknown. For additive Gaussian noise, agood estimator is given by the median of the wavelet coefficients at the finerscale. An even simple estimator is given by the normalized derivate along X orY direction

    Load a clean image.

    n = 256;M0 = rescale(load_image('boat', n));

    Generate a noisy image.

    sigma = 0.06;M = M0 + randn(n,n)*sigma;

    First we extract the high frequency residual.

    H = M;H = (H(1:n-1,:) - H(2:n,:))'/sqrt(2);H = (H(1:n-1,:) - H(2:n,:))'/sqrt(2);

  • 11/12/13 Signal and Image Noise Models

    https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 15/16

    Display.

    clf;imageplot(clamp(M), 'Noisy image', 1,2,1);imageplot(H, 'Derivative image', 1,2,2);

    Histograms.

    [h,t] = hist(H(:), 100);h = h/sum(h);

    Display histogram.

    clf;bar(t, h);axis([-.5 .5 0 max(h)]);

  • 11/12/13 Signal and Image Noise Models

    https://www.ceremade.dauphine.fr/~peyre/numerical-tour/tours/denoisingsimp_1_noise_models/ 16/16

    The mad estimator (median of median) must be rescaled so that it gives thecorrect variance for gaussian noise.

    sigma_est = mad(H(:),1)/0.6745;disp( strcat(['Estimated noise level=' num2str(sigma_est), ', true=' num2str(sigma)]) );

    Estimated noise level=0.065772, true=0.06

    Copyright 2008 Gabriel Peyre