1 前备知识
高斯双边模糊与mean shift均值模糊两种边缘保留滤波算法,都因为计算量比较大,无法实时实现图像边缘保留滤波,限制了它们的使用场景,OpenCV中还实现了一种快速的边缘保留滤波算法。高斯双边与mean shift均值在计算时候使用五维向量是其计算量大速度慢的根本原因,该算法通过等价变换到低纬维度空间,实现了数据降维与快速计算。
2 所用到的主要OpenCv API
/** @brief Filtering is the fundamental operation in image and video processing. Edge-preserving smoothing filters are used in many different applications @cite EM11 . @param src Input 8-bit 3-channel image. @param dst Output 8-bit 3-channel image. @param flags Edge preserving filters: - **RECURS_FILTER** = 1 - **NORMCONV_FILTER** = 2 @param sigma_s Range between 0 to 200. @param sigma_r Range between 0 to 1. */ CV_EXPORTS_W void edgePreservingFilter(InputArray src, OutputArray dst, int flags = 1, float sigma_s = 60, float sigma_r = 0.4f);
3 程序代码
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace std; int main(int artc, char** argv) { Mat src = imread("images/example.png"); if (src.empty()) { printf("could not load image...\n"); return -1; } namedWindow("input", CV_WINDOW_AUTOSIZE); imshow("input", src); Mat dst; double tt = getTickCount(); edgePreservingFilter(src, dst, 1, 60, 0.44); double end = (getTickCount() - tt) / getTickFrequency(); printf("time consume : %f\n ", end); imshow("result", dst); waitKey(0); return 0; }
4 运行结果
5 扩展及注意事项
6*搬运工