Repository navigation
Conversation
jni
left a comment
There was a problem hiding this comment.
@seanbudd thanks for finally getting this done! There's a few changes to be made, and in addition to the small changes we need both tests and a gallery example.
I recommend looking at Ch5 from Elegant SciPy for some inspiration. (You should use an image from the gallery, though, such as coffee, rather than an external image.)
|
|
||
| return (are, precision, recall) | ||
|
|
||
| def compare_rand_by_threshold(im_true, im_test, npoints=None): |
There was a problem hiding this comment.
We probably want to adapt these names for scikit-image more specifically:
im_true -> image_reference
im_test -> image_test
npoints -> n_points
But actually, remove rand_by_threshold altogether. 😂
There was a problem hiding this comment.
I like pytorch convention: input_ and target.
There was a problem hiding this comment.
Another option is: image_pred, image_true.
There was a problem hiding this comment.
The convention in this file was im_true, im_test, is this different elsewhere in skimage code?
There was a problem hiding this comment.
Hmmm, I consider this among the consistency warts in the scikit-image API that I want to fix before 1.0. @soupault are you really suggesting a parameter name with a trailing underscore??? At any rate I still prefer "reference" to "target", with the latter being too machine learning-specific for my tastes. We are also already using 'reference' in register_translation, too.
| 'moments', | ||
| 'moments_central', | ||
| 'moments_coords', | ||
| 'moments_coords_central' |
There was a problem hiding this comment.
Whoa! That is, actually, a bug, and the fix has to be backported.
There was a problem hiding this comment.
should this be done via a different request?
There was a problem hiding this comment.
Here's the git blame results for reference, I'll prepare another PR.
There was a problem hiding this comment.
@seanbudd at scikit-image, we usually prefer not to throw our colleagues under the bus, except for mea culpas, =) or where the error is super-subtle and looking at the commit actually aids in understanding it. But, thanks for the reference. =)
There was a problem hiding this comment.
@jni oops! Was definitely not trying to throw anyone under the bus!
There was a problem hiding this comment.
👍
git blame is an unfortunate name for the command. Humorous at times, but on the whole a negative imho!
|
|
||
| return (are, precision, recall) | ||
|
|
||
| def compare_rand_by_threshold(im_true, im_test, npoints=None): |
There was a problem hiding this comment.
I like pytorch convention: input_ and target.
| ] | ||
|
|
||
| def compare_raw_edit_distance(im_true, im_test, size_threshold=1000): | ||
| """Compute the edit distance between two segmentations. |
There was a problem hiding this comment.
I think for metrics it is highly important to provide a comprehensive description and include the corresponding formula's.
There was a problem hiding this comment.
Yes I agree. Actually I'm not positive that this particular metric computation is correct, so I suggest we remove it for now.
There was a problem hiding this comment.
Having said that, for the other metrics, please provide references to papers or other implementations. They are mostly easy to find. =)
|
|
||
| return (are, precision, recall) | ||
|
|
||
| def compare_rand_by_threshold(im_true, im_test, npoints=None): |
There was a problem hiding this comment.
Another option is: image_pred, image_true.
| vi | ||
| """ | ||
| _, _, _ , hxgy, hygx, _, _ = vi_tables(im1, im2) | ||
| # false merges, false splits |
There was a problem hiding this comment.
Here you want to update the note to explain that this comment is true when image_1 is the test and image_2 is the reference (or vice versa, I'm not too sure right now. =P) I might even vote to change the argument names to be more prescriptive (image_test, image_reference), even though conceptually the VI is symmetric and this wouldn't make any practical difference. But it's better for newcomers to understand.
|
Hello @seanbudd! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2019-03-18 07:32:07 UTC |
Codecov Report
@@ Coverage Diff @@
## master #3354 +/- ##
=========================================
Coverage ? 86.74%
=========================================
Files ? 342
Lines ? 27588
Branches ? 0
=========================================
Hits ? 23932
Misses ? 3656
Partials ? 0
Continue to review full report at Codecov.
|
| 'compare_adapted_rand_error', | ||
| 'compare_raw_edit_distance', | ||
| 'compare_split_vi', | ||
| 'compare_vi', |
| compare_rand_by_threshold, | ||
| compare_raw_edit_distance, | ||
| compare_split_vi, | ||
| compare_vi) |
There was a problem hiding this comment.
(minor quibble: align with the open parenthesis at the top)
| Parameters | ||
| ---------- | ||
| im_true : ndarray | ||
| Ground-truth image. |
|
|
||
| Parameters | ||
| ---------- | ||
| im_true : ndarray |
|
|
||
| return (are, precision, recall) | ||
|
|
||
| def compare_variation_of_information(im1, im2, weights=np.ones(2)): |
There was a problem hiding this comment.
Let's go with im_true and im_test here also, for consistency. We can update the API later if we decide to go with e.g. reference, test.
Also, let's make weights a keyword-only argument.
| [1] Meila, M. (2007). Comparing clusterings - an information based | ||
| distance. Journal of Multivariate Analysis 98, 873-895. | ||
| """ | ||
| return np.dot(weights, compare_split_variation_of_information(im1, im2)) |
There was a problem hiding this comment.
Let's use Python 3 matmul syntax here: weights @ compare_split_variation_of_information()
| """ | ||
| return np.dot(weights, compare_split_variation_of_information(im1, im2)) | ||
|
|
||
| def compare_split_variation_of_information(im1, im2): |
| """ | ||
| _, _, _ , hxgy, hygx, _, _ = _vi_tables(im1, im2) | ||
| # false merges, false splits | ||
| return np.array([hygx.sum(), hxgy.sum()]) |
There was a problem hiding this comment.
Depending on the order of im_true and im_test, you might need to reorder "false merges, false splits". You can test this with the simple "images": [1, 1], [1, 2]. (The second one is "split" relative to the first. So depending on which is im_true, you have either a false split and no false merges, or a false merge and no false splits.
| return out | ||
|
|
||
| def _vi_tables(im1, im2): | ||
| """Return probability tables used for calculating VI. |
There was a problem hiding this comment.
I've made some improvements to the code in this function in Ch5 of Elegant SciPy. Can you copy over those improvements as well?
|
I'm currently working on the gallery example, should it be under the segmentation section? |
|
|
||
| See Also | ||
| -------- | ||
| vi |
| def test_vi(): | ||
| im_true = np.array([1, 2, 3, 4]) | ||
| im_test = np.array([1, 1, 8, 8]) | ||
| assert_equal(compare_variation_of_information(im_true, im_test), -1) |
There was a problem hiding this comment.
I'm not sure what's happening here, but VI is always non-negative.
There was a problem hiding this comment.
both vi and split vi are returning negative numbers every time. I'm not sure whats going on either
|
|
||
| segments_slic = slic(img, n_segments=100, compactness=10, sigma=1) | ||
| gradient = sobel(rgb2gray(img)) | ||
| segments_watershed = watershed(gradient, markers=2, compactness=0.001) |
There was a problem hiding this comment.
There's a couple of coins examples that get basically a perfect segmentation. I suggest the following approach for this example:
- find the example where every coin is perfectly segmented. Run the same code here and call the result
im_true. - find the compact watershed example where all the coins are vastly oversegmented. Call that
im_test1. - find another example where most of the coins are properly segmented but a few are background, or merged. Call that
im_test2. - find a final example where most of the coins are merged with the background. (Or maybe even an example where all the coins are merged with the background, ie
np.ones(coins.shape, dtype=int). But better if one or two coins are properly segmented. Call thatim_test3.
Then, plot the following things:
- a scatter plot, with a legend, or text labels, plotting the
split_vi[0]againstsplit_vi[1](or vice versa. The splits should be on the vertical axis, so that the compact watershed example is on the top-left corner, and thenp.onesexample is on the bottom right corner. See the section on VI in my PLoS ONE 2013 paper for what this plot looks like.) - another scatter plot, with a legend, or text labels, plotting the precision against the recall for the three points.
- all four segmentations. (true, and the three tests.)
This all would fit quite nicely in a 2 row x 3 column figure.
Hopefully that's clear enough!
|
Ok, I've sent a preliminary push. From what I can tell the following needs to be fixed (WIP)
|
| ax[5].set_title('Morphological GAC') | ||
| ax[5].set_axis_off() | ||
|
|
||
| plt.tight_layout() |
There was a problem hiding this comment.
It is so weird that this isn't working correctly at all here. We'll need to figure this out also...
This fixes layout issues and removes unnecessary code.
|
Thanks for this addition @seanbudd! I'm looking forward to seeing it develop. |
|
any updates here? |
|
Superseded by #4025 |
|
Finally in, @seanbudd! =) Thanks for your work here! =) |
|
no problem @jni glad it eventually made it in!! |

Description
As requested in this issue we have merged relevant code from gala.evaluate under the BSD license.
Added the following segmentation metrics:
Checklist
./doc/examples(new features only)./benchmarks, if your changes aren't covered by anexisting benchmark
[For detailed information on these and other aspects see scikit-image contribution guidelines]
References
closes issue #2345
For reviewers
(Don't remove the checklist below.)
later.
__init__.py.doc/release/release_dev.rst.@meeseeksdev backport to v0.14.x