Edge detection using Laplacian operator

void Laplacian(InputArray src, OutputArray dst, int ddepth, int ksize=1, double scale=1, double delta=0, int borderType=BORDER_DEFAULT )

  • src – Source image.
  • dst – Destination image of the same size and the same number of channels as src .
  • ddepth – Desired depth of the destination image.
  • ksize – Aperture size used to compute the second-derivative filters. See getDerivKernels() for details. The size must be positive and odd.
  • scale – Optional scale factor for the computed Laplacian values. By default, no scaling is applied. See getDerivKernels() for details.
  • delta – Optional delta value that is added to the results prior to storing them in dst .
  • borderType – Pixel extrapolation method. See borderInterpolate() for details.
You can find an example in OpenCV Documentation.


  1. Load image
  2. Remove noise by blurring with a Gaussian filter
  3. Convert to gray-scale.
  4. Apply the Laplacian operator to find the edges.(Laplacian)
  5. The resulting image needs to be converted to 8-bit image for display.(convertScaleAbs)
  6. Show the result



#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>

using namespace cv;

int main( int argc, char** argv )
    Mat src, gray, dst, abs_dst;
    src = imread( "lena.jpg" );

    /// Remove noise by blurring with a Gaussian filter
    GaussianBlur( src, src, Size(3,3), 0, 0, BORDER_DEFAULT );
    cvtColor( src, gray, CV_RGB2GRAY );

    /// Apply Laplace function
    Laplacian( gray, dst, CV_16S, 3, 1, 0, BORDER_DEFAULT );
    convertScaleAbs( dst, abs_dst );
    imshow( "result", abs_dst );

    return 0;


  1. I an learning Im Proc with OpenCV. I have a basic question. Does Laplacian Edge detection takes longer time than the Canny or Sobel. If yes, Why?

    1. No. Laplacian operator takes same time that sobel operator takes. However, canny takes more time than others.

      In both Laplacian and Sobel, edge detection involves convolution with one kernel which is different in case of both. So they take almost same time.
      However, canny takes more time since it involves many steps for edge extraction.

  2. Your steps don't match your algorithm. There's no Hough Transform ;)

    1. Hi. Thanks for pointing out the mistake. I have modified the steps.

  3. Why would you blur the input image? It seems counter intuitive when trying to detect blur.

  4. This comment has been removed by the author.

  5. You have a mistake in your code. Not an error but a very basic mistake. Check shis code and you will find it: http://paste.ofcode.org/fEiy8E82mWPFLbKnbivy25

  6. where did we find the zero crossing

  7. โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร Sclub กับทางทีมงานของเราเพียงเท่านั้น
    สมัครสล็อตออนไลน์ >>> goldenslot
    สนใจร่วมลงทุนกับเรา สมัครเอเย่น Gclub คลิ๊กได้เลย

  8. เว็บไซต์คาสิโนออนไลน์ที่ได้คุณภาพอับดับ 1 ของประเทศ
    เป็นเว็บไซต์การพนันออนไลน์ที่มีคนมา Gclub Royal1688
    และยังมีหวยให้คุณได้เล่น สมัครหวยออนไลน์ ได้เลย
    สมัครสล็อตออนไลน์ได้ที่นี่ >>> Golden slot
    ร่วมลงทุนสมัครเอเย่น Gclubกับทีมงานของเราได้เลย

  9. How to fix this error?
    "Traceback (most recent call last):
    File "C:/Documents/Python Programs/Laplacian.py", line 7, in
    laplacian = cv2.Laplacian(img,cv2.CV_64F)
    cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\core\src\matrix.cpp:757: error: (-215:Assertion failed) dims <= 2 && step[0] > 0 in function 'cv::Mat::locateROI'"

  10. Searching and finding a company that offers Top Essay Writing Services can be a hefty task. Contact us, and we will serve you promptly and experience the best Nursing Research Paper Topic.