http://www.mathworks.com/matlabcentral/newsreader/view_thread/289740
MATLAB Central Newsreader  Generate noise model[Please help]
Feed for thread: Generate noise model[Please help]
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Thu, 19 Aug 2010 20:04:19 +0000
Generate noise model[Please help]
http://www.mathworks.com/matlabcentral/newsreader/view_thread/289740#772928
Daniel
May i know how to generate Rayleigh noise model using randn function..<br>
Thanks

Thu, 19 Aug 2010 20:42:08 +0000
Re: Generate noise model[Please help]
http://www.mathworks.com/matlabcentral/newsreader/view_thread/289740#772932
Walter Roberson
On 100819 03:04 PM, Daniel wrote:<br>
> May i know how to generate Rayleigh noise model using randn function..<br>
<br>
<br>
<a href="http://en.wikipedia.org/wiki/Rayleigh_distribution">http://en.wikipedia.org/wiki/Rayleigh_distribution</a><br>
<br>
and look under "Related Distributions"

Thu, 19 Aug 2010 20:50:33 +0000
Re: Generate noise model[Please help]
http://www.mathworks.com/matlabcentral/newsreader/view_thread/289740#772934
Grzegorz
Daniel <romegoh@hotmail.com> wrote in message <2039352140.31930.1282248289923.JavaMail.root@gallium.mathforum.org>...<br>
> May i know how to generate Rayleigh noise model using randn function..<br>
> Thanks<br>
<br>
Equation from raylrnd function:<br>
<br>
r = sqrt(randn().^2 + randn().^2) .* b;<br>
<br>
where b>0 is Rayleigh distribution parameter.

Thu, 19 Aug 2010 21:43:33 +0000
Re: Generate noise model[Please help]
http://www.mathworks.com/matlabcentral/newsreader/view_thread/289740#772945
Daniel
Thanks for prompt reply.However,I am sorry because I am really new to matlab, can I have a clear instruction on how to create the model.I have no idea on what I can do with the equation.

Thu, 19 Aug 2010 22:15:23 +0000
Re: Generate noise model[Please help]
http://www.mathworks.com/matlabcentral/newsreader/view_thread/289740#772951
Walter Roberson
On 100819 04:43 PM, Daniel wrote:<br>
> Thanks for prompt reply.However,I am sorry because I am really new to matlab, can I have a clear instruction on how to create the model.I have no idea on what I can do with the equation.<br>
<br>
RR = @(X) sqrt(X * X.');<br>
<br>
randRayleigh = RR(randn(1,2));

Thu, 19 Aug 2010 23:16:32 +0000
Re: Generate noise model[Please help]
http://www.mathworks.com/matlabcentral/newsreader/view_thread/289740#772962
ImageAnalyst
On Aug 19, 5:43 pm, Daniel <rome...@hotmail.com> wrote:<br>
> Thanks for prompt reply.However,I am sorry because I am really new to matlab, can I have a clear instruction on how to create the model.I have no idea on what I can do with the equation.<br>
<br>
<br>
Daniel:<br>
Did they teach you how to generate such a distribution using the well<br>
known method of inverting the CDF of the desired probability function<br>
to get a function that can generate random numbers drawn from that<br>
desired distribution function, given as input numbers that have been<br>
drawn from a uniform distribution? If not, it's something you<br>
*should* know because it's a very useful technique for getting random<br>
numbers from almost any probability density function. I illustrate<br>
this method below. Not exactly sure what you were hoping to do with<br>
it, but this is one thing you can do with the equation.<br>
IMPORTANT: THE NEWSREADER MAY SPLIT SOME LONG LINES INTO TWO, AND<br>
YOU'LL HAVE TO REJOIN THOSE LINES TOGETHER INTO A SINGLE LINE.<br>
<br>
% Script to generate random numbers drawn from a Rayleigh<br>
distribution.<br>
% Uses the well known method of inverting the CDF of the desired<br>
probability<br>
% function to get a function that can generate random numbers drawn<br>
% from that desired distribution function,<br>
% given as input numbers that have been drawn from a uniform<br>
distribution.<br>
% by ImageAnalyst<br>
<br>
clc; % Clear the command window.<br>
close all; % Close all figures (except those of imtool.)<br>
clear; % Erase all existing variables.<br>
workspace; % Make sure the workspace panel is showing.<br>
fontSize = 14;<br>
<br>
% Change the current folder to the folder of this mfile.<br>
if(~isdeployed)<br>
cd(fileparts(which(mfilename)));<br>
end<br>
<br>
% Plot the Rayleigh cumulative distribution function<br>
% over the range 020 with a sigma of 5.<br>
x = 0:20;<br>
sigma = 5;<br>
rayleighCDF = 1  exp(x.^2 / (2*sigma^2));<br>
<br>
subplot(3,1,1);<br>
plot(x, rayleighCDF, 'LineWidth', 3);<br>
caption = sprintf('Rayleigh CDF with sigma = %.2f', sigma);<br>
title(caption, 'FontSize', fontSize);<br>
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full<br>
screen.<br>
<br>
% Ask user for a number of random numbers to generate.<br>
userPrompt = 'Enter an integer number of random numbers to generate';<br>
caNumberOfRandoms = inputdlg(userPrompt, 'Enter an integer',1,<br>
{'1000'});<br>
numberOfRandoms = str2num(cell2mat(caNumberOfRandoms));<br>
<br>
% Generate numberOfRandoms uniformly distributed random numbers.<br>
uniformlyDistributedRandomNumbers = rand(numberOfRandoms, 1);<br>
subplot(3,2,3);<br>
bar(uniformlyDistributedRandomNumbers);<br>
xlim([0 numberOfRandoms]);<br>
caption = sprintf('%d Uniformly Distributed Numbers',<br>
numberOfRandoms);<br>
title(caption, 'FontSize', fontSize);<br>
<br>
%<br>
% KEY PART, RIGHT HERE!!!!<br>
% Invert the CDF of the Rayleigh function to get a function that can<br>
% generate random numbers drawn from a Rayleigh distribution,<br>
% given numbers drawn from a uniform distribution.<br>
rayleighDistNumbers = sqrt(log(1<br>
uniformlyDistributedRandomNumbers)*(2*sigma^2));<br>
%<br>
<br>
% Plot the Rayleigh distributed numbers.<br>
subplot(3,2,4);<br>
bar(rayleighDistNumbers);<br>
xlim([0 numberOfRandoms]);<br>
caption = sprintf('%d Rayleigh Distributed Numbers', numberOfRandoms);<br>
title(caption, 'FontSize', fontSize);<br>
<br>
% Get histogram of uniformly distributed numbers.<br>
[countsU, binsU] = hist(uniformlyDistributedRandomNumbers, 50);<br>
% Plot the uniformly distributed numbers.<br>
subplot(3,2,5);<br>
bar(binsU, countsU);<br>
caption = sprintf('Histogram of %d Uniformly Distributed Numbers',<br>
numberOfRandoms);<br>
title(caption, 'FontSize', fontSize);<br>
<br>
% Get histogram of Rayleigh distributed numbers.<br>
% Observe that it's distribution is not flat like it is<br>
% for the uniformly distributed numbers.<br>
% It will take on the Rayleigh distribution shape.<br>
[countsR, binsR] = hist(rayleighDistNumbers, 50);<br>
subplot(3,2,6);<br>
bar(binsR, countsR);<br>
caption = sprintf('Histogram of %d Rayleigh Distributed Numbers',<br>
numberOfRandoms);<br>
title(caption, 'FontSize', fontSize);

Sat, 21 Aug 2010 12:44:06 +0000
Re: Generate noise model[Please help]
http://www.mathworks.com/matlabcentral/newsreader/view_thread/289740#773340
Daniel
I am sorry I think you get me wrong.The problem is about image processing not mathematic.I need to read in an image and generate the Rayleigh noise model from the image given that the noise is model by the pdf as written in the link below <a href="http://www.bioen.utah.edu/wiki/index.php?title=Noise_modeling_and_Probability_Theory">http://www.bioen.utah.edu/wiki/index.php?title=Noise_modeling_and_Probability_Theory</a> ...pls help..thx

Sat, 21 Aug 2010 21:38:55 +0000
Re: Generate noise model[Please help]
http://www.mathworks.com/matlabcentral/newsreader/view_thread/289740#773403
ImageAnalyst
On Aug 21, 8:44 am, Daniel <rome...@hotmail.com> wrote:<br>
> I am sorry I think you get me wrong.The problem is about image processing not mathematic.I need to read in an image and generate the Rayleigh noise model from the image given that the noise is model by the pdf as written in the link below<a href="http://www.bioen.utah.edu/wiki/index.php?title=Noise_modeling_and_Pro......pls">http://www.bioen.utah.edu/wiki/index.php?title=Noise_modeling_and_Pro......pls</a> help..thx<br>
<br>
<br>
Daniel:<br>
I don't think I got you wrong. I gave you the general method for<br>
getting random numbers taken from whatever distribution you want.<br>
Basically you integrate the pdf to get the cdf, invert it, and plug in<br>
a uniform distribution. And I gave code to do that. That's the basic<br>
recipe that will work for any pdf. Of course it's easier if you know<br>
the analytical form for the noise, like we do for the Rayleigh (I took<br>
it from the website Walter mentioned.) But you could do it<br>
numerically if you had only an empirical pdf function.<br>
<br>
What you have not given is how that noise relates to the pixel value.<br>
Is it additive noise, where all the Rayleigh noise comes from the same<br>
distribution with some mean that is independent of the pixel value?<br>
Or is it valuedependent noise, for example the mean of the Rayleigh<br>
distribution should be the pixel value, and so you need to adjust your<br>
noisegenerating function for a new mean each time you encounter a new<br>
pixel value? Can you answer that? Because there is no "right" answer<br>
that I know of. I suspect it may be the latter but you could define<br>
it to work however you want  not that that necessarily corresponds<br>
with reality, but you could do it.<br>
ImageAnalyst