Peak signal-to-noise ratio for images (peak signal to noise ratio, PSNR)

Source: Internet
Author: User

The peak signal-to-noise ratio (PSNR) is an engineering term that represents the maximum possible power and the ratio of destructive noise power that affects its representation accuracy. Because many signals have a very wide dynamic range, the peak signal-to-noise ratio is commonly expressed in logarithmic decibel units.

In image processing, it is necessary to evaluate the image objectively, and Psnr is often needed. Psnr is an objective criterion for measuring image distortion or noise level. The larger the Psnr value between 2 images, the more similar. The general benchmark is 30db,30db below the image deterioration is more obvious.

Psnr Definition:


WhereMax represents the maximum value of the image color, the 8bit image has a maximum value of 255. The MSE is the mean variance, defined as:


whereI and K resolution is the original image and the processed image, them*n is the size of the volume image.

/********************************************
* Input format is Cv::mat type, I1,I2 represents two images of input
*
/Double Getpsnr ( Const mat& I1, const mat& I2)
{
    Mat s1;
    Absdiff (I1, I2, S1);       	// | i1-i2| The Absdiff function is a function
    S1.convertto (S1, cv_32f)  	that calculates the absolute value of two array differences in OpenCV. Here we use the cv_32f to calculate because 8-bit unsigned char is not possible to perform the square calculation
    S1 = S1.mul (S1);           	// | I1-i2|^2
    Scalar s = SUM (S1);        	For each channel plus
    double SSE = s.val[0] + s.val[1] + s.val[2];//SUM channels
    if (SSE <= 1e-10) 			//For very small values we will be approximately equal to 0
        return 0;
    else {
        Double  MSE =sse/(Double) (I1.channels () * i1.total ());	MSE
        Double Psnr = 10.0*log10 ((255*255)/mse);
        return Psnr;
    }
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.