Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Getting Canny to provide good results

Hello everyone, I am working on edge detection. I have been developing under ImageJ for a while and converted most of my code to OpenCV in the past few weeks. Most of this process happened painlessly, however I cannot get the Canny filter to work in OpenCV as it did in ImageJ.

Here is an example of image I work with (left), results with ImageJ (middle) and results with OpenCV (right). Hysteresis thresholds were set about the same.

image description

I have been searching for why such differences in results occur. I found that for ImageJ, the Canny algorithm uses a convolution mask which combines a gaussian function and a sobel kernel, thus computing gradients on a smoothed image.

OpenCV's Canny only uses a Sobel Kernel I believe, but since the Gaussian and Sobel are linear, I should get the same results by gaussing the original image beforehand and then applying Canny. But it is not the case.

One main difference is that ImageJ's kernel size for its convolution mask is 16 (and not modifiable), while OpenCv's one is 3,5 or 7 (results are shown for kernel 7), and this parameter seems to have a big impact on results.

Do you think it is the reason why I have so different results ? If so, how can I get around it ?

Thanks.

PS : Things I tried : playing with hysteresis thresholds, morphological operations post Canny, but I would like as good results as ImageJ

Getting Canny to provide good results

Hello everyone, I am working on edge detection. I have been developing under ImageJ for a while and converted most of my code to OpenCV in the past few weeks. Most of this process happened painlessly, however I cannot get the Canny filter to work in OpenCV as it did in ImageJ.

Here is an example of image I work with (left), results with ImageJ (middle) and results with OpenCV (right). Hysteresis thresholds were set about the same.

image description

I have been searching for why such differences in results occur. I found that for ImageJ, the Canny algorithm uses a convolution mask which combines a gaussian function and a sobel kernel, thus computing gradients on a smoothed image.

OpenCV's Canny only uses a Sobel Kernel I believe, but since the Gaussian and Sobel are linear, I should get the same results by gaussing the original image beforehand and then applying Canny. But it is not the case.

One main difference is that ImageJ's kernel size for its convolution mask is 16 (and not modifiable), while OpenCv's one is 3,5 or 7 (results are shown for kernel 7), and this parameter seems to have a big impact on results.

Do you think it is the reason why I have so different results ? If so, how can I get around it ?

Thanks.

PS : Things I tried : playing with hysteresis thresholds, morphological operations post Canny, but I would like as good results as ImageJ