%% PSNRの計算
clear all;

% 画像データ読み込み (bmp:原画像、jpg:JPEG圧縮画像)
oRGB = imread('test.bmp');
cRGB = imread('test.jpg');
[height,width,depth] = size(oRGB);

% 量子化誤差分散
difR = reshape(oRGB(:,:,1)-cRGB(:,:,1), width*height, 1);
difG = reshape(oRGB(:,:,2)-cRGB(:,:,2), width*height, 1);
difB = reshape(oRGB(:,:,3)-cRGB(:,:,3), width*height, 1);
sigmaR = mean( difR.^2 );
sigmaG = mean( difG.^2 );
sigmaB = mean( difB.^2 );

% PSNR計算＆表示
snrR = -10.0 * log10( sigmaR / (255*255) )
snrG = -10.0 * log10( sigmaG / (255*255) )   
snrB = -10.0 * log10( sigmaB / (255*255) )   

% 画像表示
subplot(2,1,1);
imshow(oRGB);
subplot(2,1,2);
imshow(cRGB);
