提取X方向(水平方向)的边缘。
提取Y方向(垂直方向)的边缘。
Sobel算子的优点是方法简单、处理速度快,并且所得的边缘光滑、连续.
其缺点是边缘较粗,由于处理时需作两值化处理,故得到的边缘与阈值的选取也有很大的关系.
public static void Sobel(InputArray Src_Images, OutputArray Dst_Images)
{
Mat matX = new Mat();
Mat maty = new Mat();
//X方向Sobel运算
Cv2.Sobel(Src_Images, matX, MatType.CV_64F, 1, 0,3);
Cv2.ConvertScaleAbs(matX, matX);
//Y方向Sobel运算
Cv2.Sobel(Src_Images, maty, MatType.CV_64F, 0, 1,3);
Cv2.ConvertScaleAbs(maty, maty);
Cv2.AddWeighted(matX, 0.5, maty, 0.5, 0, Dst_Images);
}
public static void Scharr(InputArray Src_Images, OutputArray Dst_Images)
{
Mat matX = new Mat();
Mat maty = new Mat();
Cv2.Scharr(Src_Images, matX, MatType.CV_64F, 1, 0,3);
Cv2.ConvertScaleAbs(matX, matX);
Cv2.Scharr(Src_Images, maty, MatType.CV_64F, 0, 1,3);
Cv2.ConvertScaleAbs(maty, maty);
Cv2.AddWeighted(matX, 0.5, maty, 0.5, 0, Dst_Images);
}
public static void Laplacian(InputArray Src_Images, OutputArray Dst_Images)
{
Mat mat = new Mat();
Cv2.Laplacian(Src_Images, mat, MatType.CV_16S);
Cv2.ConvertScaleAbs(mat, Dst_Images);
}
Canny边缘检测一般步骤:
1.去噪,通常采用高斯滤波器去除噪声
2.求梯度(包括方向),梯度方向一般总与边界垂直,被归为四类:垂直、水平、和两个对角线
3.非极大值抑制
4.滞后阈值
public static void Canny(InputArray Src_Images, OutputArray Dst_Images, double low_thresold,double up_thresold)
{
Mat mat = new Mat();
Cv2.Canny(Src_Images, Dst_Images, low_thresold, up_thresold);
}