diff --git a/src/main/java/org/mastodon/mamut/segment/SegmentUsingEllipsoidsController.java b/src/main/java/org/mastodon/mamut/segment/SegmentUsingEllipsoidsController.java index bba160212..e6b6ba36a 100644 --- a/src/main/java/org/mastodon/mamut/segment/SegmentUsingEllipsoidsController.java +++ b/src/main/java/org/mastodon/mamut/segment/SegmentUsingEllipsoidsController.java @@ -11,12 +11,9 @@ import net.imagej.ImgPlus; import net.imagej.axis.Axes; import net.imagej.axis.AxisType; -import net.imglib2.RandomAccessible; -import net.imglib2.RandomAccessibleInterval; import net.imglib2.cache.img.DiskCachedCellImg; import net.imglib2.cache.img.DiskCachedCellImgFactory; import net.imglib2.cache.img.DiskCachedCellImgOptions; -import net.imglib2.converter.RealTypeConverters; import net.imglib2.img.Img; import net.imglib2.img.display.imagej.ImageJFunctions; import net.imglib2.realtransform.AffineTransform3D; @@ -89,12 +86,9 @@ protected SegmentUsingEllipsoidsController( * Renders ellipsoids of all timepoints into an ImageJ image using the selected {@link LabelOptions} and saves it to a file. * @param labelOption the {@link LabelOptions} to use * @param file the file to save the image to - * @param withBackground whether to keep the background of the image * @param showResult whether to show the result in ImageJ */ - public void saveEllipsoidSegmentationToFile( - final LabelOptions labelOption, final File file, boolean withBackground, boolean showResult - ) + public void saveEllipsoidSegmentationToFile( final LabelOptions labelOption, final File file, boolean showResult ) { if ( file == null ) throw new IllegalArgumentException( "Cannot write ellipsoid segmentation to file. Given file is null." ); @@ -116,8 +110,6 @@ public void saveEllipsoidSegmentationToFile( source.getSourceTransform( timepointId, 0, transform ); IntervalView< IntType > frame = Views.hyperSlice( img, 3, timepointId ); AbstractSource< IntType > frameSource = new RandomAccessibleIntervalSource<>( frame, new IntType(), transform, "Segmentation" ); - if ( withBackground ) - addBackground( timepointId, frameSource ); final EllipsoidIterable< IntType > ellipsoidIterable = new EllipsoidIterable<>( frameSource ); segmentAllSpotsOfTimepoint( ellipsoidIterable, labelOption, timepointId, frames ); } @@ -144,13 +136,6 @@ private ReentrantReadWriteLock.ReadLock getReadLock( LabelOptions labelOption ) } } - private void addBackground( int timepointId, AbstractSource< IntType > sliceSource ) - { - RandomAccessible< RealType< ? > > bdvRandomAccessible = source.getSource( timepointId, 0 ); - RandomAccessibleInterval< IntType > sliceRai = sliceSource.getSource( 0, 0 ); - RealTypeConverters.copyFromTo( bdvRandomAccessible, sliceRai ); - } - private void segmentAllSpotsOfTimepoint( final EllipsoidIterable< ? extends RealType< ? > > iterable, final LabelOptions option, final int timepointId, final int frames ) diff --git a/src/main/java/org/mastodon/mamut/segment/ui/SegmentUsingEllipsoidsView.java b/src/main/java/org/mastodon/mamut/segment/ui/SegmentUsingEllipsoidsView.java index 2fcf3fddb..98ac7a035 100644 --- a/src/main/java/org/mastodon/mamut/segment/ui/SegmentUsingEllipsoidsView.java +++ b/src/main/java/org/mastodon/mamut/segment/ui/SegmentUsingEllipsoidsView.java @@ -25,10 +25,6 @@ public class SegmentUsingEllipsoidsView implements Command @Parameter(label = "Show result in ImageJ window") private boolean showResult; - @SuppressWarnings("unused") - @Parameter(label = "Keep background") - private boolean withBackground; - @SuppressWarnings("unused") @Parameter private MamutAppModel appModel; @@ -42,6 +38,6 @@ public void run() { SegmentUsingEllipsoidsController controller = new SegmentUsingEllipsoidsController( appModel, context ); LabelOptions selectedOption = LabelOptions.getByName( option ); - controller.saveEllipsoidSegmentationToFile( selectedOption, saveTo, showResult, withBackground ); + controller.saveEllipsoidSegmentationToFile( selectedOption, saveTo, showResult ); } } diff --git a/src/test/java/org/mastodon/mamut/segment/SegmentUsingEllipsoidsControllerTest.java b/src/test/java/org/mastodon/mamut/segment/SegmentUsingEllipsoidsControllerTest.java index 5b534bb08..94d5912a4 100644 --- a/src/test/java/org/mastodon/mamut/segment/SegmentUsingEllipsoidsControllerTest.java +++ b/src/test/java/org/mastodon/mamut/segment/SegmentUsingEllipsoidsControllerTest.java @@ -47,7 +47,8 @@ public void setUp() { model = new Model(); ModelGraph modelGraph = model.getGraph(); - spot = modelGraph.addVertex(); + modelGraph.addVertex(); // NB: dummy vertex with internal pool index 0 + spot = modelGraph.addVertex(); // NB: internal pool index is 1 ModelBranchGraph modelBranchGraph = model.getBranchGraph(); modelBranchGraph.graphRebuilt(); branchSpot = modelBranchGraph.getBranchVertex( spot, modelBranchGraph.vertexRef() ); @@ -67,24 +68,24 @@ public void testSaveEllipsoidSegmentationToFile() throws IOException File outputSpot = getTempFile( "resultSpot" ); File outputBranchSpot = getTempFile( "resultBranchSpot" ); File outputTrack = getTempFile( "resultTrack" ); - segmentUsingEllipsoidsController.saveEllipsoidSegmentationToFile( LabelOptions.SPOT_ID, outputSpot, true, false ); - segmentUsingEllipsoidsController.saveEllipsoidSegmentationToFile( LabelOptions.BRANCH_SPOT_ID, outputBranchSpot, true, false ); - segmentUsingEllipsoidsController.saveEllipsoidSegmentationToFile( LabelOptions.TRACK_ID, outputTrack, true, false ); + segmentUsingEllipsoidsController.saveEllipsoidSegmentationToFile( LabelOptions.SPOT_ID, outputSpot, false ); + segmentUsingEllipsoidsController.saveEllipsoidSegmentationToFile( LabelOptions.BRANCH_SPOT_ID, outputBranchSpot, false ); + segmentUsingEllipsoidsController.saveEllipsoidSegmentationToFile( LabelOptions.TRACK_ID, outputTrack, false ); ImgOpener imgOpener = new ImgOpener( context ); SCIFIOImgPlus< IntType > imgSpot = getIntTypeSCIFIOImgPlus( imgOpener, outputSpot ); SCIFIOImgPlus< IntType > imgBranchSpot = getIntTypeSCIFIOImgPlus( imgOpener, outputBranchSpot ); SCIFIOImgPlus< IntType > imgTrack = getIntTypeSCIFIOImgPlus( imgOpener, outputTrack ); - // check that the random content has been replaced by the spot id in the center of the spot + // 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( 0, imgTrack.getAt( center ).get() ); - // check that the random content has NOT been replaced outside the ellipsoid of the spot + assertEquals( 1, imgTrack.getAt( center ).get() ); + // check that there is no value set outside the ellipsoid of the spot long[] corner = new long[] { 0, 0, 0 }; - assertNotEquals( spot.getInternalPoolIndex(), imgSpot.getAt( corner ).get() ); - assertNotEquals( branchSpot.getInternalPoolIndex(), imgBranchSpot.getAt( corner ).get() ); - assertNotEquals( 0, imgTrack.getAt( corner ).get() ); + assertEquals( 0, imgSpot.getAt( corner ).get() ); + assertEquals( 0, imgBranchSpot.getAt( corner ).get() ); + assertEquals( 0, imgTrack.getAt( corner ).get() ); } private static SCIFIOImgPlus< IntType > getIntTypeSCIFIOImgPlus( ImgOpener imgOpener, File outputSpot ) @@ -110,9 +111,9 @@ public void testExceptions() throws IOException file.deleteOnExit(); assertThrows( IllegalArgumentException.class, - () -> controller.saveEllipsoidSegmentationToFile( LabelOptions.SPOT_ID, null, true, false ) + () -> controller.saveEllipsoidSegmentationToFile( LabelOptions.SPOT_ID, null, false ) ); - assertThrows( IllegalArgumentException.class, () -> controller.saveEllipsoidSegmentationToFile( null, file, true, false ) ); + assertThrows( IllegalArgumentException.class, () -> controller.saveEllipsoidSegmentationToFile( null, file, false ) ); } private static AbstractSource< IntType > createRandomSource()