Brief introduction
Sobel (Sobel) operator
Sobel operator is an important field of computer vision processing method. Mainly used to obtain digital images of a ladder, use common sense and physicalEdge detection.
Sobel operator is detected only produce better results, but has a smooth restraining noise, but the resulting thick edge, and the false edge may occur.
Calculation method:
Use function: Sobel () function
application:
Part Code Example:
int main()
{
Mat src, gray_src,dest;
src = imread("C:/Users/86159/Desktop/yasina.jpg");
cvtColor(src, gray_src, COLOR_BGR2GRAY);
GaussianBlur(gray_src, dest, Size(3, 3), 0, 0);
Mat dest_x, dest_y;
Sobel(dest, dest_x, CV_16S, 1, 0, 3);
Sobel(dest, dest_y, CV_16S, 0, 1, 3);
convertScaleAbs(dest_x, dest_x);
convertScaleAbs(dest_y, dest_y);
Mat dst = Mat(dest.size(), dest.type());
addWeighted(dest_x, 0.5, dest_y, 0.5, 0, dst);
bitwise_not(dst, dst);
namedWindow("原图", WINDOW_AUTOSIZE);
moveWindow("原图", 50, 0);
imshow("原图", src);
namedWindow("效果图", WINDOW_AUTOSIZE);
moveWindow("效果图", 800, 0);
imshow("效果图", dst);
waitKey(0);
return 0;
}
effect:
Special Notice: Sobel acquired image blending the x and y directions do not necessarily use addWeighted (), available upon request from the best algorithm defines the following examples (G = sqrt (Gx ^ 2 + Gy ^ 2)) is given by:
Mat dst = Mat(dest.size(), dest.type());
int width = dest_x.cols;
int heigth = dest_y.rows;
for (int row = 0; row < heigth; row++)
{
for (int col = 0; col < width; col++)
{
int x = pow(dest_x.at<uchar>(row, col),2);
int y = pow(dest_y.at<uchar>(row, col),2);
int xy =sqrt(x + y);
dst.at<uchar>(row, col) = xy;
}
}