-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add relabel_sequential()
for relabeling label data after map_raster()
#664
Add relabel_sequential()
for relabeling label data after map_raster()
#664
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #664 +/- ##
==========================================
+ Coverage 91.80% 91.83% +0.02%
==========================================
Files 45 45
Lines 6959 7002 +43
==========================================
+ Hits 6389 6430 +41
- Misses 570 572 +2
|
Now also added helper function I think the PR is ready for review now. |
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 @ArneDefauw , thanks a lot, super useful. I went back to this function in squidpy, and remember that we also did an additional step to harmonize the labels with dask image
from dask_image.ndmeasure._utils._label import (
connected_components_delayed,
label_adjacency_graph,
relabel_blocks,
)
# max because labels are not continuous (and won't be continuous)
label_groups = label_adjacency_graph(img, None, img.max())
new_labeling = connected_components_delayed(label_groups)
relabeled = relabel_blocks(img, new_labeling)
any reason for leaving this out? Otherwise for me it is good to go!
Hi @giovp , thanks for the review! Yes, I did not include the step to harmonize the labels across chunks due to some issues I observed when cell density is high, see also my previous comments. I make it a little bit more concrete with an example: So this is map_raster on a labels layer without harmonizing labels:
Then without using the harmonizing of labels I get: and with harmonizing of the labels using
I get: ![]() Which is not great, cells on the boundary of the chunks are merged together. A solution for this, is using this approach: But I do not know if you want this to be included in this PR, see also comment of @LucaMarconato #597 (comment). |
hi @ArneDefauw , sorry for late reply. I took a look at it's a nice approach I think, and I wonder if it should be included already here. Meaning, I am not sure how useful it is the output of relabelling without the across-block label harmonization. Yes, relabelling fix one step of the chunked segmentation, but the result is not really actionable/useful right? Or am I missing something? also @LucaMarconato wdyt? you can take a look at the output of the excellent post from @ArneDefauw before to understand visually what is the problem |
Yes, indeed, if you do not know how to do the across-block label harmonization, the result will not be very useful. On the other hand, there are probably many ways to do it. |
@ArneDefauw thanks for the PR and apologies for taking some time to get to it. After discussing with @LucaMarconato and @berombau we decided to put the label block harmonization in |
Co-authored-by: Wouter-Michiel Vierdag <w-mv@hotmail.com>
for more information, see https://pre-commit.ci
Hi @melonora , that makes sense, thanks for having a look at the PR! |
…/spatialdata into map_raster_relabeling
I adjusted the error message a tiny bit. While the function is private, it is called by public API. A less experienced programmer might not know about bit shift. |
Also made |
…/spatialdata into map_raster_relabeling
for more information, see https://pre-commit.ci
Thanks @ArneDefauw for the PR and @melonora for addressing the review comments. We are good to merge! |
relabel_sequential()
for relabeling label data after map_raster()
Follow up PR for #588, see discussion #597 for relabeling in case output data is a labels layer (i.e.
dims
does not containc
) via use of a bit shift.