Skip to content

Commit

Permalink
Add offset 1 to label ids
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
stefanhahmann committed Sep 27, 2023
1 parent c6a8708 commit 879d2ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() );
Expand Down Expand Up @@ -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() );
Expand Down

0 comments on commit 879d2ee

Please sign in to comment.