bilateralFilter() 函数

void cv::bilateralFilter	(	InputArray 	src,
OutputArray 	dst,
int 	d,
double 	sigmaColor,
double 	sigmaSpace,
int 	borderType = BORDER_DEFAULT 
)	
  • src

输入图片需要是 8 位的数据类型,或者浮点型,可以是单通道,或者三通道。
Source 8-bit or floating-point, 1-channel or 3-channel image.

  • dst

输出图片和输入图片有相同的尺寸,数据类型,通道数
Destination image of the same size and type as src .

  • d

邻域的直径,如果是小于等于 0,则由 sigmaSpace 计算得到
Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, it is computed from sigmaSpace.

  • sigmaColor

颜色空间滤波器的标准差。等大的值表示邻域中更多的颜色被混合,即半等价颜色的区域更大
Filter sigma in the color space. A larger value of the parameter means that farther colors within the pixel neighborhood (see sigmaSpace) will be mixed together, resulting in larger areas of semi-equal color.

  • sigmaSpace

空域滤波器的标准差。更大的值代表更大范围内的像素(颜色相近)会被相互影响。当 d 大于 0 的时候,sigmaSpace 被忽略,否则 d 由 sigmaSpace 计算得到。
Filter sigma in the coordinate space. A larger value of the parameter means that farther pixels will influence each other as long as their colors are close enough (see sigmaColor ). When d>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is proportional to sigmaSpace.

  • borderType

外延模式
border mode used to extrapolate pixels outside of the image, see BorderTypes

使用注意点

  • 双边滤波可以在去除噪声的同时,保持边缘信息相对清晰。但是,相比于大多数滤波器,双边滤波的速度是非常慢的。

  • 关于 sigma 的值: 通常为了简化,两个 sigma 的值可以设置为相等。如果这两个值都非常小,比如小于 10,则滤波器没有什么太大的效果。如果大于 150,则会有非常强的影响,甚至会让图片产生卡通化的效果。

  • 关于滤波器尺寸: 通常 d 大于 5 的时候,滤波过程会非常慢,所以如果是在线处理,那么建议 d 设置为 5,而离线处理非常多的噪声的情况,可以考虑把 d 设置为 9。

测试代码

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

using namespace std;

int main()
{
	cv::Mat img1 = imread("./1.jpg", cv::IMREAD_ANYCOLOR);
	cv::Mat img2 = imread("./2.jpeg", cv::IMREAD_ANYCOLOR);

	if (img1.empty() || img2.empty())
	{
		cout << "Image read failed~" << endl;
		return;
	}

	cv::Mat result_img1_1, result_img1_2, result_img2_1, result_img2_2;

	// 不同直径
	cv::bilateralFilter(img1, result_img1_1, 9, 50, 25 / 2);
	cv::bilateralFilter(img1, result_img1_2, 25, 50, 25 / 2);
	// 不同标准差
	cv::bilateralFilter(img2, result_img2_1, 9, 9, 9);
	cv::bilateralFilter(img2, result_img2_2, 9, 200, 200);

	// 显示结果
	cv::imshow("img1", img1);
	cv::imshow("d=9", result_img1_1);
	cv::imshow("d=25", result_img1_2);

	cv::imshow("img2", img2);
	cv::imshow("s=9", result_img2_1);
	cv::imshow("s=200", result_img2_2);

	cv::waitKey(0);
	return 0;
}

测试效果

  • 不同滤波器尺寸:

在这里插入图片描述

  • 不同的标准差:

在这里插入图片描述

GitHub 加速计划 / opencv31 / opencv
142
15
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:3 个月前 )
d9a139f9 Animated WebP Support #25608 related issues #24855 #22569 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake 1 天前
09030615 V4l default image size #25500 Added ability to set default image width and height for V4L capture. This is required for cameras that does not support 640x480 resolution because otherwise V4L capture cannot be opened and failed with "Pixel format of incoming image is unsupported by OpenCV" and then with "can't open camera by index" message. Because of the videoio architecture it is not possible to insert actions between CvCaptureCAM_V4L::CvCaptureCAM_V4L and CvCaptureCAM_V4L::open so the only way I found is to use environment variables to preselect the resolution. Related bug report is [#25499](https://github.com/opencv/opencv/issues/25499) Maybe (but not confirmed) this is also related to [#24551](https://github.com/opencv/opencv/issues/24551) This fix was made and verified in my local environment: capture board AVMATRIX VC42, Ubuntu 20, NVidia Jetson Orin. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [X] I agree to contribute to the project under Apache 2 License. - [X] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [X] The PR is proposed to the proper branch - [X] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake 1 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐