imnoise does not work as expected

조회 수: 6 (최근 30일)
Brian
Brian 2013년 1월 24일
imnoise(a, 'gaussian', mean, var) seems simple enough in concept: add a Gaussian distribution of noise to an image. However, it does not recover the values expected.
Try: >> a = zeros(16, 16); b = imnoise(a, 'gaussian', 0, 0.1); >> mean(b(:)) ans = 0.1262 >> std(b(:))^2 ans = 0.040
The mean is not zero! The variance is not 0.1!
I can't figure out why the imnoise code produces this result. The code snippet is below.
switch code case 'gaussian' % Gaussian white noise b = a + sqrt(p4)*randn(sizeA) + p3;
If a = 0 and p3 = 0, then the result should have a mean value of zero.
Answers?

채택된 답변

Steve Eddins
Steve Eddins 2013년 1월 24일
imnoise clips the output to the range [0,1].
>> min(b(:))
ans =
0
  댓글 수: 2
Brian
Brian 2013년 1월 24일
Ok. Now try something that should address this:
>> a = ones(1024); b = imnoise(a, 'gaussian', 0, 0.1); >> mean(b(:) - 1) ans = -0.1261 ??? shouldn't this be zero?
>> std(b(:) - 1) ans = 0.1844 ??? shouldn't this be sqrt(0.1)?
Brian
Brian 2013년 1월 24일
You really need to add this to your documentation of your demos. I did not expect
I = im2double(imread('cameraman.tif'));
to normalize the image [0,1]. If you look at the documentation for im2double, it states "rescaling the data if necessary". That is subjective. Necessary for what?
The best documentation has mathematical formulas and references.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by