@@ -335,6 +335,60 @@ public void testDifferentDimensions()
335335 assertTrue ( c .next ().isEmpty () );
336336 }
337337
338+ @ Test
339+ public void testDefaultLabelEntireMask ()
340+ {
341+ final MaskInterval m = createBox ( new long [] { 10 , 10 }, new long [] { 20 , 20 } );
342+ final Img < IntType > indexImg = ArrayImgs .ints ( 21 , 21 );
343+ final ImgLabeling < String , IntType > imgLabeling = new ImgLabeling <>( indexImg );
344+ final String defaultLabel = "default" ;
345+ Masks .addMasksToLabeling ( Collections .singletonList ( m ), imgLabeling , defaultLabel );
346+
347+ final Cursor < LabelingType < String > > c = imgLabeling .cursor ();
348+ while ( c .hasNext () )
349+ {
350+ final LabelingType < String > labels = c .next ();
351+ if ( m .test ( c ) )
352+ {
353+ assertTrue ( labels .contains ( defaultLabel ) );
354+ assertEquals ( 1 , labels .size () );
355+ }
356+ else
357+ assertTrue ( labels .isEmpty () );
358+ }
359+ }
360+
361+ @ Test
362+ public void testDefaultLabelPartialMask ()
363+ {
364+ final LabeledMaskInterval < String > labeledSphere = new LabeledMaskInterval <>( createSphere ( new long [] { 10 , 10 }, 5 ), "label" );
365+ final MaskInterval sphere = createSphere ( new long [] { 15 , 13 }, 4 );
366+ final MaskInterval or = labeledSphere .or ( sphere );
367+ final MaskInterval minus = sphere .minus ( labeledSphere );
368+ final String defaultLabel = "default" ;
369+ final Img < IntType > indexImg = ArrayImgs .ints ( 20 , 20 );
370+ final ImgLabeling < String , IntType > imgLabeling = new ImgLabeling <>( indexImg );
371+ Masks .addMasksToLabeling ( Collections .singletonList ( or ), imgLabeling , defaultLabel );
372+
373+ final Cursor < LabelingType < String > > c = imgLabeling .cursor ();
374+ while ( c .hasNext () )
375+ {
376+ final LabelingType < String > labels = c .next ();
377+ if ( labeledSphere .test ( c ) )
378+ {
379+ assertTrue ( labels .contains ( labeledSphere .getLabel () ) );
380+ assertEquals ( 1 , labels .size () );
381+ }
382+ else if ( minus .test ( c ) )
383+ {
384+ assertTrue ( labels .contains ( defaultLabel ) );
385+ assertEquals ( 1 , labels .size () );
386+ }
387+ else
388+ assertTrue ( labels .isEmpty () );
389+ }
390+ }
391+
338392 // -- Helper methods --
339393
340394 private static MaskInterval createBox ( final long [] min , final long [] max )
0 commit comments