Skip to content

Commit

Permalink
Remove option to include intensity in the segmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhahmann committed Sep 26, 2023
1 parent 3636768 commit 28c08b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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." );
Expand All @@ -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 );
}
Expand All @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand All @@ -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 )
Expand All @@ -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()
Expand Down

0 comments on commit 28c08b4

Please sign in to comment.