imgcomp.m

来自「这是一个去马赛克工具软件」· M 代码 · 共 38 行

M
38
字号
function [DIFF, ERROR_DIST_IMG] = ImgComp( Input, Ref, Method);
%function [DIFF, ERROR_DIST_IMG]

[size_y, size_x, color] = size(Input);
if( size(Ref) ~= size(Input) )
    error('Size of two images are not equal!');
end

if nargin < 3
    Method = 'mse';
end

Input = double(Input);
Ref = double(Ref);


switch lower(Method)
    case 'mse'
		%DIFF(1): The sum of the error in 3 channels
		%DIFF(2:4): The error in each channel
		DIFF = zeros(4,1);      
        ERROR_DIST_IMG = (Input-Ref ).^2;
%		DIFF(2)= sum(sum(  ERROR_DIST_IMG(:,:,1) ));
		DIFF(2)= sum(sum(  ERROR_DIST_IMG(5:size_y-5,5:size_x-5,1) ));
		if color == 3
%            DIFF(3) = sum(sum( ERROR_DIST_IMG(:,:,2) ));
%            DIFF(4) = sum(sum( ERROR_DIST_IMG(:,:,3) ));
 		    DIFF(3)= sum(sum(  ERROR_DIST_IMG(5:size_y-5,5:size_x-5,2) ));
      		DIFF(4)= sum(sum(  ERROR_DIST_IMG(5:size_y-5,5:size_x-5,3) ));
        end
        DIFF(1) = sum(DIFF(2:4));
    case 'psnr'
        %DIFF: The PSNR
        ERROR_DIST_IMG = (Input-Ref ).^2;
        DIFF = 10*log10( size_y * size_x * color *255^2 / sum(sum(sum( ERROR_DIST_IMG ))) );
    otherwise
        error(strcat('Unknown Method:', Method));
end

⌨️ 快捷键说明

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