Ask Your Question

Is this a bug or not about filter2D?

asked 2012-12-05 04:15:39 -0600

wuling gravatar image

updated 2013-03-18 10:06:19 -0600

Guanta gravatar image

image description

Hi all: Above pic is the orginal picture. I tried some kernels to check filter2D. For some kernels i get right result, sometimes not. So I am confused that the code is wrong, or that there are some bugs in filter2D. The code is here:

float m[] = {-1.0, -1.0, -1.0,
-1.0, 10.0, -1.0,
-1.0, -1.0, -1.0 };
cv::Mat kernel=cv::Mat(3,3,CV_32F,m);
filter2D(src, dst,-1,kernel);

But I get:

image description

This is the wrong pic. I ever use imagj & ni vision to check result. The correct pic should be like

image description

What to do? I want to get correct image!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2012-12-05 06:08:48 -0600

venky gravatar image

Hi, It looks quite similar to me the final response between the two. Might be the values are scaled or normalized in the output in one case and the other one is saturated. Check the output values out, and try to normalize it by min and max value in the image and then compare the two results. Thanks Venky

edit flag offensive delete link more


Dear venky: i try scaled or normalized but i get the other uncorrect image.

wuling gravatar imagewuling ( 2012-12-05 06:10:57 -0600 )edit

I hope the image and ni vision toolbox does not do any other tricks to get a better result. I am also not sure if you have the same kernal for opencv and imagej and ni vision, So it will be very difficult for me to comment. I have used filter 2D and I got the same response when i cross checked with Matlab.

venky gravatar imagevenky ( 2012-12-05 06:19:22 -0600 )edit

If i add cv::convertScaleAbs(dst,dst,1.0,0.0); then i get the other image. I ever use Aforge -> ilab to chek again. All are the same, except opencv convolution.

wuling gravatar imagewuling ( 2012-12-05 06:41:09 -0600 )edit

how does the filter2d algorithm work? The OpenCV documentation does not match my results. gravatar image[email protected] ( 2012-12-20 16:08:08 -0600 )edit

I thinks filter2D is matlab type Convolution , in fact is Correlation. you can ref : "Correlation and Convolution " and opencv filter2d:

There are some different.

wuling gravatar imagewuling ( 2013-03-18 11:34:52 -0600 )edit

answered 2013-03-18 07:40:06 -0600

wuling gravatar image
edit flag offensive delete link more

Question Tools


Asked: 2012-12-05 04:15:39 -0600

Seen: 1,468 times

Last updated: Mar 18 '13