⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compare.m

📁 用matlab进行图像处理 对车牌号码进行识别 非常具有实用价值
💻 M
字号:
function [absdiff, snr, psnr, imfid, mse] = compare(originalimg, restoredimg)
%Function to compare the original image with the
%restored image using some predefined methods
%Inputs: originalimg, restoredimg
%Returns: absdiff, snr, psnr, imfid, mse
%
%originalimg:  It is the original unblurred image
%restoredimg:  It is the restored image
%absdiff:      Average Absolute Difference
%snr:          Signal to Noise Ratio (dB)
%psnr:         Peak Signal to Noise Ratio (dB)
%imfid:        Image Fidelity
%mse:          Mean Square Error
%
%Example:
%      [absdiff, snr, psnr, imfid, mse] = compare(originalimg, restoredimg);
%      This call takes original image and the restored image and returns
%      the comparison of both the images using some predefined methods.

%Average absolute difference
%{
md = originalimg - restoredimg;
mdsize = size(md);
summation = 0;
for i = 1:mdsize(1);
    for j = 1:mdsize(2);
        summation = summation + abs(md(i,j));
    end
end

absdiff = summation/(mdsize(1)*mdsize(2));
%}


%Signal to Noise Ratio (SNR)
%{
md = (originalimg - restoredimg).^2;
mdsize = size(md);
summation = 0;
sumsq=0;
for  i = 1:mdsize(1);
    for j = 1:mdsize(2);
        summation = summation + abs(md(i,j));
        sumsq = sumsq + (originalimg(i,j)^2);
    end
end

snr = sumsq/summation;
snr = 10 * log10(snr);
%}


%Peak Signal to Noise Ratio (PSNR)
%{
md = (originalimg - restoredimg).^2;
mdsize = size(md);
summation = 0;
sumsq=0;
for  i = 1:mdsize(1);
    for j = 1:mdsize(2);
        summation = summation + abs(md(i,j));
    end
end

psnr = size(originalimg, 1) * size(originalimg, 2) * max(max(originalimg.^2))/summation;
psnr = 10 * log10(psnr);
%}


%Image Fidelity

md = (originalimg - restoredimg).^2;
mdsize = size(md);
summation = 0;
sumsq = 0;
for  i = 1:mdsize(1);
    for j = 1:mdsize(2);
        summation = summation + abs(md(i,j));
        sumsq = sumsq + (originalimg(i,j)^2);
    end
end

imfid = (1-summation)/sumsq;
%}


%Mean Square Error
%{
diff = originalimg - restoredimg;
diff1 = diff.^2;
mse = mean(mean(diff1));
%}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -