sobel算子:
I為原圖像
1.水平變化
將
與一個奇數大小的內核
進行卷積。比如,當內核大小為3時,
的計算結果為:

2.垂直變化:
將:math:I 與一個奇數大小的內核
進行卷積。比如,當內核大小為3時,
的計算結果為

3.結果:

4.openCv提供的函數:
Sobel( src_gray, grad_y, ddepth, 0, 1, 3, scale, delta, BORDER_DEFAULT );該函數接受了以下參數:
src_gray: 在本例中為輸入圖像,元素類型 CV_8Ugrad_x/grad_y: 輸出圖像.ddepth: 輸出圖像的深度,設定為 CV_16S 避免外溢。x_order: x 方向求導的階數。y_order: y 方向求導的階數。scale, delta 和 BORDER_DEFAULT: 使用默認值我的源代碼:#include <cv.h>#include <opencv2/core/core.hpp> #include <opencv2/imgPRoc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> using namespace std;using namespace cv;int main( int argc, char** argv ){ Mat image=imread("./1.jpg",CV_LOAD_IMAGE_GRAYSCALE); Mat grad_x; Mat grad_y; Mat sobel; //計算sobel濾波器的模 Sobel(image,grad_x,CV_16S,1,0); Sobel(image,grad_y,CV_16S,0,1); //計算L1的模 sobel=abs(grad_x)+abs(grad_y); // Mat sobel_image; //cvConvertScaleAbs函數是OpenCV中的函數,使用線性變換轉換輸入數組元素成8位無符號整型。 convertScaleAbs(sobel,sobel_image); imshow("sobel",sobel_image); waitKey(0); return 0;}
新聞熱點
疑難解答