# ddepth parameter of the Laplacian filter

Here how I used to implement the Laplacian filter over my images:

 int scale = 1;
int delta = 0;
int ddepth = CV_16S;
int kernel_size = 3;
Mat res,imgGrayScale, imgGrayScaleGaussianBlurred;
cv::cvtColor(sourceImage, imgGrayScale, CV_RGB2GRAY);
imwrite("Im3downsampledimgGrayScale.png",imgGrayScale);
GaussianBlur( imgGrayScale, imgGrayScaleGaussianBlurred, Size(3,3), 0, 0, BORDER_DEFAULT );
imwrite("Im3downsampledimgBlurred.png",imgGrayScaleGaussianBlurred);
//Laplace
Laplacian( imgGrayScale, res, ddepth, kernel_size, scale, delta, BORDER_DEFAULT );
convertScaleAbs( res, result);


Can someone clarify what it does the "ddepth" parameter? Why it states in the documentation that should be CV_16S to avoid overflow? What does it mean this?

ddepth: Depth of the destination image. Since our input is CV_8U we define ddepth = CV_16S to avoid overflow

edit retag close merge delete

Sort by » oldest newest most voted

Let imagine Laplacian filter 3x3 kernel:

Let consider pixel with the following neighborhood:

1   1    1
1   255 1
1   1    1


After applying Laplacian filter pixel value should be equal -4*255 + 4 = -1016

If we continue use CV_8U type (unsigned char 0-255) we can't save this value. So we should change type to CV_16S (signed short int, –32,768 to 32,767)

more

Ok cool, so convertScaleAbs( res, result); converts each channel of the image to 8bit right? if not, how can I display the image result of the laplacian?

( 2015-01-19 03:37:49 -0600 )edit

Yes, it converts each channel to 8 bit.

( 2015-01-20 01:29:33 -0600 )edit

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2015-01-14 10:42:51 -0600

Seen: 25,186 times

Last updated: Jan 14 '15