如何计算边缘检测图像的均方误差(MSE)和PSNR值

时间:2018-01-17 16:44:17

标签: matlab edge-detection canny-operator error-detection

我使用以下代码查找边缘图像的均方误差,并与参考边缘图像进行比较。

clc;    % Clear the command window.
close all;  % Close all figures (except those of imtool.)
clear;  % Erase all existing variables. Or clearvars if you want.
workspace;  % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;


ReferenceImage = imread('F:\R\CT\0.5\0.5\2.jpg');
[rows columns] = size(ReferenceImage);

% Display the first image.
subplot(2, 2, 1);
imshow(ReferenceImage, []);
title('Reference image with Sigma 0.8 and Threshold 0', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.

% Get a second image by adding noise to the first image.
noisyImage = imread('F:\R\CT\0.5\0.5\3.jpg');


% Display the second image.
subplot(2, 2, 2);
imshow(noisyImage, []);
title('Noisy Image', 'FontSize', fontSize);

%------ PSNR CALCULATION ----------------------------------------------------------
% Now we have our two images and we can calculate the PSNR.
% First, calculate the "square error" image.
% Make sure they're cast to floating point so that we can get negative differences.
% Otherwise two uint8's that should subtract to give a negative number
% would get clipped to zero and not be negative.
squaredErrorImage = (double(ReferenceImage) - double(noisyImage)) .^ 2;
% Display the squared error image.
subplot(2, 2, 3);
imshow(squaredErrorImage, []);
title('Squared Error Image', 'FontSize', fontSize);
% Sum the Squared Image and divide by the number of elements
% to get the Mean Squared Error.  It will be a scalar (a single number).
mse = sum(sum(squaredErrorImage)) / (rows * columns);
% Calculate PSNR (Peak Signal to Noise Ratio) from the MSE according to the formula.
PSNR = 10 * log10( 256^2 / mse);
% Alert user of the answer.
message = sprintf('The mean square error is %.2f.\nThe PSNR = %.2f', mse, PSNR);
msgbox(message);

但是我得到的结果就像附加图像一样,但是我没有得到最终的单个值,而是收到错误,

Error in msgbox (line 59)
error(nargoutchk(0,1,nargout));
Error in error (line 49)
msgbox(message); 

Result of Error Image

0 个答案:

没有答案