Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

endless loop in canny edge detector #16

Closed
lucaro opened this issue Jan 13, 2014 · 3 comments
Closed

endless loop in canny edge detector #16

lucaro opened this issue Jan 13, 2014 · 3 comments

Comments

@lucaro
Copy link

lucaro commented Jan 13, 2014

Hi Peter

When I feed an Image into the canny edge detector which is solid black, the process method does not seem to ever return.

example:
BufferedImage solidBlack = ImageIO.read(new File("black.png"); //loads solid black image
ImageUInt8 gray = ConvertBufferedImage.convertFrom(solidBlack , (ImageUInt8) null);
CannyEdge<ImageUInt8, ImageSInt16> canny = FactoryEdgeDetectors.canny(2, false, true, ImageUInt8.class, ImageSInt16.class);
float THRESHOLD_LOW = 0.075f, THRESHOLD_HIGH = 0.3f;
canny.process(gray, THRESHOLD_LOW, THRESHOLD_HIGH, gray); //<-- never returns

I solved this with a workaround which checks first if the image is entirely black:
public static boolean isSolidBlack(ImageUInt8 img){
for(byte b : img.data){
if(b != 0){
return false;
}
}
return true;
}

@lessthanoptimal
Copy link
Owner

That's a bug and it's fixed. Canny can't handle the situation when the threshold is zero and the image has no intensity. The adaptive canny now takes that in account and handles it correctly. Updated unit tests and a few other changes. Let me know if this works for you.

2e30cc8

@lessthanoptimal
Copy link
Owner

Actually use this commit instead. It fixes the real bug and provides more consistent behavior. In this situation the entire image will be one massive edge because the threshold (computed using the relative threshold) is set to zero.

33e2529

@lucaro
Copy link
Author

lucaro commented Jan 14, 2014

Thanks a lot for the fast response

@lucaro lucaro closed this as completed Jan 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants