MATLAB Answers

Filter and measure MSE, PSNR, SNR of single image

244 views (last 30 days)
iza
iza on 20 Jan 2015
Answered: Hasan Deen on 5 Mar 2019
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');

  3 Comments

Latha
Latha on 12 Oct 2017
Mse is not calculated from two images
Image Analyst
Image Analyst on 12 Oct 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.

Sign in to comment.

Accepted Answer

iza
iza on 21 Jan 2015
Any comment on this?..

  2 Comments

iza
iza on 21 Jan 2015
Is it correct way to measure MSE,SNR and PSNR?

Sign in to comment.

More Answers (2)

sam alsalihy
sam alsalihy on 15 Jul 2017
noise image not effect on the result
why?

  0 Comments

Sign in to comment.


Hasan Deen
Hasan Deen on 5 Mar 2019
thank you

  0 Comments

Sign in to comment.

Sign in to answer this question.