note
mat = (0,1,0;1,-4,1;0,1,0)
code
// 图像增强之图像锐化(边缘增强)之拉普拉斯算子
void GetLaplaceMat(Mat& laplaceMat) {
laplaceMat = (Mat_<int>(3,3) << 0,1,0,1,-4,1,0,1,0);
}
void EdgeSharpenLaplace(Mat&src, Mat& res) {
Mat laplaceMat;
GetLaplaceMat(laplaceMat);
filter2D(src, res, src.type(), laplaceMat);
}
void EdgeSharpenLaplaceTest(void) {
Mat src = imread("../source/lena.jpg", IMREAD_GRAYSCALE);
if (src.empty()) {
printf("src empty\n");
return;
}
Mat res(src.rows, src.cols, src.type(), Scalar(0));
namedWindow("src", WINDOW_NORMAL);
namedWindow("res", WINDOW_NORMAL);
EdgeSharpenLaplace(src, res);
imshow("src", src);
imshow("res", res);
MyWait();
destroyAllWindows();
}