Ask Your Question
2

Problem with Laplacian Filter

asked 2013-07-19 03:13:02 -0600

mary gravatar image

updated 2015-10-06 09:14:42 -0600

Hello, I use opencv for Android and I would like to use a Laplacian Filter for the 8-bit greyscale image so I use the follow code:

Bitmap image = BitmapFactory.decodeByteArray(im, 0, im.length);
int l=CvType.CV_8UC1;
Mat matImage = new Mat();               
Utils.bitmapToMat(image, matImage); 
Mat matImageGrey = new Mat();
Imgproc.cvtColor(matImage,matImageGrey, Imgproc.COLOR_BGR2GRAY);
Mat matImageGrey8bit = new Mat();
matImageGrey.convertTo(matImageGrey8bit, l);

Bitmap destImage;
destImage=Bitmap.createBitmap(image);
Mat dst2=new Mat();
Utils.bitmapToMat(destImage, dst2); 
Mat laplacianImage = new Mat();
dst2.convertTo(laplacianImage, l);

Imgproc.Laplacian(matImageGrey8bit, laplacianImage, '2');

The problem is that my image (laplacianImage) is too dark. I don't know image processing but I think that the third parameter of the Laplacian function can be the reason but if I try to change it from '2' to '1' I have an exception.

07-19 10:09:31.331: E/cv::error()(19796): OpenCV Error: The function/feature is not implemented        (Unsupported combination of source format (=0), and destination format (=1)) in cv::Ptr<cv::BaseFilter> cv::getLinearFilter(int, int, cv::InputArray, cv::Point, double, int), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/imgproc/src/filter.cpp, line 3192

The question is: Why does it produce this exception? Thank you!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
5

answered 2013-07-19 04:02:41 -0600

berak gravatar image

oh, you should give a number for ddepth, not a char !

Imgproc.Laplacian(matImageGrey8bit, laplacianImage, CvType.CV_8U);

totally amazing, that feeding '2' into it even worked ;)

('2' evaluates to 50, which is odd, so the least significant bits still evaluate to 0, while '1' evaluates to 49, so .. )

if your image is too dark, you probably need to play with the ksize,scale params

btw,

Mat matImageGrey = new Mat();
Imgproc.cvtColor(matImage,matImageGrey, Imgproc.COLOR_BGR2GRAY);
//Mat matImageGrey8bit = new Mat();         
//matImageGrey.convertTo(matImageGrey8bit, l);   // not needed, matImageGrey is already CvType.CV_8UC1
edit flag offensive delete link more

Comments

Thank you for your response! you're right! :)

mary gravatar imagemary ( 2013-07-19 04:58:45 -0600 )edit
1

Keep in mind the integer overflow issues when using Laplacian, especially when using CV_8U.

rwong gravatar imagerwong ( 2014-09-23 09:29:44 -0600 )edit

Question Tools

Stats

Asked: 2013-07-19 03:13:02 -0600

Seen: 4,069 times

Last updated: Jul 19 '13