@@ -226,26 +226,30 @@ def remove_marked(image,markers):
226
226
return image * (marked == 0 )
227
227
228
228
@checks (SEGMENTATION ,SEGMENTATION )
229
- def correspondences (labels1 ,labels2 ):
229
+ def correspondences (labels1 ,labels2 , return_counts = True ):
230
230
"""Given two labeled images, compute an array giving the correspondences
231
231
between labels in the two images (as tuples of label in `labels1`,
232
232
label in `labels2`, and pixel count)."""
233
233
q = 100000
234
234
assert amin (labels1 )>= 0 and amin (labels2 )>= 0
235
235
assert amax (labels2 )< q
236
236
combo = labels1 * q + labels2
237
- result , counts = unique (combo , return_counts = True )
238
- result = array ([result // q ,result % q ,counts ])
237
+ result = unique (combo , return_counts = return_counts )
238
+ if return_counts :
239
+ result , counts = result
240
+ result = array ([result // q ,result % q ,counts ])
241
+ else :
242
+ result = array ([result // q ,result % q ])
239
243
return result
240
244
241
245
@checks (ABINARY2 ,SEGMENTATION )
242
246
def propagate_labels_simple (regions ,labels ):
243
247
"""Given an image and a set of labels, apply the labels
244
248
to all the connected components in the image that overlap a label."""
245
249
rlabels ,_ = label (regions )
246
- cors = correspondences (rlabels ,labels )
250
+ cors = correspondences (rlabels ,labels , False )
247
251
outputs = zeros (amax (rlabels )+ 1 ,'i' )
248
- for o ,i , _ in cors .T : outputs [o ] = i
252
+ for o ,i in cors .T : outputs [o ] = i
249
253
outputs [0 ] = 0
250
254
return outputs [rlabels ]
251
255
@@ -275,10 +279,10 @@ def propagate_labels(image,labels,conflict=0):
275
279
to all the connected components in the image that overlap a label.
276
280
Assign the value `conflict` to any components that have a conflict."""
277
281
rlabels ,_ = label (image )
278
- cors = correspondences (rlabels ,labels )
282
+ cors = correspondences (rlabels ,labels , False )
279
283
outputs = zeros (amax (rlabels )+ 1 ,'i' )
280
284
oops = - (1 << 30 )
281
- for o ,i , _ in cors .T :
285
+ for o ,i in cors .T :
282
286
if outputs [o ]!= 0 : outputs [o ] = oops
283
287
else : outputs [o ] = i
284
288
outputs [outputs == oops ] = conflict
0 commit comments