拉普拉斯算子(laplacian)
1、拉普拉斯算子
拉普拉斯边缘提取与sobel提取不同在于:
sobel是一阶导,反应的是图像中像素跃迁较大的边缘部位,而laplacian二阶导反应的是图像中最大变化处的值,即零值,从而提取边缘。
拉普拉斯处理流程:
- 1、高斯滤波
- 2、转灰度
- 3、计算梯度(二阶导)
- 4、取绝对值(convertScaleAbs)
- 5、 结果
2、代码实现
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat img = imread("G:/testpic/img.png");
if (img.empty())
{
printf("cannot load the image");
return -1;
}
namedWindow("input", WINDOW_AUTOSIZE);
imshow("input", img);
//1、高斯滤波
Mat img_blur, gray;
GaussianBlur(img, img_blur, Size(3,3));
imshow("blur", img_blur);
//2、转灰度图
cvtColor(img_blur, gray, COLOR_BGR2GRAY);
imshow("gray", gray);
//laplacian
Laplacian(gray, result, CV_8U, 3);
//取绝对值
convertScaleAbs(result, result);
imshow("result", result);
waitKey(0);
return 0;
}
原图:
laplacian算子: