Similarity between gaussian noise image and original image

1 view (last 30 days)
This is my code
im1= imread('cameraman.tif');
im1=im2double(im1);
im2= imnoise(im1,'gaussian',0.21);
im2=im2double(im2);
[r ,c ] = size(im1);
MeanIm1= mean(im1);
Mean1=mean(MeanIm1);
MeanIm2= mean(im2);
Mean2=mean(MeanIm2);
MeanDifference = abs((Mean1-Mean2));
MeanDifference = 100*MeanDifference
Quality= round(100-MeanDifference);
imshow(im2);
title(Quality);
I wanted to write an algorithm that gives qualit mark to a gaussian image according to its mean value.
For instanc, if we write
imnoise(im1,'gaussian',0.15)
we should have Quality=85
These codes works until the mean value 0.30 as ı want. After that value it doesn't work.

Answers (1)

DGM
DGM on 15 Dec 2023
Edited: DGM on 15 Dec 2023
This happens because the output of imnoise() is clamped to the dynamic range expected of the output class -- even for floating-point outputs.
You're expecting the mean difference to be strictly proportional to the first numeric parameter passed to imnoise(). Due to truncation, it's actually a function of both numeric parameters, as well as the intensity distribution of the given image. It's only a coincidence that it almost looks like it might work when the mean, variance, and dynamic range are all relatively small.
Consider a simplified scenario with a solid 50% gray image and default mean and variance. In this case, the noise doesn't spread the distribution enough to cause a significant amount of truncation, so the MAD stays similar to the noise mean.
% TEST 1
noisemn = 0; % zero-mean
noisevar = 0.01; % small variance
A = 0.5*ones(100); % solid 50% gray
observebehavior(A,noisemn,noisevar)
meandiff = 5.7846e-04
Now let's say we increase (or decrease) the noise mean away from zero. Now the distribution shifts enough that significant truncation occurs.
% TEST 2
noisemn = 0.50; % nonzero mean
noisevar = 0.01; % small variance
A = 0.5*ones(100); % solid 50% gray
observebehavior(A,noisemn,noisevar)
meandiff = 0.4601
Similarly, the result depends on the intensity distribution of the image.
% TEST 3
noisemn = 0.15; % nonzero mean
noisevar = 0.01; % small variance
A = 0.85*ones(100); % solid 85% gray
observebehavior(A,noisemn,noisevar)
meandiff = 0.1100
The result is also a function of the variance.
% TEST 4
noisemn = 0.15; % nonzero mean
noisevar = 0.08; % more variance
A = 0.85*ones(100); % solid 85% gray
observebehavior(A,noisemn,noisevar)
meandiff = 0.0401
So far, we've been using a solid gray field. In practice, we're rarely concerned with preserving object content that doesn't exist. What if the intensity distribution of the image weren't so trivial? Consider the following:
% TEST 5
noisemn = 0.35; % nonzero mean
noisevar = 0.01; % small variance
A = repmat(linspace(0,1,100),[100 1]); % a linear ramp (uniform intensity distribution)
observebehavior(A,noisemn,noisevar)
meandiff = 0.2824
function observebehavior(A,noisemn,noisevar)
% apply noise as imnoise does
% assuming A is unit-scale float
B = A + noisemn + sqrt(noisevar)*randn(size(A)); % apply noise
B = min(max(B,0),1); % clamp values
% see what's happening
subplot(2,1,1)
imhist(A)
subplot(2,1,2)
imhist(B)
% what's the mean absolute difference?
meandiff = abs(mean(A(:)) - mean(B(:)))
end
Given that images are typically transported in integer formats, it's reasonable to apply the truncation as imnoise() does. In practice, don't expect the MAD to directly follow the mean of the applied gaussian noise unless you're making some special efforts to preserve subminimal and supramaximal values.

Community Treasure Hunt

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

Start Hunting!