一、Sobel算子
1、什么是sobel算子
sobel主要是用于邊緣檢測的離散微分算子,結合了高斯平滑和微分求導,用來計算圖像灰度的近似梯度。主要是用來產生一個梯度矢量的。
2、sobel算子的計算過程
即如何得出圖像的梯度矢量
3、soble函數
void Sobel(InputArray src,OutputArray dst, int ddepth, int dx, int dy, int ksize = 3,double scale = 1,double delta = 0, int boederType = BORDER_DEFAULT);
ddepth 為輸出圖像深度,當然要根據輸入圖像深度來選擇
若src.depth() = CV_8U,取ddepth = -1/CV_16S/CV_32F/CV_64F
若src.depth() = CV_16U/CV_16S,取ddepth = -1/CV_32F/CV_64F
若src.depth() = CV_32F,取ddepth = -1/CV_32F/CV_64F
若src.depth() = CV_64F,取ddepth = -1/CV_64F
dx 和dy分別表示x方向和y方向的差分階數
ksize默認為3,表示sobel核的大小,必須取1,3,5,7
scale表示計算導數時可選的縮放因子,=1則表示沒有縮放
delta為將結果存入目標矩陣之前的可選項
我們常用dx = 1,dy = 0,ksize = 3來基三x方向的導數,dx = 0,dy =1,ksize = 3來計算y方向的導數
int test18() {
Mat img = imread("C:\Urs\86188\Desktop\526.jpg");
Mat grad_x,grad_y;
Mat abs_grad_x, abs_grad_y,dst;
Mat img_gray;
cvtColor(img, img_gray, COLOR_BGR2GRAY);
imshow("img", img);
imshow("img_gray", img_gray);
//求x方向梯度
Sobel(img, grad_x, CV_16S, 1, 0, 3, 1, 1, BORDER_DEFAULT);
convertScaleAbs(grad_x, abs_grad_x);
imshow("x方向sobel", abs_grad_x);
//求y方向梯度
Sobel(img, grad_y, CV_16S, 0, 1, 3, 1, 1, BORDER_DEFAULT);
convertScaleAbs(grad_y, abs_grad_y);
imshow("y方向sobel", abs_grad_y);
//合并梯度
addWeighted(abs_grad_x,0.5, abs_grad_y,0.5, 0,dst);
imshow("dst sobel", dst);
waitKey(10000000);
return 0;
}
本文發布于:2023-02-28 21:01:00,感謝您對本站的認可!
本文鏈接:http://www.newhan.cn/zhishi/a/167771685196630.html
版權聲明:本站內容均來自互聯網,僅供演示用,請勿用于商業和其他非法用途。如果侵犯了您的權益請與我們聯系,我們將在24小時內刪除。
本文word下載地址:sobel算子(sobel算子邊緣檢測).doc
本文 PDF 下載地址:sobel算子(sobel算子邊緣檢測).pdf
| 留言與評論(共有 0 條評論) |