OPENCV对图像进行简单平滑处理BLUR

    科技2024-01-02  72

    参考来源:https://docs.opencv.org/3.4/dc/dd3/tutorial_gausian_median_blur_bilateral_filter.html

    switch(SMOOTH_METHOD) { case NO_BLUR: img2 = img; break; case HOMO_BLUR: cv::blur(img, img2, cv::Size(KERNEL_LENGTH, KERNEL_LENGTH), cv::Point(-1,-1) ); break; case GAUSS_BLUR: cv::GaussianBlur(img, img2, cv::Size(KERNEL_LENGTH, KERNEL_LENGTH), 0, 0 ); break; case MEDIAN_BLUR: cv::medianBlur(img, img2, KERNEL_LENGTH); break; case BILATERAL_BLUR: cv::bilateralFilter(img, img2, KERNEL_LENGTH, KERNEL_LENGTH*2, KERNEL_LENGTH/2); break; default: return; }

    Normalized Box Filter

    This filter is the simplest of all! Each output pixel is the mean of its kernel neighbors ( all of them contribute with equal weights)

     简单均值滤波器

    src: Source imagedst: Destination imageSize( w, h ): Defines the size of the kernel to be used ( of width w pixels and height h pixels)Point(-1, -1): Indicates where the anchor point (the pixel evaluated) is located with respect to the neighborhood. If there is a negative value, then the center of the kernel is considered the anchor point. 

    Gaussian Filter 

    Probably the most useful filter (although not the fastest). Gaussian filtering is done by convolving each point in the input array with a Gaussian kernel and then summing them all to produce the output array.src: Source imagedst: Destination imageSize(w, h): The size of the kernel to be used (the neighbors to be considered). w and h have to be odd and positive numbers otherwise the size will be calculated using the σx and σy arguments.σx: The standard deviation in x. Writing 0 implies that σx is calculated using kernel size.σy: The standard deviation in y. Writing 0 implies that σy is calculated using kernel size.

    高斯滤波器:最常用但也比较耗时

    Median Filter

    The median filter run through each element of the signal (in this case the image) and replace each pixel with the median of its neighboring pixels (located in a square neighborhood around the evaluated pixel).src: Source imagedst: Destination image, must be the same type as srci: Size of the kernel (only one because we use a square window). Must be odd.奇数

    中值滤波器:去周围元素的中值 

    Bilateral Filter

    So far, we have explained some filters which main goal is to smooth an input image. However, sometimes the filters do not only dissolve the noise, but also smooth away the edges. To avoid this (at certain extent at least), we can use a bilateral filter.In an analogous way as the Gaussian filter, the bilateral filter also considers the neighboring pixels with weights assigned to each of them. These weights have two components, the first of which is the same weighting used by the Gaussian filter. The second component takes into account the difference in intensity between the neighboring pixels and the evaluated one.src: Source imagedst: Destination imaged: The diameter of each pixel neighborhood.σColor: Standard deviation in the color space.σSpace: Standard deviation in the coordinate space (in pixel terms)

     双边滤波器:表面一定程度上边缘模糊。

     

    Processed: 0.016, SQL: 8