Zi 字媒體
2017-07-25T20:27:27+00:00
fanfuhan OpenCV 教學029 ~ opencv-029-快速的圖像邊緣濾波算法
資料來源: https://fanfuhan.github.io/
https://fanfuhan.github.io/2019/04/08/opencv-029/
GITHUB:https://github.com/jash-git/fanfuhan_ML_OpenCV
高斯雙邊模糊與mean shift均值模糊兩種邊緣保留濾波算法,都因為計算量比較大,無法實時實現圖像邊緣保留濾波,限制了它們的使用場景,OpenCV中還實現了一種快速的邊緣保留濾波算法。
高斯雙邊與mean shift均值在計算時候使用五維向量是其計算量大速度慢的根本原因,該算法通過等價變換到低緯維度空間,實現了數據降維與快速計算。
C++
#include
#include
using namespace std;
using namespace cv;
/*
* 快速的图像边缘滤波算法
*/
int main() {
Mat src = imread("../images/test.png");
if (src.empty()) {
cout << "could not load image.." << endl;
}
imshow("input", src);
Mat dst;
edgePreservingFilter(src, dst, 1, 60, 0.44);
imshow("result", dst);
waitKey(0);
return 0;
}
Python
import cv2 as cv
import numpy as np
src = cv.imread("D:/images/example.png")
cv.namedWindow("input", cv.WINDOW_AUTOSIZE)
cv.imshow("input", src)
h, w = src.shape[:2]
dst = cv.edgePreservingFilter(src, sigma_s=100, sigma_r=0.4, flags=cv.RECURS_FILTER)
result = np.zeros([h, w*2, 3], dtype=src.dtype)
result[0:h,0:w,:] = src
result[0:h,w:2*w,:] = dst
cv.imshow("result", result)
cv.imwrite("D:/result.png", result)
cv.waitKey(0)
cv.destroyAllWindows()
寫了
5860316篇文章,獲得
23313次喜歡