Matlab中psf2otf()函数在opencv中的实现

时间:2023-03-09 23:16:13
Matlab中psf2otf()函数在opencv中的实现

在Matlab中有个psf2otf()函数,可以将小尺寸的点扩散函数,扩大尺寸,并作二维傅里叶变换,opencv中没有这个函数,所以编了这么个函数:

/*****************************
Mat psf2otf(const Mat&psf, Size outSize=Size(3,3))
参数说明:
psf——输入的点扩散函数;
outSize——是输出otf的尺寸;

在本程序中,还调用了circShift()函数,该函数具体参见:
http://www.cnblogs.com/phoenixdsg/p/8425336.html

本程序中,还调用了mymax()函数和myMagnitude()函数,难度不大自己想办法吧。

*******************************/

下面是psf2otf()函数的定义:

{

    Mat otf;
if(countNonZero(psf)&&!psf.empty())
{
Size psfSize=psf.size(); Size paddSize=outSize-psfSize;
copyMakeBorder(psf,otf,paddSize.height/,paddSize.height/,
paddSize.width/ ,paddSize.width/,
BORDER_CONSTANT,Scalar());
circShift(otf,-otf.size().height/,-otf.size().width/);
otf=fft(otf);
//计算psf的元素个数
int nElem=psf.cols*psf.rows; double nOps=; int nfft=nElem/psfSize.width;
nOps +=nfft+psfSize.width*log2(psfSize.width)*nfft;
nfft=nElem/psfSize.height;
nOps +=nfft+psfSize.width*log2(psfSize.height)*nfft;
//将复数otf分解成实部real和虚部imagin
Mat planes[];
split(otf,planes);
double imagin_max=mymax(abs(planes[]));
double mag_max=mymax(myMagnitude(otf)); if((imagin_max/mag_max)<eps)
return planes[]; }
return otf;
}

下面是对该函数的测试程序:

int main()
{
Mat mat=(Mat_<double>(,)<<
,-,,
-,,-,
,-,);
Mat otf=psf2otf(mat);
cout<<otf<<endl;
return ;
}

输出结果如下:

Matlab中psf2otf()函数在opencv中的实现