CString CImgEnhance::SNR(unsigned char* m_pSrcImgData)
{
int byteCount; //DIB位图的字节数
int i;
// LPBITMAPINFOHEADER lpbmi;
// lpbmi=(LPBITMAPINFOHEADER)lpSrcDIB;
// m_pSrcImgData=(LPBYTE)lpbmi+lpbmi->
biSize+sizeof(RGBQUAD)*lpbmi->
biClrUsed;
//计算图像信噪比
double temp1=0.0;
double temp2=0.0;
//处理8位灰度图像
if (m_nBitCount==8)
{
//计算整幅DIB位图的字节数
byteCount =m_imgHeight*m_imgWidth*m_nBitCount/8;
for( i=0; i
temp1=temp1+(double)m_pImgData[i]*m_pImgData[i];
temp2=temp2+(double)(m_pImgData[i]-
m_pSrcImgData[i])*(m_pImg Data[i]-m_pSrcImgData[i]);
}
}
else
{
AfxMessageBox("只能处理8位灰度图像!");
return "ERROR";
}
double SNR=temp1/temp2;
SNR=10*log10(SNR);
CString StrSNR;
StrSNR.Format("%f",SNR);
return StrSNR;
}
CString CImgEnhance::PSNR(unsigned char* m_pSrcImgData)
{
int byteCount; //DIB位图的字节数
int i;
//计算图像峰值信噪比
double temp1=0.0;
double temp2=0.0;
//处理8位灰度图像
if (m_nBitCount==8)
{
//计算整幅DIB位图的字节数
byteCount =m_imgHeight*m_imgWidth*m_nBitCount/8;
for( i=0; i
temp1=temp1+(double)m_pImgData[i]*m_pImgData[i];
temp2=temp2+(double)(m_pImgData[i]
-m_pSrcImgData[i])*(m_pImg Data[i]-m_pSrcImgData[i]);
}
}
else
{
AfxMessageBox("只能处理8位灰度图像!");
return "ERROR";
}
double PSNR=m_imgHeight*m_imgWidth/temp2;
PSNR=10*log10(255*255*PSNR); //PSNR即为峰值信噪比
CString StrPSNR;
StrPSNR.Format("%f",PSNR);
return StrPSNR;
}
ff=input(