基于低/高通滤波器掩模OpenCV的带阻滤波器掩模

时间:2014-11-09 19:52:33

标签: c++ opencv image-processing fft

我正在寻找合并以下图片的方法: enter image description here enter image description here

成像:

enter image description here

我正在做的是尝试使用butterworth低通/高通滤波器制作带阻滤波器。 如果没有办法合并这样的面具我会发布我的butterworth代码所以也许你可以帮我重新实现它来做这项工作:

void Processing::lowhighpass_filter(cv::Mat &dft_Filter, int D, int n, bool highpass)
{
    dft_Filter = cv::Mat(dft_Filter.rows,dft_Filter.cols,CV_32F,cv::Scalar::all(0));

    cv::Point centre = cv::Point(dft_Filter.rows / 2, dft_Filter.cols / 2);
    double radius;

    // based on the forumla in the IP notes (p. 130 of 2009/10 version)
    for(int i = 0; i < dft_Filter.rows; i++)
    {
        for(int j = 0; j < dft_Filter.cols; j++)
        {
            radius = (double) std::sqrt(std::pow((i - centre.x), 2.0) + std::pow((double) (j - centre.y), 2.0));
            dft_Filter.at<float>(i,j) = (float) ( 1 / (1 + std::pow((double) (radius /  D),   (double) (2 * n))));
        }
    }

    if (highpass)
    {
        dft_Filter = cv::Scalar::all(1) - dft_Filter;
        //cv::imshow("highpass_filter", dft_Filter);
    }

    cv::Mat toMerge[] = {dft_Filter, dft_Filter};
    cv::merge(toMerge, 2, dft_Filter);
}

我需要在第三张图像上创建蒙版,可能具有可修改的内圈和外圈半径。有线索吗?

2 个答案:

答案 0 :(得分:2)

将第一个标准化为[0:1]范围,然后将这两个图像之间的每个元素相乘。 不要忘记,它们需要具有CV_32FC或CV_64FC元素类型。

答案 1 :(得分:0)

您还需要在FT域中找到圆的半径,稍后您将指定半径值以停止所需的频率。 如果您已经更正了代码,请在此处共享您的代码,以便其他人获得您的代码帮助。