Laplace Edge Detection method
Unlike the first derivative edge detection of Sobel, the Laplace operator is a kind of detection which takes the transverse longitudinal of the image into account, and mainly uses the second derivative to carry out the discrete transformation:
Because Laplace is also transformed using analytic gradients, the Sobel method is actually called. In the previous article, it was shown that the results were calculated using Sobel in two directions.
The code is as follows:
1#include <opencv2\opencv.hpp>2#include <iostream>3#include <string>4 5 #pragmaComment (linker, "/subsystem:\" windows\ "/entry:\" Maincrtstartup\ "")6 7 using namespacestd;8 using namespaceCV;9 Ten voidShow (ConstSTD::string&name,ConstMat &img) One { A Namedwindow (name, cv_window_autosize); - imshow (Name, IMG); - } the - intMainvoid) - { -Mat src = imread ("lena.jpg"); + if(Src.empty ()) - return-1; + Mat Src_gray, DST; A intKernel_size =3; at intScale =1; - intDelta =0; - intDdepth =cv_16s; - stringWin_name ="Laplace demo"; -Gaussianblur (SRC, src, Size (3,3),0,0, Border_default); - cvtcolor (SRC, Src_gray, cv_rgb2gray); inShow ("SRC", SRC); - Mat abs_dst; to Laplacian (Src_gray, DST, ddepth, kernel_size, scale, Delta, Border_default); + Convertscaleabs (DST, ABS_DST); - Show (Win_name, ABS_DST); the Waitkey (); * return 0; $}
The result is:
Pick a Sobel The result of the overlay treatment:
While it is obvious that soble is better at handling overlays, it is easier to compare Laplace with less code.
The implementation process is similar to the previous Sobel operation:
1. The image is Gaussian blurred to de-noising;
2. Load and convert the processed image into grayscale image;
3. Laplace transform: The parameters are corresponding to the input and output, the color depth of the output image (that is, the elements of the matrix in what form), kernel size, the rest is now our unknown default value;
4, the output image is converted to the same as the original input depth of the image storage mode;
5. Output conversion results;
Above.
OPENCV Official Document Learning record (15)