Canny edge giving different result

asked 2017-11-29 23:56:16 -0600

Santhosh1 gravatar image

updated 2017-11-30 00:55:08 -0600

I have two programs

  1. extracts edges from a bunch of images in a loop at once
  2. extracts edge from a single image

Using two blurring filter of same kernel size in both the programs.

then

ret, thresh = cv2.threshold(e_img, 240, 255, cv2.THRESH_BINARY)
im2, contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)

then get the count and save the extracted image.

The preprocessing steps of blurring the image and thresholding the Canny Edge are same.

The images used by the two programs are same haven't been altered or enhanced in any way.

For one of the images Program 1 giving less number of contours detected but when running the same image in the Program 2, I can see more contours visually as well as in the count of the edges detected.

In short Program 1 is giving less number of contours than Program 2

Any idea what is happening here?

All the parameters for extraction are same but the detection difference so much.

This is one of the random pictures of potatoes i found online as an example of the output The left most when run through program 1, the middle one when extracted through program 2 then the right most is the origin image

We can see edges detected have changed, one is detecting the border(program2) where as other(program1) can't

image description

edit retag flag offensive close merge delete

Comments

1

Please add the two code snippets and your outputs! Without that is not possible to figure out what you are doing wrong!

Balaji R gravatar imageBalaji R ( 2017-11-30 00:13:26 -0600 )edit

I have added the code used for detection. The blurring filters used are the same as well as the detection.

Santhosh1 gravatar imageSanthosh1 ( 2017-11-30 00:51:11 -0600 )edit

This seems to be happening when the image is brighter than normal. That's one thing I can observed.

Santhosh1 gravatar imageSanthosh1 ( 2017-11-30 00:58:35 -0600 )edit

If you want some helps you must give a full program and images. if somebody else can reproduce issue then you can post an issue. It is really difficult to guess what happens because it should not happen!

LBerger gravatar imageLBerger ( 2017-11-30 02:01:20 -0600 )edit
1
Balaji R gravatar imageBalaji R ( 2017-11-30 02:27:00 -0600 )edit
1

are you using jpg images ? (lossy compression)

berak gravatar imageberak ( 2017-11-30 07:51:49 -0600 )edit

@LBerger I did rerun the code, now the program1 and the program2 results match up.

Santhosh1 gravatar imageSanthosh1 ( 2017-11-30 23:50:37 -0600 )edit

@Balaji R The code is small Apply Median Filter with kernel size 9 and then Gaussian with kernel size 5, then extract the Canny Edges with threshold which is my case is good between 1-130. Same code I use in both the programs above.

Santhosh1 gravatar imageSanthosh1 ( 2017-11-30 23:53:45 -0600 )edit
1

@berak I'm using png images

Santhosh1 gravatar imageSanthosh1 ( 2017-11-30 23:54:11 -0600 )edit

Same in that case, png has a compression rate and decompression of the image can result in small changes in multiple loops. However I am still convinced that your changes are due too different code structures... please add those!

StevenPuttemans gravatar imageStevenPuttemans ( 2017-12-01 08:04:52 -0600 )edit