参照链接:https://github.com/carandraug/PeterKovesiImage/blob/master/PhaseCongruency/gaborconvolve.m点击打开链接
毕设要用Log-Gabor滤波器来实现视网膜血管增强,这东西真是折腾了我好一段时间。。。。Matlab代码转到C++代码没动什么脑子,基本就是按逻辑翻译过来的
Log-Gabor滤波器的概念本文暂不表述了,待后期添加
首先是一些与滤波器无关的matlab转C++用 的代码:
void circshift(Mat& out, const Point& delta)
{
Size sz = out.size();
// 错误检查
assert(sz.height > 0 && sz.width > 0);
// 此种情况不需要移动
if ((sz.height == 1 && sz.width == 1) || (delta.x == 0 && delta.y == 0))
return;
// 需要移动参数的变换,这样就能输入各种整数了
int x = delta.x;
int y = delta.y;
if (x > 0) x = x % sz.width;
if (y > 0) y = y % sz.height;
if (x < 0) x = x % sz.width + sz.width;
if (y < 0) y = y % sz.height + sz.height;
// 多维的Mat也能移动
vector<Mat> planes;
split(out, planes);
for (size_t i = 0; i < planes.size(); i++)
{
// 竖直方向移动
Mat tmp0, tmp1, tmp2, tmp3;
Mat q0(planes[i], Rect(0, 0, sz.width, sz.height - y));
Mat q1(planes[i], Rect(0, sz.height - y, sz.width, y));
q0.copyTo(tmp0);
q1.copyTo(tmp1);
tmp0.copyTo(planes[i](Rect(0, y, sz.width, sz.height - y)));
tmp1.copyTo(planes[i](Rect(0, 0, sz.width, y)));
// 水平方向移动
Mat q2(planes[i], Rect(0, 0, sz.width - x, sz.height));
Mat q3(planes[i], Rect(sz.width - x, 0, x, sz.height));
q2.copyTo(tmp2);
q3.copyTo(tmp3);
tmp2.copyTo(planes[i](Rect(x, 0, sz.width - x, sz.height)));
tmp3.copyTo(planes[i](Rect(0, 0, x, sz.height)));
}
merge(planes, out);
}
void fftshift(Mat& out)
{
Size sz = out.size();
Point pt(0, 0);
pt.x = (int)floor(sz.width / 2.0);
pt.y = (int)floor(sz.height / 2.0);
circshift(out, pt);
}
void ifftshift(Mat& out)
{
Size sz = out.size();
Point pt(0, 0);
pt.x = (int)ceil(sz.width / 2.0);
pt.y = (int)ceil(sz.height / 2.0);
circshift(out, pt);
}
void meshgrid(double xStart, double xEnd, double yStart, double yEnd,
Mat& X, Mat& Y)
{
std::vector<double> t_x, t_y;
while (xStart <= xEnd)
{
t_x.push_back(xStart);
++xStart