OpenCv图像处理之中值滤波-非线性滤波(一)

OpenCv图像处理之中值滤波-非线性滤波

来看一下源码中对medianBlur()的定义和参数描述

CV_EXPORTS_W void medianBlur(InputArray src, OutputArray dst, int ksize);
//src通道数可选1,3,4,若核大小为3或5时,则图像的深度应为CV_8U, CV_16U, or CV_32F,若为大孔径尺寸,那么它的深度只能为CV_8U
@param src input 1-, 3-, or 4-channel image; when ksize is 3 or 5, the image depth should be
CV_8U, CV_16U, or CV_32F, for larger aperture sizes, it can only be CV_8U.
//目标矩阵尺寸和类型和src一样
@param dst destination array of the same size and type as src.
//核尺寸必须是大于1的奇数
@param ksize aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7 ...

test.cpp文件//用于定义常用的函数

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

void resize_img(Mat &mat, int width, int height, int interpolation = INTER_AREA) {
    
    

    cv::resize(mat, mat, Size(width, height), 0, 0, interpolation);
}

Mat zero_mat(Mat mat, int width, int height) {
    
    
    Mat dst = Mat::zeros(Size(width, height), mat.type());
    return dst;
}

main.cpp文件

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

void resize_img(Mat &mat, int width, int height, int interpolation = INTER_AREA);

Mat zero_mat(Mat mat, int width, int height);

int main() {
    
    
    Mat original_img, clone_img, dst_img;
    original_img = imread("D:/cat.jpg", IMREAD_COLOR);
    if (original_img.empty()) {
    
    
        cout << "open error!" << endl;
        return -1;
    }
    clone_img = original_img.clone();
    double scale = 0.5;
    int width = int(clone_img.cols * scale);
    int height = int(clone_img.rows * scale);
    resize_img(clone_img, width, height);
    dst_img = zero_mat(dst_img, width, height);
    medianBlur(clone_img, dst_img, 9);
    imshow("dst", dst_img);
    waitKey(0);
    return 0;
}

效果显示
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_35140742/article/details/120209587