Skip to content

Commit

Permalink
Replace channel index selection for BDV channel import by BDV source …
Browse files Browse the repository at this point in the history
…selection
  • Loading branch information
stefanhahmann committed Mar 15, 2024
1 parent 88e4642 commit 5ab71ed
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,21 +291,15 @@ public static void importSpotsFromImgPlus( final ImgPlus< ? > imgPlus, final dou
/**
* Imports spots from the given big data viewer channel into the given project model.
* @param projectModel the project model to add the spots to.
* @param labelChannelIndex the index of the channel to import the spots from. This channel should contain the labels.
* @param source the source to import the spots from.
* @param sigma the standard deviation of the Gaussian distribution to use for the covariance matrix.
* @throws IllegalArgumentException if the label channel index is out of bounds, i.e. if it is greater than the number of channels in the big data viewer source contained in the project model.
*/
public static void importSpotsFromBdvChannel( final ProjectModel projectModel, final int labelChannelIndex, final double sigma )
public static void importSpotsFromBdvChannel( final ProjectModel projectModel, final Source< ? > source, final double sigma )
{
final SharedBigDataViewerData sharedBigDataViewerData = projectModel.getSharedBdvData();
int numChannels = sharedBigDataViewerData.getSources().size();
if ( labelChannelIndex >= numChannels )
throw new IllegalArgumentException( "The label channel index " + labelChannelIndex
+ " is out of bounds. The available big data viewer source only contains " + numChannels + " channels." );
final AbstractSequenceDescription< ?, ?, ? > sequenceDescription = sharedBigDataViewerData.getSpimData().getSequenceDescription();
final List< TimePoint > frames = sequenceDescription.getTimePoints().getTimePointsOrdered();
final Source< ? extends RealType< ? > > source =
Cast.unchecked( sharedBigDataViewerData.getSources().get( labelChannelIndex ).getSpimSource() );
// NB: Use the dimensions of the first source and the first time point only without checking if they are equal in other sources and time points.
final VoxelDimensions voxelDimensions = sequenceDescription.getViewSetups().get( 0 ).getVoxelSize();
IntFunction< RandomAccessibleInterval< RealType< ? > > > imgProvider =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package org.mastodon.mamut.io.importer.labelimage.ui;

import bdv.viewer.SourceAndConverter;
import org.mastodon.mamut.ProjectModel;
import org.mastodon.mamut.io.importer.labelimage.LabelImageUtils;
import org.scijava.ItemVisibility;
import org.scijava.command.Command;
import org.scijava.command.ContextCommand;
import org.scijava.command.DynamicCommand;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Plugin( type = Command.class, label = "Import spots from BDV channel" )
public class ImportSpotsFromBdvChannelView extends ContextCommand
public class ImportSpotsFromBdvChannelView extends DynamicCommand
{
private static final int WIDTH = 15;

Expand All @@ -28,29 +33,30 @@ public class ImportSpotsFromBdvChannelView extends ContextCommand
@Parameter
private ProjectModel projectModel;

@SuppressWarnings( "all" )
@Parameter( label = "Index of channel with labels", min = "0", description = "The index of the BDV channel that contains the labels. Counting of label channel indeces starts at 0.", validater = "validateChannelIndex" )
private int labelChannelIndex = 0;
@Parameter( label = "Instance segmentation source", initializer = "initImgSourceChoices" )
public String imgSourceChoice = "";

@SuppressWarnings( "all" )
@Parameter( label = "Sigma", min = "0", description = "Deviations from center to draw the ellipsoid border" )
private double sigma = 2.1;

@SuppressWarnings( "unused" )
private void validateChannelIndex()
private void initImgSourceChoices()
{
int numChannels = projectModel.getSharedBdvData().getSources().size();
if ( labelChannelIndex >= numChannels )
cancel( "You have chosen " + labelChannelIndex + " as channel index, but the available big data viewer source only contains "
+ numChannels + " channels.\n"
+ "Please choose a lower channel index. Channel indices start at 0." );
final ArrayList< SourceAndConverter< ? > > sources = projectModel.getSharedBdvData().getSources();
List< String > choices = new ArrayList<>();
for ( SourceAndConverter< ? > source : sources )
choices.add( source.getSpimSource().getName() );
getInfo().getMutableInput( "imgSourceChoice", String.class ).setChoices( choices );
}

@Override
public void run()
{
if ( isCanceled() )
Optional< SourceAndConverter< ? > > sourceAndConverter = projectModel.getSharedBdvData().getSources().stream()
.filter( source -> source.getSpimSource().getName().equals( imgSourceChoice ) ).findFirst();
if ( !sourceAndConverter.isPresent() )
return;
LabelImageUtils.importSpotsFromBdvChannel( projectModel, labelChannelIndex, sigma );
LabelImageUtils.importSpotsFromBdvChannel( projectModel, sourceAndConverter.get().getSpimSource(), sigma );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public void testImportSpotsFromBdvChannel()
int pixelValue = 1;
Img< FloatType > img = createImageCubeCorners( pixelValue );
ProjectModel projectModel = DemoUtils.wrapAsAppModel( img, model, context );
LabelImageUtils.importSpotsFromBdvChannel( projectModel, 0, 1 );
LabelImageUtils.importSpotsFromBdvChannel( projectModel, projectModel.getSharedBdvData().getSources().get( 0 ).getSpimSource(),
1 );

Iterator< Spot > iter = model.getGraph().vertices().iterator();
Spot spot = iter.next();
Expand Down

0 comments on commit 5ab71ed

Please sign in to comment.