是一种频域率滤波方法。通过分离照射分量和反射分量,将分别对应的低频和高频信息分离。图像的照射分量通常由慢的空间变化来表征,而反射分量往往引起突变,特别是不同物体的连接部分。通过滤波器函数中的γH和γL(γH为对应的高频系数,γL为对应的低频系数,使得γH > 1且γL < 1)使得滤波器趋向于衰减低频信号,增强高频信号,最终的结果是同时进行动态范围的压缩和对比度的增强。
void homomorphicfiltering(IplImage* src, IplImage* dst,
const double & gammaH, const double& gammaL, const double& C, const double & d0)
{
if ( gammaH < 1 || gammaL > 1 )
{
cerr<< "gammaH > 1 && gammaL < 1时高频增强,低频减小!" <<endl;
return;
}
if (src->nChannels != 2 || dst->nChannels != 2 )
{
cerr<< "通道数y必须为a1!!" <<endl;
return;
}
if (src->width != dst->width || src->height != dst->height)
{
cvError(CV_StsUnmatchedSizes, "homomorphicfiltering", "图像的长和宽必须相等" , __FILE__, __LINE__ );
}
//图像大小
CvSize sz = cvSize(src->width, src->height);
CvMat* temp = cvCreateMat(src->height, src->width, CV_64FC1);
double P = src->width/2;
double Q = src->height/2;
IplImage* imgRe = cvCreateImage(sz, src->depth, 1);
IplImage* imgIm = cvCreateImage(sz, src->depth, 1);
IplImage* srcTemp = cvCloneImage(src);
IplImage* dstTemp = cvCloneImage(src);
fftshift(src, srcTemp);
cvSplit(srcTemp, imgRe, imgIm, NULL, NULL);
for (int y = 0; y != src->height; ++y)
{
for (int x = 0; x != src->width; ++x)
{
double d2 = pow (pow(x - P, 2.0) + pow(y - Q, 2.0), 0.5);
*(( double*)CV_MAT_ELEM_PTR(*temp, y, x)) = (gammaH - gammaL)*(1 - exp(-C*d2/pow (d0, 2))) + gammaL;
}
}
cvMul(imgRe, temp, imgRe);
cvMul(imgIm, temp, imgIm);
cvMerge(imgRe, imgIm, NULL, NULL, dst);
fftshift(dst, dst);
}
08-12
214
06-23