Skip to content

Commit 2edf7e2

Browse files
committed
handle input of pre-objects with count 0
1 parent 4581206 commit 2edf7e2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

active_plugins/enforceobjectsonetoone.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,18 @@ def run(self, workspace):
163163
workspace.display_data.statistics = []
164164

165165
pre_primary = workspace.object_set.get_objects(self.x_name.value)
166-
167166
pre_primary_seg = pre_primary.segmented
168167

169168
pre_secondary = workspace.object_set.get_objects(self.y_name.value)
170-
171169
pre_secondary_seg = pre_secondary.segmented
172170

173-
primary_seg = self.enforce_unique(pre_primary_seg, pre_secondary_seg, erode_excess=True)
174-
175-
secondary_seg = self.enforce_unique(pre_secondary_seg, primary_seg)
171+
if pre_secondary.count == 0:
172+
secondary_seg = primary_seg = pre_primary_seg
173+
elif pre_primary.count == 0:
174+
primary_seg = secondary_seg = pre_secondary_seg
175+
else:
176+
primary_seg = self.enforce_unique(pre_primary_seg, pre_secondary_seg, erode_excess=True)
177+
secondary_seg = self.enforce_unique(pre_secondary_seg, primary_seg)
176178

177179
if not numpy.array_equal(numpy.unique(primary_seg),numpy.unique(secondary_seg)):
178180
raise RuntimeError(f"Something is wrong, there are {numpy.unique(primary_seg).shape[0]-1} primary objects (highest value: {numpy.unique(primary_seg)[-1]}) and {numpy.unique(secondary_seg).shape[0]-1} secondary objects (highest value: {numpy.unique(secondary_seg)[-1]})")

0 commit comments

Comments
 (0)