Canny edge giving different result
I have two programs
- extracts edges from a bunch of images in a loop at once
- 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
Please add the two code snippets and your outputs! Without that is not possible to figure out what you are doing wrong!
I have added the code used for detection. The blurring filters used are the same as well as the detection.
This seems to be happening when the image is brighter than normal. That's one thing I can observed.
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!
Please read this https://stackoverflow.com/help/mcve
are you using jpg images ? (lossy compression)
@LBerger I did rerun the code, now the program1 and the program2 results match up.
@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.@berak I'm using png images
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!