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

Resolves problem of incorrect handing of NaN values #19

Merged
merged 1 commit into from
Dec 17, 2020

Conversation

zygmuntszpak
Copy link
Member

The Gaussian filtering step associated with the Canny edge detector used KernelFactors.IIRGaussian((σ,σ)) which does not leave the NaN values untouched but returns what seem to be spurious values in the NaN region. Consequently, when one computes the gradient one obtains a gradient response in those regions, which in turns cause canny to detect edges there as well. I address this issue by swapping to a KernelFactors.gaussian((σ,σ)) implementation. This should, in principle, yield a more accurate result. In practice, it means that the choice of σ had greater influence on the detected edges (the algorithm becomes more sensitive to the choice of that parameter). This meant that I had to rejigger some of the reference and test parameters in the test suite.

out, offsets = detect_subpixel_edges(img)
@test_reference "References/circle_edge.png" Gray.(detect_edges(img)) by=edge_detection_equality()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to remove circle_edge.png?

FYI, one way to quickly rebuild all the references is to remove the whole References folder.

Copy link
Member Author

@zygmuntszpak zygmuntszpak Dec 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this particular test we unfortunately need to remove it. The issue is that by using the KernelFactors.gaussian() instead of KernelFactors.IIRGaussian() the resulting image is different in a subtle way. The image has fewer unique intensity values. This subtle changes messes up the implicit threshold that is associated with the "Default Values" of low = Percentile(20) and high = Percentile(80). Whereas these percentiles gave the correct result and were good default values for this particular edge image when we used the IIRGaussian filter, they are a poor choice for this particular edge image when using the KernelFactors.gaussian() filters. A suitable threshold for this image would now be low = Percentile(75) and high = Percentile(80). The trouble is that this test is specifically meant to execute the API for the default values. Hence, I decided to go with a different image altogether because it doesn't make sense to change the default values to low = Percentile(75) and high = Percentile(80) in the general case.

Copy link
Member

@johnnychen94 johnnychen94 Dec 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I didn't notice this circle_edge.png is used in L108. I was thinking of whether this file can be removed.

BTW, it seems that you've accidentally committed two cameraman_edge.png files.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might just add that this was a very annoying and perplexing discovery. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and yet some bad luck in the nightly version :(

@zygmuntszpak zygmuntszpak force-pushed the fix_gaussian branch 2 times, most recently from 9dd750e to 82fe716 Compare December 17, 2020 06:48
The Gaussian filtering step associated with the Canny edge detector used  `KernelFactors.IIRGaussian((σ,σ))` which  does not leave the NaN values untouched but returns what seem to be spurious values in the NaN region. Consequently, when one computes the gradient one obtains a gradient response in those regions, which in turns cause canny to detect edges there as well. I address this issue by swapping to a `KernelFactors.gaussian((σ,σ))` implementation. This should, in principle, yield a more accurate results. In practice, it means that the choice of `σ` had greater influence on the detected edges (the algorithm becomes more sensitive to the choice of that parameter). This meant that I had to rejigger some of the reference and test parameters in the test suite.
@zygmuntszpak zygmuntszpak merged commit af7594f into master Dec 17, 2020
@zygmuntszpak zygmuntszpak deleted the fix_gaussian branch December 17, 2020 10:17
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

Successfully merging this pull request may close these issues.

2 participants