Filter and measure MSE, PSNR, SNR of single image

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.
fontSize = 22;
%Load single MRI image
I = imread('IM_00042.tif');
% addition of graininess (i.e. noise)
I_noise = imnoise(I, 'gaussian', 0.09);
% the average of 3^2, or 9 values(filters the multidimensional array A with the multidimensional filter h)
h = ones(3,3) / 3^2;
I2 = imfilter(I_noise,h);
% Measure signal-to-noise ratio
img=I;
img=double(img(:));
ima=max(img(:));
imi=min(img(:));
mse=std(img(:));
snr=20*log10((ima-imi)./mse)
% Measure Peak SNR
[peaksnr, snr] = psnr(I_noise, I);
fprintf('\n The Peak-SNR value is %0.4f', peaksnr);
fprintf('\n The SNR value is %0.4f \n', snr);
fprintf('\n The MSE value is %0.4f \n', mse);
%Plot original & filtered figure
subplot(1,2,1), imshow(I_noise), title('Original image')
subplot(1,2,2), imshow(I2), title('Filtered image')
text(size(I,2),size(I,1)+15, ...
'Gaussian = 0.09', ...
'FontSize',10,'HorizontalAlignment','right');

4 comentarios

Latha
Latha el 12 de Oct. de 2017
Mse is not calculated from two images
Image Analyst
Image Analyst el 12 de Oct. de 2017
In her code it's not, but in general it often/usually is computed from two images, a reference image and a test image. Her code just uses one image, and she makes the common beginner mistake of thinking the standard deviation of gray levels in an image is all due to noise. Obviously it's not, except in the special case where you know for a fact that your scene is totally uniform (or should be if it did not have any noise).
She should use the functions immse() and psnr() in the Image Processing Toolbox, after getting a better understanding of what those quantities mean, and what she needs to measure.
Thanks for the solution
@Image Analyst I am trying to estimate SNR of a noisy and reconstructed MR image and there are two methods that i find online.
One where I choose a single image, select ROI-1 of a specific dimension inside the object and then choose ROI-2 of same dimension of the backgorund in the image, and then SNR = [Mean(ROI-1 minus ROI-2)/std(ROI2)].
The other method is simply use reconstructed as reference image, use noisy image as the other and use [peaksnr, snr] = psnr(Image, Ref) to estimate the SNR between two images.
could you please give some suggestion on when to use single image method and when to use multi image method? my ultimate goal is to find if the reconstructed image has higher SNR than noisy image.
Thanks in advance

Iniciar sesión para comentar.

Respuestas (3)

iza
iza el 21 de En. de 2015

0 votos

Any comment on this?..

5 comentarios

Image Analyst
Image Analyst el 21 de En. de 2015
Why should we comment on it?
iza
iza el 21 de En. de 2015
Is it correct way to measure MSE,SNR and PSNR?
ari ali
ari ali el 12 de Mayo de 2020
Hello
I have a project about ( image enhancement using modified histogram equalization ) i must be found function (snr , psnr and mse ) for original image , for image after addi noise and for image after applying filter .. in this step i need your help how can find functions for orginal image and noise image and image after applying filter ???? . Best regards
Image Analyst
Image Analyst el 12 de Mayo de 2020
There are functions immse() and psnr() in the Image Processing Toolbox.
ghada sandoub
ghada sandoub el 15 de Feb. de 2021
are these functions work with the colour image? i.e. can these functions estimate the MSE and PSNR for the whole RGB image or we have to use these functions separately for each channel of the image?

Iniciar sesión para comentar.

sam alsalihy
sam alsalihy el 15 de Jul. de 2017

0 votos

noise image not effect on the result
why?

Categorías

Más información sobre Image Processing Toolbox en Centro de ayuda y File Exchange.

Preguntada:

iza
el 20 de En. de 2015

Comentada:

el 15 de Feb. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by