how to calculate actual snr of image in matlab?

 Accepted Answer

Get the signal - that's your "true" noiseless image.
Get the noise - that's your actual noisy image minus the "true" noiseless image.
Divide them element by element, then take the mean over the whole image.

12 Comments

The noise is your actual noisy image minus the "true" noiseless image.
noiseOnlyImage = noisyImage - trueImage;
if i will find standard deviation of image,is it noise?
noise = final_image - clean_image. If you only have the final image you have to make assumptions about the noise or 'estimate' the clean image.
The standard deviation is not noise, unless your image is known to be uniform. There could be variation in the image that's completely normal (not noise but due to true image structure) that could make the std dev high.
how noise is calculated?
The noise is your actual noisy image minus the "true" noiseless image.
noiseOnlyImage = noisyImage - trueImage;
If you don't have the "true" noise-free image, then how do you know if what you are seeing is noise, or the real genuine true scene? You can't, unless you make some sort of assumptions.
signal=if i take mean of noiseless of total image noise=if i take mean of noisy-noiseless of total image then i divide signal and noise(not element by element because some element have '0' noise) is it true?
NO, that's certainly not true. In fact it's the opposite - it's what you said not to do. What if the mean of the noise was zero? Your method would say that the SNR is infinite even though there's substantial noise. The ratio of the means IS NOT the same as the mean of the ratios. Run this code to see why:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
% Create noise-free image.
noiseFreeImage = 100*ones(240, 320);
subplot(1,2,1);
imshow(noiseFreeImage, []);
% Add +/- 10 gray levels of noise to it
noisyImage = noiseFreeImage + 20*rand(size(noiseFreeImage))-10;
subplot(1,2,2);
imshow(noisyImage, []);
% Get the noise-only image
noiseOnlyImage = abs(noisyImage - noiseFreeImage);
% Calculate the mean of each
signalMean = mean(noiseFreeImage(:))
noiseOriginal = mean(noisyImage(:))
noiseOnlyMean = mean(noiseOnlyImage(:))
% Get ratio of the means
snr1 = signalMean/noiseOnlyMean
% Do element by element
snrImage = signalMean ./ noiseOnlyImage;
% Get the mean of the SNR image.
snr2 = mean(snrImage(:))
if any element in noiseOnlyImage is zero(means that additive noisy array or image contain any element zero) then snr2 becomes infinite. snr1 have some value.
so why snr1 calculating is not better compared snr2?
Well, what if your signal is 100 everywhere, and your noisy image is 100 plus or minus 100, so it goes from 0 to 200. Don't you agree that that is a very very noisy image and it should have a low signal to noise ratio? It's total noise - all over the place. But it's mean is still 100 - same as your signal. So just looking at the means, you can't tell the difference between your perfect noise-free signal and the incredibly noisy signal. How is that any good?
By the way, you can always omit pixels where the noise is zero if you want.
thanks for your valuable guidance

Sign in to comment.

More Answers (1)

Hi,
Here you are.
img=imread('.JPG');
img=double(img(:));
ima=max(img(:));
imi=min(img(:));
ims=std(img(:));
snr=10*log((ima-imi)./ims);

4 Comments

What's the basis for saying this? Unless your image is supposed to be completely uniform, the standard deviation is not noise. It is just variation in your scene that is supposed to be there. And the range of the image is not the signal. To compute the noise you need to know the reference, perfect, non-noisy image.
Hello,
so how do you calculate the SNR for a SINGLE image without a reference?
Thank you
A signal to noise ratio requires both a signal, and noise. If you don't have each of those, you can't do it. However there are single image quality metrics. Try this link.
Perform a histogram on your image and then decide at what level you consider to be signal, i.e., above a value is signal and below that value is noise. If your image is in dB then you might use -6dB as the threshold value. In my case my max signal value is always 0dB as it has been normalised to the max value and converted to dB. So you can say anything less than -6dB is noise and anything greater than -6dB is signal. An easy way to calculate the noise floor is rms(rms(image));. This means that if your signal has a max value of 0dB then the peak SNR for your signal = 0dB + the value of the rms calculation.

Sign in to comment.

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!