Professional Documents
Culture Documents
Message: 10 of 13
I'm afraid that is incorrect. You should divide by the standard deviation which is the square root of the variance.
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 ?
meanx = 3;
stdx = 5;
x = meanx + stdx*randn(50,1);
A random variable X whose distribution has the shape of a normal curve is called a normal random variable.
Normal Curve
This random variable X is said to be normally distributed with mean μ and standard deviation σ if its probability distribution is given by
Note:
[See Area under a Curve for more information on using integration to find areas under curves. Don't worry - we don't have to perform
this integration - we'll use the computer to do it for us.]
We can transform all the observations of any normal random variable X with mean μ and variance σ to a new set of observations of
another normal random variable Z with mean 0 and variance 1 using the following transformation:
Example
Say μ = 2 and σ = 1/3 in a normal distribution.
μ = 2, σ = 1/3
The following graph represents the same information, but it has been standardized so that μ = 0 and σ = 1:
μ = 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 variable Z with mean 0 and variance 1 (or standard deviation 1) is called a standard normal
distribution. Standardizing the distribution like this makes it much easier to calculate probabilities.
Since all the values of X falling between x1 and x2 have corresponding Z values between z1 and z2, it means:
Example
Considering our example above where μ = 2, σ = 1/3, then
So s.d. to 2 s.d. to the right of μ = 2 will be represented by the area from to . This area is graphed as
follows:
μ = 2, σ = 1/3
The area above is exactly the same as the area
z1 = 0.5 to z2 = 2
μ = 0, σ = 1
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.
Finally, 99.73% of the scores lie within 3 standard deviations of the mean.
The z-Table
The areas under the curve bounded by the ordinates z = 0 and any positive value of z are found in the z-Table. From this table the area
under the standard normal curve between any two ordinates can be found by using the symmetry of the curve about z = 0. We can also
use Scientific Notebook, as we shall see.
EXAMPLE 1
Find the area under the standard normal curve for the following, using the z-table. Sketch each one.
Answer
Loading...
EXAMPLE 2
Find the following probabilities:
Answer
Loading...
EXAMPLE 3
It was found that the mean length of 100 parts produced by a lathe was 20.05 mm with a standard deviation of 0.02 mm. Find the
probability that a part selected at random would have a length
Answer
Loading...
EXAMPLE 4
A company pays its employees an average wage of $3.25 an hour with a standard deviation of 60 cents. If the wages are approximately
normally distributed, determine
a. the proportion of the workers getting wages between $2.75 and $3.69 an hour;
b. the minimum wage of the highest 5%.
Answer
Loading...
EXAMPLE 5
The average life of a certain type of motor is 10 years, with a standard deviation of 2 years. If the manufacturer is willing to replace only
3% of the motors that fail, how long a guarantee should he offer? Assume that the lives of the motors follow a normal distribution.
Answer
Loading...
Application - The Stock Market
Sometimes, stock markets follow an uptrend (or downtrend) within 2 standard deviations of the mean. This is called moving within the
linear regression channel.
Here is a chart of the Australian index (the All Ordinaries) from 2003 to Sep 2006.
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 recovered
to the mean, as you can see in the zoomed view below. Such analysis helps traders make money (or not lose money) when investing.
A normalized Gaussian distribution has a mean (average) value of zero (0), and a variance (spread) of one (1). The mean essentially
points 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 from
this point. Consider the curves below, where we play around with the variance and mean of a normalized curve.
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).
Gaussian distribution (mean = -10, variance = 5)
Now consider the example above. The curve’s peak is centered at the mean (-10), while the increased variance has caused the curve to
spread-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 the
standard deviation. So, for each pixel in the original source image, the output after the addition of noise will be roughly equal to the sum
of 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 a
tool, normpdf, which allows us to generate a Gaussian/normal distribution easily enough, but we’d prefer to do everything from the
ground-up so that we can learn more from this. One method for generating a Gaussian distribution with a mean of zero (0) and a
variance 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 these
values, two separate random variables which will approximately fall within a random distribution with a mean of zero (0) and a variance
of one (1), by using the following formulae:
•
•
Once we’ve 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, we’d like
to 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-value
we generated, we effectively change the mean by the constant. As for the variance, if we multiple each Z-value by a constant, the
variance increases by the square of that constant. So if we want to take a normalized Gaussian distribution (mean = 0, variance = 1), and
we’d like to change the mean to , and the variance to , we simply perform the following operation on each Z-value we generated
previously:
A MATLAB function for generating ‘nVals’ data points that form a Gaussian distribution with a mean of ‘meanVal’ and a variance of
‘varVal’ 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, <teo@giassa.net> www.giassa.net
%==========================================================================
%Make sure variance isn't zero
if(varVal <= 0)
error('Can not proceed: Variance cannot equal zero or be negative!')
end
%==========================================================================
% Completed
%==========================================================================
output_data = tempVector;
Now that we have a method for generating a normal distribution, we can apply Gaussian noise to an image by simply “adding” the
distribution to the original source image. One simple approach to this is to generate a Gaussian distribution with a specific mean and
variance, and the number of elements should be equal to the number of pixels in the source image. Then, simply randomize the order of
the individual values in the distribution, and add it as an array to the image buffer. The sample code below demonstrates this in action.
%==========================================================================
function output_image = addGaussianNoise(input_image, meanNoise, varNoise )
% addGaussianNoise - Adds Gaussian noise to an image
% output_image - The processed image
% input_image - The source image data
% (C) 2010 Matthew Giassa, <teo@giassa.net> www.giassa.net
%==========================================================================
%Make a grayscale copy of our input image
I = double(rgb2gray(input_image));
%==========================================================================
% 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 you
a visual representation of how changing these parameters will affect the final result.
In case you haven’t guessed it by now, changing the mean will change the average brightness of the image, while increasing the variance
will make the image more noisy (ie: the random “speckles” everywhere become more noticeable).
Now that we’ve learned what Gaussian noise is with respect to image processing, along with a means of generating it in arbitrary
amounts, we need a way to remove it. Fortunately, we already know how! We know from the earlier section on image normalization that
we can deal with changes to the average brightness of an image simply by normalizing it. That takes care of the new mean intensity
value. As for the “speckles”, we can remove those by blurring the image with a simple convolution masks. The code for these algorithms
can be found in previous sections of these tutorials, so they will not be reproduced here. An example run-through of this process is
shown below.
You will notice that the input image and the final result are not identical. You could theoretically use varying sizes of convolution masks
for 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 5×5 will generally tend to blur the image too much and decrease the quality of the
output. As is the case in practically any engineering problem, there are always trade-offs. In this case, how much noise can we remove
without decreasing the output image quality too much.
Simple method for removing Gaussian noise from an image
References
[1] “Box-Muller Transformation — from Wolfram MathWorld.” Wolfram MathWorld: The Web’s Most Extensive Mathematics
Resource. Web. 26 Apr. 2010. <http://mathworld.wolfram.com/Box-MullerTransformation.html>.
[2] “Central Limit Theorem — from Wolfram MathWorld.” Wolfram MathWorld: The Web’s Most Extensive Mathematics Resource.
Web. 26 Apr. 2010. <http://mathworld.wolfram.com/CentralLimitTheorem.html>.