如何求彩色图像的峰值信噪比?求matlab编的M文件~~

2024-12-01 11:03:56
推荐回答(2个)
回答(1):

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;
}

回答(2):

ff=input(