혹시 RGB PSNR 구현해보신분 계신가요?
글쓴이: poporian / 작성시간: 수, 2010/02/10 - 3:36오후
아래부분은 위키페디아의 일부 내용이고요.
Here, MAXI is the maximum possible pixel value of the image. When the pixels are represented using 8 bits per sample, this is 255. More generally, when samples are represented using linear PCM with B bits per sample, MAXI is 2B−1. For color images with three RGB values per pixel, the definition of PSNR is the same except the MSE is the sum over all squared value differences divided by image size and by three.
맨마지막 줄을 참고하여 밑에 구현한 코드인데요. 혹시 틀린부분이 있으면 지적해주세요.
int i, j; double ssdR = 0, ssdG = 0, ssdB = 0, psnr = 0; int w1 = m_b1->GetWidth(); int h1 = m_b1->GetHeight(); int w2 = m_b2->GetWidth(); int h2 = m_b2->GetHeight(); Color c1, c2; for(i = 0; i < w1; i++) { for(j = 0; j < h1; j++) { m_b1->GetPixel(i, j, &c1); m_b2->GetPixel(i, j, &c2); ssdR += (pow(((double)c1.GetR() - (double)c2.GetR()), 2)); ssdG += (pow(((double)c1.GetG() - (double)c2.GetG()), 2)); ssdB += (pow(((double)c1.GetB() - (double)c2.GetB()), 2)); } } double mse = ((ssdR + ssdG + ssdB) / 3) / (h1*w1); psnr = 10 * log10(255*255 / mse);
Forums:
댓글 달기