-
Notifications
You must be signed in to change notification settings - Fork 2
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
Implement basic label matching #2
Conversation
for functions see biapolutils.label.match_labels and match_labels_stack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Johannes @jo-mueller ,
great to see this evolving! I just put some comments in the code, mostly asking for better variable naming and some API changes.
Let me know if I can help.
Best,
Robert
def intersection_over_union(masks_true, masks_pred): | ||
""" intersection over union of all mask pairs | ||
|
||
From: https://github.com/MouseLand/cellpose/blob/6fddd4da98219195a2d71041fb0e47cc69a4b3a6/cellpose/metrics.py#L165 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please make a folder "/license_thirdparty" and put the cellpose license in there? Furthermore, a acknowledgement statment in the readme would be kind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
import numpy as np | ||
|
||
def label_overlap_matrix(x, y): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please rename the variables x
and y
? I suggest something more descriptive like label_image_x
and label_image_y
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in ab725ce
biapolutils/label/_match_labels.py
Outdated
from skimage import io | ||
import os | ||
|
||
def match_labels_stack(stack, method='iou', **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A method should not be passed as string. Please pass the method as method. See this notebook for an example. https://github.com/BiAPoL/Bio-image_Analysis_with_Python/blob/main/python_basics/12_functional_parameters.ipynb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in 92167c9 - Thanks for the source!
biapolutils/label/_match_labels.py
Outdated
|
||
return stack | ||
|
||
def match_labels(imageA, imageB, method='iou', **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rename imageA
and imageB
to something more descriptive. Please also be consistent with the naming above, e.g. label_image_x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also don't pass a method as string like explained above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional arguments changed in 92167c9
import tqdm | ||
from ._intersection_over_union import intersection_over_union | ||
|
||
def stitch3Dto3D(masks, method='iou', **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename masks
and pass a method, See comments above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sticht3Dto3D was removed in 31c66f1 - the function is covered by match_labels_stack and works in 2D->3D and 3D->4D.
import matplotlib.pyplot as plt | ||
|
||
if __name__=='__main__': | ||
path = r'D:\Documents\Promotion\Projects\2021_napari_quantify_segmentation\data\set1_unmatched' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please replace absolute paths on your computer with relative paths so that this works on all computers. Also please upload the example data. If the dataset is big, I suggest to use a smaller one. I'm personally big fan of example images with size 5x5 pixels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a data
submodule with example images that are shipped with biapolutils (ba3c4fb). I couldn't find a license for blobs.gif from ImageJ (source: https://imagej.nih.gov/ij/images/)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blobs is part of ImageJ und thus, public domain :-)
https://imagej.nih.gov/ij/disclaimer.html
setup.cfg
Outdated
@@ -31,4 +31,5 @@ install_requires = | |||
numpy | |||
scikit-image | |||
scikit-learn | |||
tqdm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can see, tqdm is not used in your code. Do we really need this dependency? Please also check the other dependencies and reduce them to the absolute minimum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in 3b036f4. I do think, however, that some sort of progress feedback could be valuable in some functions.
Also, could you please make individual github issues out of that list? We might otherwise forget to implement that stuff. Thanks! |
…iAPoL/biapol-utilities into implement-basic-label-matching
redundant because implemented in match_labels_stack
Some more suggestions:
|
added the ImageJ blobs example to biapolutils
use shipped example data for demonstration
@@ -0,0 +1,21 @@ | |||
"""Biapol utilities for Python | |||
``biapol-utilities`` (a.k.a. ``biapolutils``) is a collection of utility functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
``biapol-utilities`` (a.k.a. ``biapolutils``) is a collection of utility functions | |
``biapol-utilities`` (a.k.a. ``biapol_utilitiess``) is a collection of utility functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in 35303e1
biapol_utilities/__init__.py
Outdated
Label handling and evaluation | ||
surface | ||
Manage surfaces and point representations | ||
util |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please write things out, e.g. "utilities" in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in df73737
import matplotlib.pyplot as plt | ||
|
||
if __name__=='__main__': | ||
path = r'D:\Documents\Promotion\Projects\2021_napari_quantify_segmentation\data\set1_unmatched' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blobs is part of ImageJ und thus, public domain :-)
https://imagej.nih.gov/ij/disclaimer.html
no functions there (yet)
Hey Johannes @jo-mueller , for the future: You should not merge your own pull-request without proper review. Let others be part of the process ;-) Best, |
I implemented functions to match labels based on intersection over union (cpu) that work in 2D and 3D based on cellpose (source)
The functions are biapolutils.label.match_labels and match_labels_stack that rely on label.label_overlap_matrix and label.intersection_over_union.
A basic notebook for label-matching is available.
future versions of these functions should include