-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Lack of symmetry in find_boundaries? #738
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
Comments
I always knew this was a problem in skimage, but I'm not sure what the best solution is. The problem is that a boundary is really a subpixel property, so what we really should do is return an image twice the size of the original with the "between" pixels marked Anything that operates on the space of the original image is going to be an unsatisfactory approximation. @tonysyu (I think) went with an asymmetrical solution: it's finding every pixel where Hopefully that makes sense. Again, both solutions have issues. Not sure what the best way forward is. |
As an alternative, I suggest trying out import numpy as np
from skimage.measure import find_contours # New function, similar name
a = np.zeros((5, 5), dtype='bool')
a[2, 2] = True
# a is converted to double; the 0.5 tells it the level of the contour
contours = find_contours(a, 0.5) The result is a list of arrays containing contour vertices for all unconnected contours found for the passed [array([[ 2.5, 2. ],
[ 2. , 1.5],
[ 1.5, 2. ],
[ 2. , 2.5],
[ 2.5, 2. ]])] Which is correct by inspection for the given example. The 3D analogue of this is |
@jni I see the problem. I think you are on the right track when you use dilation/erosion. What about @JDWarner Thanks, this is an excellent suggestion for my particular use case right now, which is to calculate the Hausdorff distance between two boolean images ( |
@josteinbf, very nice for binary images, but won't work for n-labeled images, which In another note, I hadn't heard about Hausdorff distance, which is totally awesome, and indeed I've been meaning to add segmentation evaluation functions to scikit-image for quite some time... Would you like to start an |
@jni Agreed when it comes to your assessment of binary vs labelled. However, I'm starting to think that having boundaries two pixels wide actually makes sense. Consider this definition: "A pixel in a labelled image is a boundary pixel if it has one or neighbour pixels that has a different label than it
8000
self." This should be equivalent to the Summary of the above: Implement I really think skimage could use a Hausdorff distance function :) I don't have much time for skimage developments these days, and I should complete my phase unwrapping stuff before I file more PRs, so it may take a while before you see a PR on this. If you get inpatient, let me know, and I'll put the code in a gist or something for you to play with. It seems to be working fine, but needs tests and docs. |
I have Dice and Jaccard metrics I could be persuaded to upload... If you publish a working skeleton in a gist I'm sure we could help with fleshing that out into an addition! |
@JDWarner I would certainly appreciate it if you could upload the code for those two metrics, too! A gist right away would be great; I'm struggling with a "measure quality of segmentation" problem at work at the moment (hence the Hausdorff implementation), and more metrics would be great. Let me see if I can't find time for a Hausdorff PR over the next few days. If not, a gist is coming. I don't want to dump this on anyone else before I'm sure that's the only way to do it. |
By the way, are we sure that metrics such as these belong in the |
Generally these comparisons are done between segmented or masked images, which presumably may have had previous work done by That said, if we had a more robust set of them I could see the case for moving similarity metrics over to Here's a Gist for the Dice coefficient, and here's a Gist for the Jaccard coefficient. Only the Jaccard coefficient is a true metric; the Dice coefficient does not satisfy the triangle inequality. They both are defined on the range [0, 1] but the Jaccard metric is generally more difficult to satisfy. |
Either I have implementations of the variation of information and Rand index in gala. (More precisely in evaluate.py). Both work with n-dimensional images. |
Sounds to me like we have a few metrics; I think I will submit the first Hausdorff to |
I'm trying to use the find_boundaries function, and to figure out what output to expect, I tested it on an array with only a single pixel being
True
and the rest beingFalse
:The output was the following:
I was surprised by this output, as it seems to me that it is less symmetric than it ought to be. I was expecting either just a single pixel being
True
, or perhaps a 2x2 block beingTrue
. I decided to test the symmetry a bit further by finding the boundary of the same array after flipping it:The output was
I'm not sure if this is a bug, but it may well be. The docs could certainly be improved, though, as I cannot understand why the result is what it is.
Can anyone please help me clarify what to expect here?
The text was updated successfully, but these errors were encountered: