When exported label map is added to 3D ROI Manager, overlapping areas are counted as new labels
Hi, Firstly, thank you for this resource, it is working really well for me. I am using it to generate ground-truth images for use with the StarDist Segmentation, and it is easy to use and has great functionality. I have come across a problem however, but I'm not sure if it is because I am doing something wrong.
I colour each nucleus in an image with a separate label, and some of my labels overlap in lab kit. In lab kit this is fine, the overlapping area belongs to both labels as it should. However when I export the label map into imageJ and add the image to the 3D Roi Manager, these overlapping areas are counted as new labels, which is not ideal. From 200 labels on lab kit, I have 258 in the Roi Manager. I'm worried that, as well as skewing the 3D Measure values, this may also be leading to errors in the training of my segmentation model with StarDist, if it too is erroneously attributing nuclear identity to these overlapping areas.
I was wondering how I could prevent this.
Thanks again, and look forward to hearing from you,
Michael Schwimmer
Hi, I noticed a solution from another user @maweigert (#31), involving the override checkbox. This seems to not make a difference if it was not checked during label drawing. Is there a way to achieve the same result after all the labels have been drawn, I would really like to not have to redraw a lot of labels!
Thankyou very much,
Michael
Hi @michaelschwimmer
Indeed, checking override is very important for generating stardist training data.
Is there a way to achieve the same result after all the labels have been drawn, I would really like to not have to redraw a lot of labels!
This is going to be hard in general. If the overlap only affects small regions of the annotations, you could try to filter the overlap regions and set them to one of the two adjacent regions. This can be done in python like so:
import numpy as np
from skimage import measure, segmentation
def fix_labels(lbl):
y = np.zeros_like(lbl)
for r in measure.regionprops(lbl):
outer = list(lbl[segmentation.find_boundaries(lbl==r.label, mode= "outer")])
outer_label = max(outer,key=outer.count)
y[lbl==r.label] = r.label if outer_label==0 else outer_label
return y
img = ... # load the 2D label image
img_fixed = fix_labels(img)
Which results in something like this:

Maybe this helps...
Martin
Hi @maweigert ,
Will this work for 3D images? Just noticing the img = # load the 2D label image.
Thank you very much!
Michael Schwimmer
Will this work for 3D images?
Yes