OPENCV Official Document Learning record (15)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.