classdef PSNRImageMetricItem < MetricItem
    
    
    
    methods
        function obj=PSNRImageMetricItem
            obj=obj@MetricItem('PSNR');
        end
        
        function psnr=calc(obj,item1,item2)
            fprintf('Calculating PSNR ... \n');
            image1=uint8(imread(item1.getfilename));
            image2=uint8(imread(item2.getfilename));
            if size(image1,3)>1
                image1=rgb2gray(image1);
            end
            if size(image2,3)>1
                image2=rgb2gray(image2);
            end
            maxint=255;
            mse=abs(double(image1)-double(image2)).^2;
            [n_rows,n_coloumns]=size(image1);
            mse=sum(mse(:))/(n_rows*n_coloumns);
            psnr=10*log10(maxint^2/mse);
        end
    end
end