From 879d2eebbadde4270705e3ca7b004850787c65f4 Mon Sep 17 00:00:00 2001 From: Stefan Hahmann Date: Wed, 27 Sep 2023 14:28:23 +0200 Subject: [PATCH] Add offset 1 to label ids * This is needed, since all ids (i.e. spot ids, branch spot ids, track ids) in Mastodon are counted zero based and thus the label zero could not be differentiated from the background, which is also set to zero in the export --- .../segment/SegmentUsingEllipsoidsController.java | 9 ++++++--- .../segment/SegmentUsingEllipsoidsControllerTest.java | 11 +++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/mastodon/mamut/segment/SegmentUsingEllipsoidsController.java b/src/main/java/org/mastodon/mamut/segment/SegmentUsingEllipsoidsController.java index e6b6ba36a..8e10db5ea 100644 --- a/src/main/java/org/mastodon/mamut/segment/SegmentUsingEllipsoidsController.java +++ b/src/main/java/org/mastodon/mamut/segment/SegmentUsingEllipsoidsController.java @@ -48,6 +48,9 @@ public class SegmentUsingEllipsoidsController { + + public static final int LABEL_ID_OFFSET = 1; + private static final Logger logger = LoggerFactory.getLogger( MethodHandles.lookup().lookupClass() ); private final Model model; @@ -185,16 +188,16 @@ private int getLabelId( final Spot spot, final LabelOptions option ) switch ( option ) { case SPOT_ID: - return spot.getInternalPoolIndex(); + return spot.getInternalPoolIndex() + LABEL_ID_OFFSET; case BRANCH_SPOT_ID: BranchSpot ref = model.getBranchGraph().vertexRef(); int branchSpotId = model.getBranchGraph().getBranchVertex( spot, ref ).getInternalPoolIndex(); model.getBranchGraph().releaseRef( ref ); // NB: optional, but increases performance, when this method is called often - return branchSpotId; + return branchSpotId + LABEL_ID_OFFSET; case TRACK_ID: if ( trackIdProjection == null ) trackIdProjection = getTrackIDFeatureProjection( context, model ); - return ( int ) trackIdProjection.value( spot ); + return ( int ) trackIdProjection.value( spot ) + LABEL_ID_OFFSET; default: throw new IllegalArgumentException( "Unknown label option: " + option ); } diff --git a/src/test/java/org/mastodon/mamut/segment/SegmentUsingEllipsoidsControllerTest.java b/src/test/java/org/mastodon/mamut/segment/SegmentUsingEllipsoidsControllerTest.java index 94d5912a4..dd0669ad5 100644 --- a/src/test/java/org/mastodon/mamut/segment/SegmentUsingEllipsoidsControllerTest.java +++ b/src/test/java/org/mastodon/mamut/segment/SegmentUsingEllipsoidsControllerTest.java @@ -27,7 +27,6 @@ import java.util.List; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertThrows; public class SegmentUsingEllipsoidsControllerTest @@ -47,8 +46,7 @@ public void setUp() { model = new Model(); ModelGraph modelGraph = model.getGraph(); - modelGraph.addVertex(); // NB: dummy vertex with internal pool index 0 - spot = modelGraph.addVertex(); // NB: internal pool index is 1 + spot = modelGraph.addVertex(); ModelBranchGraph modelBranchGraph = model.getBranchGraph(); modelBranchGraph.graphRebuilt(); branchSpot = modelBranchGraph.getBranchVertex( spot, modelBranchGraph.vertexRef() ); @@ -78,9 +76,10 @@ public void testSaveEllipsoidSegmentationToFile() throws IOException SCIFIOImgPlus< IntType > imgTrack = getIntTypeSCIFIOImgPlus( imgOpener, outputTrack ); // check that the spot id / branchSpot id / track id is used as value in the center of the spot - assertEquals( spot.getInternalPoolIndex(), imgSpot.getAt( center ).get() ); - assertEquals( branchSpot.getInternalPoolIndex(), imgBranchSpot.getAt( center ).get() ); - assertEquals( 1, imgTrack.getAt( center ).get() ); + assertEquals( spot.getInternalPoolIndex() + SegmentUsingEllipsoidsController.LABEL_ID_OFFSET, imgSpot.getAt( center ).get() ); + assertEquals( + branchSpot.getInternalPoolIndex() + SegmentUsingEllipsoidsController.LABEL_ID_OFFSET, imgBranchSpot.getAt( center ).get() ); + assertEquals( SegmentUsingEllipsoidsController.LABEL_ID_OFFSET, imgTrack.getAt( center ).get() ); // check that there is no value set outside the ellipsoid of the spot long[] corner = new long[] { 0, 0, 0 }; assertEquals( 0, imgSpot.getAt( corner ).get() );