【OpenCV】Laplance算子
解释:在二阶导数的时候,最大变化处的值为零即边缘是零值。通过二阶
导数计算,依据此理论我们可以计算图像二阶导数,提取边缘。
Laplance算子
->拉普拉斯算子(Laplance operator)
Opencv已经提供了相关API - cv::Laplance
处理流程
高斯模糊 – 去噪声GaussianBlur()
转换为灰度图像cvtColor()
拉普拉斯 – 二阶导数计算Laplacian()
取绝对值convertScaleAbs()
显示结果
相关API cv::Laplacian
Laplacian(
InputArray src,
OutputArray dst,
int depth, //深度CV_16S
int kisze, // 3
double scale = 1,
double delta =0.0,
int borderType = 4
)
代码实现
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat src, gray_src, dst, edge_image;
src = imread("1.jpg");
if (!src.data) {
cout << "can not load the image..." << endl;
return -1;
}
char input_title []= "input";
char output_title[] = "edge_image";
namedWindow(input_title, CV_WINDOW_AUTOSIZE);
namedWindow(output_title, CV_WINDOW_AUTOSIZE);
imshow(input_title, src);
GaussianBlur(src, dst, Size(3, 3), 0);
cvtColor(dst, gray_src, CV_BGR2GRAY);
Laplacian(gray_src, edge_image, CV_32F, 3);
convertScaleAbs(edge_image, edge_image);
imshow(output_title, edge_image);
imwrite("laplacian.jpg", edge_image);
waitKey(0);
return 0;
}
实验效果
原图
laplacian
+convertScaleAbs