Ask Your Question
1

ddepth parameter of the Laplacian filter

asked 2015-01-14 10:42:51 -0500

maystroh gravatar image

updated 2016-01-12 08:14:46 -0500

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 flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
3

answered 2015-01-14 13:22:49 -0500

AlexanderShishkov gravatar image

Let imagine Laplacian filter 3x3 kernel: image description

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)

edit flag offensive delete link more

Comments

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?

maystroh gravatar imagemaystroh ( 2015-01-19 03:37:49 -0500 )edit

Yes, it converts each channel to 8 bit.

AlexanderShishkov gravatar imageAlexanderShishkov ( 2015-01-20 01:29:33 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 21,112 times

Last updated: Jan 14 '15