Laplacian 運算元是n維歐幾里德空間中的一個二階微分運算元,定義為梯度grad的散度div。可使用運算模板來運算這定理定律。
基本介紹
- 中文名:Laplacian運算元
- 外文名:Laplacian運算元
定義
運算模板
0 | 1 | 0 |
1 | -4 | 1 |
0 | 1 | 0 |
1 | 1 | 1 |
1 | -8 | 1 |
1 | 1 | 1 |
結果對比
#include <opencv2\opencv.hpp>#include <opencv2\highgui\highgui.hpp>#include <opencv2\imgproc\imgproc.hpp>using namespace cv;int main(){ //[0] define the variables Mat src, src_gray, dst, abs_dst; //[1] load the picture src = imread("2.jpg"); //[2] show source picture imshow("Source picture", src); //[3] use Gaussian filter to eliminate noise GaussianBlur(src, src, Size(7, 7), 0, 0, BORDER_DEFAULT); //[4] convert from color picture to gray scale picture cvtColor(src, src_gray, COLOR_BGR2GRAY); //[5] use Laplace function Laplacian(src_gray, dst, CV_16S, 3, 1, 0, BORDER_DEFAULT); //[6] calculate the absolute,and convert the result to 8-bit; convertScaleAbs(dst, abs_dst); //[7] show the effect picture imshow("effect picture", abs_dst); waitKey(0); return 0;}