卷積應用-圖像邊緣提取

卷積應用-圖像邊緣提取 邊緣是什么 – 是像素值發生躍遷的地方,是圖像的顯著特征之一, 在圖像特征提取、對象檢測、模式識別等方面都有重要的作用。 如何捕捉/提取邊緣 – 對圖像求它的一階導數 - delta = f(x) – f(x-1), delta越大,說明像素在X方向變化越大,邊緣信號越強
Sobel算子 是離散微分算子(discrete differentiation operator), 用來計算圖像灰度的近似梯度Soble算子功能集合高斯平滑和微分求導 又被稱為一階微分算子,求導算子,在水平和垂直兩個方向上求導,得到圖像X方法與Y方向梯度圖像



cv::Sobel ( InputArray Src // 輸入圖像 OutputArray dst // 輸出圖像,大小與輸入圖像一致 int depth // 輸出圖像深度. Int dx // X方向,幾階導數 int dy // Y方向,幾階導數. int ksize // SOBEL算子kernel大小,必須是1、3、5、7、 double scale = 1 double delta = 0 int borderType = BORDER_DEFAULT )
cv::Scharr ( InputArray Src // 輸入圖像 OutputArray dst // 輸出圖像,大小與輸入圖像一致 int depth // 輸出圖像深度 Int dx. // X方向,幾階導數 int dy // Y方向,幾階導數 double scale = 1 double delta = 0 int borderType = BORDER_DEFAULT )
其他API
GaussianBlur( src, dst, Size(3,3), 0, 0, BORDER_DEFAULT ); cvtColor( src, gray, COLOR_RGB2GRAY ); addWeighted( A, 0.5,B, 0.5, 0, AB); convertScaleAbs(A, B)// 計算圖像A的像素絕對值,輸出到圖像B
int main(int argc, char** argv) { Mat src, dst; src = imread(STRPAHT2); if (!src.data) { printf("could not load image...\n"); return -1; } Mat gray_src; GaussianBlur(src, dst, Size(3, 3), 0, 0, BORDER_DEFAULT); cvtColor(dst, gray_src, CV_BGR2GRAY); //imshow("gray image", gray_src); Mat xgrad, ygrad; //Scharr(gray_src, xgrad, CV_16S, 1, 0, 3); //Scharr(gray_src, ygrad, CV_16S, 0, 1, 3); //convertScaleAbs(xgrad, xgrad); //convertScaleAbs(ygrad, ygrad); //imshow("xgrad", xgrad); //imshow("ygrad", ygrad); Sobel(gray_src, xgrad, CV_16S, 1, 0, 3); Sobel(gray_src, ygrad, CV_16S, 0, 1, 3); convertScaleAbs(xgrad, xgrad); convertScaleAbs(ygrad, ygrad); imshow("xgrad", xgrad); imshow("ygrad", ygrad); waitKey(0); return 0; }
