normal distribn theory

Upload: guru-ballur

Post on 10-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 Normal Distribn Theory

    1/16

    How to normalize an image to zero mean and unit variance

    From:Rob Gens

    Date: 7 Apr, 2009 10:46:02

    Message: 10 of 13

    Reply to this messageAdd author to My Watch ListView original formatFlag as spam

    > NormalizedArray = (TheArray-mean(TheArray(:))) ./ var(TheArray(:));>> To normalize to 0 mean, subtract off the mean. To normalize to unit variance, divide by> the variance. The variance is independent of the mean, so there is no need to take> the variance -after- subtracting the mean: the variance of the original array will be> identical.

    I'm afraid that is incorrect. You should divide by the standard deviation which is the square root of the variance.

    NormalizedArray = (TheArray-mean(TheArray(:))) ./ sqrt(var(TheArray(:)));

    the function ' randn' gives only random nos. but based on mean=0, variance=1>and S.D=1.>>But, I need to vary the variance of this function from 1 to 2, 3,...10. ..to>simulate a gaussian white noise. May some expert teach me how to do it ?

    Here's a simple example:

    meanx = 3;stdx = 5;x = meanx + stdx*randn(50,1);

    14. Normal Probability Distributions

    The Normal Probability Distribution is very common in the field of statistics. Whenever you measure things like people's height, weight,salary, opinions or votes, the graph of the results is very often a normal curve.

    The Normal Distribution

    On this page...

    Properties of a normal distribution

    Area under the normal curve

    Standard normal distribution

    Percentages of the area under standard normal curve

    http://www.mathworks.de/matlabcentral/newsreader/author/112410http://www.mathworks.de/matlabcentral/newsreader/create_message?reply_id=640981http://www.mathworks.de/matlabcentral/newsreader/create_author_watchlist/112410?thread=236272http://www.mathworks.de/matlabcentral/newsreader/create_author_watchlist/112410?thread=236272http://www.mathworks.de/matlabcentral/newsreader/view_original/640981http://www.mathworks.de/matlabcentral/newsreader/flagged_as_spam/640981http://www.mathworks.de/matlabcentral/newsreader/flagged_as_spam/640981http://www.intmath.com/Counting-probability/14_Normal-probability-distribution.php#propertieshttp://www.intmath.com/Counting-probability/14_Normal-probability-distribution.php#areahttp://www.intmath.com/Counting-probability/14_Normal-probability-distribution.php#standard-normalhttp://www.intmath.com/Counting-probability/14_Normal-probability-distribution.php#percenthttp://www.mathworks.de/matlabcentral/newsreader/create_message?reply_id=640981http://www.mathworks.de/matlabcentral/newsreader/create_author_watchlist/112410?thread=236272http://www.mathworks.de/matlabcentral/newsreader/view_original/640981http://www.mathworks.de/matlabcentral/newsreader/flagged_as_spam/640981http://www.intmath.com/Counting-probability/14_Normal-probability-distribution.php#propertieshttp://www.intmath.com/Counting-probability/14_Normal-probability-distribution.php#areahttp://www.intmath.com/Counting-probability/14_Normal-probability-distribution.php#standard-normalhttp://www.intmath.com/Counting-probability/14_Normal-probability-distribution.php#percenthttp://www.mathworks.de/matlabcentral/newsreader/author/112410
  • 8/8/2019 Normal Distribn Theory

    2/16

    The z-Table

    Application - stock market

    A random variableXwhose distribution has the shape of a normal curve is called a normal random variable.

    Normal Curve

    This random variableXis said to be normally distributed with mean and standard deviation if its probability distribution is given by

    Properties of a Normal Distribution

    1. The normal curve is symmetrical about the mean ;

    2. The mean is at the middle and divides the area into halves;3. The total area under the curve is equal to 1;4. It is completely determined by its mean and standard deviation (or variance 2)

    Note:

    In a normal distribution, only 2 parameters are needed, namely and 2.

    Area Under the Normal Curve using Integration

    The probability of a continuous normal variableXfound in a particular interval [a, b] is the area under the curve bounded byx = a andx= b and is given by

    and the area depends upon the values of and .

    [SeeArea under a Curve for more information on using integration to find areas under curves. Don't worry - we don't have to performthis integration - we'll use the computer to do it for us.]

    The Standard Normal Distribution

    http://www.intmath.com/Counting-probability/14_Normal-probability-distribution.php#z-tablehttp://www.intmath.com/Counting-probability/14_Normal-probability-distribution.php#stockshttp://www.intmath.com/applications-integration/2-area-under-curve.phphttp://www.intmath.com/applications-integration/2-area-under-curve.phphttp://www.intmath.com/Counting-probability/14_Normal-probability-distribution.php#z-tablehttp://www.intmath.com/Counting-probability/14_Normal-probability-distribution.php#stockshttp://www.intmath.com/applications-integration/2-area-under-curve.php
  • 8/8/2019 Normal Distribn Theory

    3/16

    It makes life a lot easier for us if we standardize our normal curve, with a mean of zero and a standard deviation of 1 unit.

    If we have the standardized situation of = 0 and = 1, then we have:

    Standard Normal Curve = 0, = 1

    We can transform all the observations of any normal random variableXwith mean and variance to a new set of observations ofanother normal random variableZwith mean 0 and variance 1 using the following transformation:

    We can see this in the following example.

    Example

    Say = 2 and = 1/3 in a normal distribution.

    The graph of the normal distribution is as follows:

    = 2, = 1/3

    The following graph represents the same information, but it has been standardized so that = 0 and = 1:

  • 8/8/2019 Normal Distribn Theory

    4/16

    = 0, = 1

    The two graphs have different and , but have the same shape (if we tweak the axes).

    The new distribution of the normal random variableZwith mean 0 and variance 1 (or standard deviation 1) is called a standard normaldistribution. Standardizing the distribution like this makes it much easier to calculate probabilities.

    If we have mean and standard deviation , then

    Since all the values ofXfalling betweenx1 andx2 have correspondingZvalues betweenz1 andz2, it means:

    The area under theXcurve betweenX = x1 andX = x2 equals:

    The area under theZcurve betweenZ = z1 andZ = z2.

    Hence, we have the following equivalent probabilities:

    P(x1

  • 8/8/2019 Normal Distribn Theory

    5/16

    The area above is exactly the same as the area

    z1 = 0.5 toz2 = 2

    in the standard normal curve:

    = 0, = 1

    Percentages of the Area Under the Standard Normal Curve

    A graph of this standardized (mean 0 and variance 1) normal curve is shown.

    In this graph, we have indicated the areas between the regions as follows:

    -1 Z 1 68.27%

    -2 Z 2 95.45%

    -3 Z 3 99.73%

    This means that 68.27% of the scores lie within 1 standard deviation of the mean.

    This comes from:

  • 8/8/2019 Normal Distribn Theory

    6/16

    Also, 95.45% of the scores lie within 2 standard deviations of the mean.

    This comes from:

    Finally, 99.73% of the scores lie within 3 standard deviations of the mean.

    This comes from:

    The total area from - 1.06)

    (b)P(Z< -2.15)

    http://www.intmath.com/help/scientific-notebook.phphttp://www.intmath.com/Counting-probability/z-table.phphttp://www.intmath.com/Counting-probability/z-table.phphttp://www.intmath.com/Counting-probability/z-table.phphttp://www.intmath.com/Counting-probability/Ans_14.php?a=0http://www.intmath.com/help/scientific-notebook.phphttp://www.intmath.com/Counting-probability/z-table.phphttp://www.intmath.com/Counting-probability/Ans_14.php?a=0
  • 8/8/2019 Normal Distribn Theory

    7/16

    (c)P(1.06

  • 8/8/2019 Normal Distribn Theory

    8/16

    Application - The Stock Market

    Sometimes, stock markets follow an uptrend (or downtrend) within 2 standard deviations of the mean. This is called moving within thelinear regression channel.

    Here is a chart of the Australian index (the All Ordinaries) from 2003 to Sep 2006.

    Image source: incrediblecharts.com.

    The upper gray line is 2 standard deviations above the mean and the lower gray line is 2 standard deviations below the mean.

    Notice in April 2006 that the index went above the upper edge of the channel and a correction followed (the market dropped).

    But interestingly, the latter part of the chart shows that the index only went down as far as the bottom of the channel and then recoveredto the mean, as you can see in the zoomed view below. Such analysis helps traders make money (or not lose money) when investing.

    Image source: incrediblecharts.com.

    I Gaussian Noise Linear Filtering

    Gaussian noise is another type of noise commonly encountered in image processing. It gets this name because the noise spectrum (ie: ahistogram of just the image noise over a blank background) has a Gaussian/normal distribution, as shown below.

    http://www.incrediblecharts.com/http://www.incrediblecharts.com/http://www.incrediblecharts.com/http://www.incrediblecharts.com/http://www.incrediblecharts.com/http://www.incrediblecharts.com/
  • 8/8/2019 Normal Distribn Theory

    9/16

    Probability distribution function - Gaussian distribution (mean = 0, variance = 1)

    A normalized Gaussian distribution has a mean (average) value of zero (0), and a variance (spread) of one (1). The mean essentiallypoints out where the peak of the curve is with respect to the x-axis, and the variance tells us how wide or spread-out the values are fromthis point. Consider the curves below, where we play around with the variance and mean of a normalized curve.

    http://www.giassa.net/wp-content/uploads/2010/04/1-normpdf.png
  • 8/8/2019 Normal Distribn Theory

    10/16

    Gaussian distribution (mean = 10, variance = 0.5)

    Notice how the peak is at the mean value (10), and the smaller variance has caused the curve to be compressed in the horizontal axis(less spread).

    http://www.giassa.net/wp-content/uploads/2010/04/1-higher-mean-smaller-var.png
  • 8/8/2019 Normal Distribn Theory

    11/16

    Gaussian distribution (mean = -10, variance = 5)

    Now consider the example above. The curves peak is centered at the mean (-10), while the increased variance has caused the curve tospread-out more along the x-axis.

    Now, with respect to image processing, the addition of Gaussian noise essentially means that the input image has been altered due to the

    addition of a Gaussian random variable with mean and variances , where is the square-root of the variance, also known as thestandard deviation. So, for each pixel in the original source image, the output after the addition of noise will be roughly equal to the sumof the original pixel value, and a random variable in the neighborhood of the mean value of the noise being added.

    Before we continue, we should ask ourselves this: how can we generate Gaussian noise to apply to an image. MATLAB comes with atool, normpdf, which allows us to generate a Gaussian/normal distribution easily enough, but wed prefer to do everything from theground-up so that we can learn more from this. One method for generating a Gaussian distribution with a mean of zero (0) and avariance of one (1) is the Box-Muller method as described in [1].

    First, consider two random variables, and , both of which are independent random variables on [0,1]. We can generate from thesevalues, two separate random variables which will approximately fall within a random distribution with a mean of zero (0) and a varianceof one (1), by using the following formulae:

    Once weve generated enough Z-values using these formulae (using different random values for and each time, of course), the Z-values will roughly approximate a normalized Gaussian/normal distribution, according to the central limit theorem [2]. Now, wed liketo be able to change the mean and variance of this distribution so that we can experiment with Gaussian distributions other than just the

    normalized Gaussian distribution (ie: something other than just mean = 0, variance = 1).

    This is actually a very simple operation, since we already have a normalized Gaussian distribution. If we add a constant to each Z-valuewe generated, we effectively change the mean by the constant. As for the variance, if we multiple each Z-value by a constant, thevariance increases by the square of that constant. So if we want to take a normalized Gaussian distribution (mean = 0, variance = 1), and

    http://www.giassa.net/wp-content/uploads/2010/04/2-lower-mean-higher-var.png
  • 8/8/2019 Normal Distribn Theory

    12/16

    wed like to change the mean to , and the variance to , we simply perform the following operation on each Z-value we generatedpreviously:

    A MATLAB function for generating nVals data points that form a Gaussian distribution with a mean of meanVal and a variance ofvarVal is shown below, demonstrating how I have implemented this approach to creating arbitrary Gaussian distributions.

    %==========================================================================

    function output_data = genNormDist(meanVal, varVal, nVals)% genNormDist - Generates a normal/Gaussian distribution with mean% of 'meanVal', variance of 'varVal', and 'nVals'% discrete values in the distribution.% This method uses the Box-Muller method to create an% approximation to a normal distribution with mean of% '0' and a variance of '1'. The data set is then% multiplied by sqrt(varVal) to change the variance% to 'varVal', and then has meanVal added to each% term to adjust the mean, respectively% output_data - The processed data% meanVal - The mean% varVal - The variance

    % nVals - The number of values in the distribution% (C) 2010 Matthew Giassa, www.giassa.net%==========================================================================%Make sure variance isn't zeroif(varVal

  • 8/8/2019 Normal Distribn Theory

    13/16

    %Make a grayscale copy of our input imageI = double(rgb2gray(input_image));

    %Determine input image dimensions[j k] = size(I);

    %Create a Gaussian random variable distributionrandVals = genNormDist(meanNoise, varNoise, j.*k);size(randVals)%Reshape the image

    I = reshape(I,1,[]);size(I)%Add the Gaussian noiseI = I + randVals;

    mean(I)var(I)

    %Revert the image back from a 1D vector to a 2D imageI = reshape(I,j,k);

    %==========================================================================% Completed%==========================================================================

    output_image = I;

    A few sample images are provided below with different means and variances assigned to them using the code above. It should give youa visual representation of how changing these parameters will affect the final result.

    Before and after (mean = 0, variance = 50)

    http://www.giassa.net/wp-content/uploads/2010/04/3-0-mean-50-var.png
  • 8/8/2019 Normal Distribn Theory

    14/16

    Before and after (mean = 100, variance = 1)

    http://www.giassa.net/wp-content/uploads/2010/04/4-100-mean-1-var.png
  • 8/8/2019 Normal Distribn Theory

    15/16

    Before and after (mean = 100, variance = 50)

    In case you havent guessed it by now, changing the mean will change the average brightness of the image, while increasing the variancewill make the image more noisy (ie: the random speckles everywhere become more noticeable).

    Now that weve learned what Gaussian noise is with respect to image processing, along with a means of generating it in arbitraryamounts, we need a way to remove it. Fortunately, we already know how! We know from the earlier section on image normalization thatwe can deal with changes to the average brightness of an image simply by normalizingit. That takes care of the new mean intensityvalue. As for the speckles, we can remove those by blurring the image with a simple convolution masks. The code for these algorithmscan be found in previous sections of these tutorials, so they will not be reproduced here. An example run-through of this process isshown below.

    You will notice that the input image and the final result are not identical. You could theoretically use varying sizes of convolution masksfor blurring the noisy image in the final step, and calculate separate error vectors for each case to see which one yields the smallest error

    value. In most cases, a convolution mask larger than 55 will generally tend to blur the image too much and decrease the quality of theoutput. As is the case in practically any engineering problem, there are always trade-offs. In this case, how much noise can we removewithout decreasing the output image quality too much.

    http://www.giassa.net/?page_id=472http://www.giassa.net/?page_id=472http://www.giassa.net/?page_id=588http://www.giassa.net/?page_id=479http://www.giassa.net/wp-content/uploads/2010/04/5-100-mean-50-var.pnghttp://www.giassa.net/?page_id=472http://www.giassa.net/?page_id=588http://www.giassa.net/?page_id=479
  • 8/8/2019 Normal Distribn Theory

    16/16

    Simple method for removing Gaussian noise from an image

    References

    [1] Box-Muller Transformation from Wolfram MathWorld. Wolfram MathWorld: The Webs Most Extensive MathematicsResource. Web. 26 Apr. 2010. .

    [2] Central Limit Theorem from Wolfram MathWorld. Wolfram MathWorld: The Webs Most Extensive Mathematics Resource.Web. 26 Apr. 2010. .

    http://www.giassa.net/wp-content/uploads/2010/04/6-example-gaussian-noise.png