Canny算子(基于sobel)
1.消除噪声。 普通情况下,使用高斯平滑滤波器卷积降噪。
2.计算梯度幅值和方向。 此处,依照Sobel滤波器的步骤。
3.非极大值抑制。 这一步排除非边缘像素, 仅仅保留了一些细线条(候选边缘)。
4.滞后阈值。最后一步,Canny 使用了滞后阈值,滞后阈值须要两个阈值(高阈值和低阈值):
Ⅰ.假设某一像素位置的幅值超过 高 阈值, 该像素被保留为边缘像素。
Ⅱ.假设某一像素位置的幅值小于 低 阈值, 该像素被排除。
Ⅲ.假设某一像素位置的幅值在两个阈值之间,该像素仅仅在连接到一个高于 高 阈值的像素时被保留。
Canny算子提升了图片的质量,边缘薄
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat image, result, result2;
image = imread("D:/1.jpg", 0);
Canny(image, result, 60, 200);
threshold(result, result2, 128, 255, THRESH_BINARY_INV);
namedWindow("Canny");
imshow("Canny", result);
namedWindow("Canny2");
imshow("Canny2", result2);
waitKey(0);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
Canny算子(基于sobel)
1.消除噪声。 普通情况下,使用高斯平滑滤波器卷积降噪。
2.计算梯度幅值和方向。 此处,依照Sobel滤波器的步骤。
3.非极大值抑制。 这一步排除非边缘像素, 仅仅保留了一些细线条(候选边缘)。
4.滞后阈值。最后一步,Canny 使用了滞后阈值,滞后阈值须要两个阈值(高阈值和低阈值):
Ⅰ.假设某一像素位置的幅值超过 高 阈值, 该像素被保留为边缘像素。
Ⅱ.假设某一像素位置的幅值小于 低 阈值, 该像素被排除。
Ⅲ.假设某一像素位置的幅值在两个阈值之间,该像素仅仅在连接到一个高于 高 阈值的像素时被保留。
Canny算子提升了图片的质量,边缘薄
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat image, result, result2;
image = imread("D:/1.jpg", 0);
Canny(image, result, 60, 200);
threshold(result, result2, 128, 255, THRESH_BINARY_INV);
namedWindow("Canny");
imshow("Canny", result);
namedWindow("Canny2");
imshow("Canny2", result2);
waitKey(0);
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19