2009年2月2日月曜日

OpenCV で PSNR

いつものように OpenCV で.
aとbは1チャンネルで同じサイズじゃないとダメだよ.
double calcPSNR(const CvArr *a, const CvArr *b)
{
CvMat *x;
CvMat *y;
CvMat *z;
double MSE;
double PSNR;
CvSize size;

size = cvGetSize(a);
x = cvCreateMat(size.height, size.width, CV_64F);
y = cvCreateMat(size.height, size.width, CV_64F);
z = cvCreateMat(size.height, size.width, CV_64F);

cvScale(a, x);
cvScale(b, y);

cvSub(x, y, z);
cvPow(z, z, 2.0);
MSE = cvSum(z).val[0] / double(size.width * size.height);
PSNR = 10.0 * log10(255.0 * 255.0 / MSE);

cvReleaseMat(&x);
cvReleaseMat(&y);
cvReleaseMat(&z);

return PSNR;
}

関連記事

1 コメント:

WireCut さんのコメント...

Hi,

I'm Italian and I have difficulties to comunicate in your language.

I would chat with you about your code to calculate the PSNR between images.

Could you please send me an aknoledgment email ad my addrees: wirecut (at) tiscali.it
to begin communicate with you.

Ciao
Leo

 

echinocactus. Powered By Blogger © 2009 Bombeli | Theme Design: ooruc