图像BPR,MSE,RMSE,PSNR求取模块

本模块采用opencv中的Mat类型对图像进行操作

其中,SrcImageRec为原始参考图像,SrcUp为处理后的图像!


#pragma region Criterion BPR MSE RMSE PSNR

	Mat BadImage = Mat::zeros(SrcUp.size(),SrcUp.type());
	double BRP = 0.0,Mse = 0.0 , Rmse = 0.0, Psnr = 0.0;
	double blackcnt = 0.0,cnt = 0.0;
	int dv = 0;
	long sum = 0;

	for (int j = 0; j < height; j++)
	{
		for (int i = 0; i < width; i++)
		{
			if (SrcImageRec.at<uchar>(j,i) != 0)
			{
				//MSE RMSE PSNR
				dv = abs(SrcImageRec.at<uchar>(j,i) - SrcUp.at<uchar>(j,i));
				dv = pow(dv,2);
				sum += dv;
				//BPR
				if (dv > 1)
				{
					BadImage.at<uchar>(j,i) = 0;
					cnt++;
				}
				else
				{
					BadImage.at<uchar>(j,i) = 255;
				}
			} 
			else
			{
				blackcnt++;
			}
		}
	}

	BRP = 1.0 * cnt / (height * width - blackcnt)*100;
	Mse = 1.0 * sum/(height*width - blackcnt);
	Rmse = sqrt(Mse);
	Psnr = 10 * log10(255*255/(Mse));

	cout<<"Lee DADU Imagescale "<<Imagescale<<" BPR  : "<<BRP<<"%"<<endl;
	cout<<"Lee DADU Imagescale "<<Imagescale<<" MSE  : "<<Mse<<endl;
	cout<<"Lee DADU Imagescale "<<Imagescale<<" RMSE : "<<Rmse<<endl;
	cout<<"Lee DADU Imagescale "<<Imagescale<<" PSNR : "<<Psnr<<endl;
	imwrite(argv[5],BadImage);
#pragma endregion


你可能感兴趣的:(opencv,MSE,PSNR,RMSE)