Skip to content

Commit aaaf10a

Browse files
bugfix convertoutlinestoobjects
Co-authored-by: bethac07 <bcimini@broadinstitute.org>
1 parent 4581206 commit aaaf10a

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

unmaintained_plugins/CellProfiler4_autoconverted/convertoutlinestoobjects.py renamed to active_plugins/convertoutlinestoobjects.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def run(self, workspace):
6666

6767

6868
def convert_outlines_to_objects(outlines, diameter):
69+
# turn everything into a label matrix
6970
labels = skimage.measure.label(
7071
outlines > 0,
7172
background=True,
@@ -96,6 +97,17 @@ def convert_outlines_to_objects(outlines, diameter):
9697

9798
background_indexes = numpy.unique(labels)[is_background]
9899

100+
# set the background to 0
99101
labels[numpy.isin(labels, background_indexes)] = 0
100102

103+
# reindex everything to be consecutive
104+
indexes = numpy.unique(labels)
105+
new_object_count = len(indexes)
106+
max_label = numpy.max(labels)
107+
label_indexes = numpy.zeros((max_label + 1,), int)
108+
label_indexes[indexes] = numpy.arange(0, new_object_count)
109+
110+
#target_labels[target_labels > max_label] = 0
111+
labels = label_indexes[labels]
112+
101113
return labels

0 commit comments

Comments
 (0)