diff --git a/unmaintained_plugins/CellProfiler4_autoconverted/convertoutlinestoobjects.py b/active_plugins/convertoutlinestoobjects.py similarity index 86% rename from unmaintained_plugins/CellProfiler4_autoconverted/convertoutlinestoobjects.py rename to active_plugins/convertoutlinestoobjects.py index 3bc4325c..a5c7d2e9 100644 --- a/unmaintained_plugins/CellProfiler4_autoconverted/convertoutlinestoobjects.py +++ b/active_plugins/convertoutlinestoobjects.py @@ -66,6 +66,7 @@ def run(self, workspace): def convert_outlines_to_objects(outlines, diameter): + # turn everything into a label matrix labels = skimage.measure.label( outlines > 0, background=True, @@ -96,6 +97,15 @@ def convert_outlines_to_objects(outlines, diameter): background_indexes = numpy.unique(labels)[is_background] + # set the background to 0 labels[numpy.isin(labels, background_indexes)] = 0 + # reindex everything to be consecutive + indexes = numpy.unique(labels) + new_object_count = len(indexes) + max_label = numpy.max(labels) + label_indexes = numpy.zeros((max_label + 1,), int) + label_indexes[indexes] = numpy.arange(0, new_object_count) + labels = label_indexes[labels] + return labels