Laplacian算子
二阶导数的时候,最大变化处的值为零即边缘是零值。
通过二阶导数计算,依据此理论我们可以计算图像二阶导数,提取边缘。
#include
#include
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat src;
src = imread("../path.jpg");
if (src.empty())
{
cout << "could not load image..." << endl;
return -1;
}
namedWindow("src", WINDOW_AUTOSIZE);
imshow("src", src);
Mat dst,gray, laplacian;
GaussianBlur(src, dst, Size(3, 3), 0, 0);//高斯平滑
cvtColor(dst, gray, COLOR_BGR2GRAY);//转化为灰度图像
Laplacian(gray,laplacian, CV_16S, 3);//拉普拉斯变化
convertScaleAbs(laplacian, laplacian);//取绝对值
threshold(laplacian, laplacian, 0, 255, THRESH_OTSU | THRESH_BINARY);//图像二值化
namedWindow("laplacian", WINDOW_AUTOSIZE);
imshow("laplacian", laplacian);
waitKey(0);
return 0;
}
输出结果: