Skip to content

Commit 46c0755

Browse files
authored
Merge pull request #275 from CellProfiler/update_objs_outlines
bugfix convertoutlinestoobjects
2 parents becdf09 + bf9f271 commit 46c0755

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

Lines changed: 10 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,15 @@ 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+
labels = label_indexes[labels]
110+
101111
return labels

0 commit comments

Comments
 (0)