opencv:自定义滤波

試著忘記壹切 提交于 2020-02-01 21:31:29

卷积核的定义

均值卷积核

    // 自定义滤波 - 均值卷积
    int k = 15;
    Mat mkernel = Mat::ones(k, k, CV_32F) / (float)(k * k);
    Mat dst;
    // 第三个参数,图像深度,-1表示和输入图像一样
    filter2D(src, dst, -1, mkernel, Point(-1, -1), 0, BORDER_DEFAULT);
    imshow("custom mean filter", dst);

非均值卷积核

    // 非均值滤波
    Mat robot = (Mat_<int>(2, 2) << 1, 0, 0, -1);
    Mat result;
    filter2D(src, result, CV_32F, robot, Point(-1,-1), 0, BORDER_DEFAULT);
    imshow("result", result);
    convertScaleAbs(result, result);
    imshow("convertScaleAbs result", result);

输出图像类型

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!