Skip to content

Commit

Permalink
An advanced version of the omnipose detector.
Browse files Browse the repository at this point in the history
With a gotcha: omnipose is based on cellpose 1, so there is no
'cellprob_threshld_ parameter, but 'mask_threshold' instead.
  • Loading branch information
tinevez committed Nov 6, 2023
1 parent b2952b1 commit 8b266ca
Show file tree
Hide file tree
Showing 3 changed files with 578 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package fiji.plugin.trackmate.omnipose.advanced;

import static fiji.plugin.trackmate.cellpose.advanced.AdvancedCellposeDetectorFactory.KEY_CELL_PROB_THRESHOLD;
import static fiji.plugin.trackmate.cellpose.advanced.AdvancedCellposeDetectorFactory.KEY_FLOW_THRESHOLD;
import static fiji.plugin.trackmate.gui.Fonts.SMALL_FONT;

import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.util.Map;

import javax.swing.JLabel;

import fiji.plugin.trackmate.Model;
import fiji.plugin.trackmate.Settings;
import fiji.plugin.trackmate.cellpose.advanced.AdvancedCellposeDetectorConfigurationPanel;
import fiji.plugin.trackmate.detection.SpotDetectorFactoryBase;
import fiji.plugin.trackmate.gui.displaysettings.SliderPanelDouble;
import fiji.plugin.trackmate.gui.displaysettings.StyleElements;
import fiji.plugin.trackmate.omnipose.OmniposeDetectorConfigurationPanel;
import fiji.plugin.trackmate.omnipose.OmniposeSettings.PretrainedModelOmnipose;

public class AdvancedOmniposeDetectorConfigurationPanel extends OmniposeDetectorConfigurationPanel
{

private static final long serialVersionUID = 1L;

private static final String TITLE = AdvancedOmniposeDetectorFactory.NAME;;

private final StyleElements.BoundedDoubleElement flowThresholdEl = new StyleElements.BoundedDoubleElement( "Flow threshold", 0.0, 3.0 )
{

private double flowThreshold = 0.;

@Override
public double get()
{
return flowThreshold;
}

@Override
public void set( final double v )
{
flowThreshold = v;
}
};

private final StyleElements.BoundedDoubleElement cellProbThresholdEl = new StyleElements.BoundedDoubleElement("Cell prob", -6.0, 6.0)
{

private double cellProbThreshold = 0.;

@Override
public double get()
{
return cellProbThreshold;
}

@Override
public void set( final double v )
{
cellProbThreshold = v;
}
};

public AdvancedOmniposeDetectorConfigurationPanel( final Settings settings, final Model model )
{
super( settings, model, TITLE, ICON, DOC1_URL, "omnipose", PretrainedModelOmnipose.values() );

/*
* Add flow threshold.
*/

int gridy = 12;

final JLabel lblFlowThreshold = new JLabel( "Flow threshold:" );
lblFlowThreshold.setFont( SMALL_FONT );
final GridBagConstraints gbcLblFlowThreshold = new GridBagConstraints();
gbcLblFlowThreshold.anchor = GridBagConstraints.EAST;
gbcLblFlowThreshold.insets = new Insets( 0, 5, 5, 5 );
gbcLblFlowThreshold.gridx = 0;
gbcLblFlowThreshold.gridy = gridy;
add( lblFlowThreshold, gbcLblFlowThreshold );

final SliderPanelDouble sliderPanelFlowThreshold = StyleElements.linkedSliderPanel( flowThresholdEl, 3, 0.1 );
AdvancedCellposeDetectorConfigurationPanel.setFont( sliderPanelFlowThreshold, SMALL_FONT );
final GridBagConstraints gbcFlowThresholdSlider = new GridBagConstraints();
gbcFlowThresholdSlider.anchor = GridBagConstraints.EAST;
gbcFlowThresholdSlider.insets = new Insets( 0, 5, 5, 5 );
gbcFlowThresholdSlider.fill = GridBagConstraints.HORIZONTAL;
gbcFlowThresholdSlider.gridx = 1;
gbcFlowThresholdSlider.gridwidth = 2;
gbcFlowThresholdSlider.gridy = gridy;
add( sliderPanelFlowThreshold, gbcFlowThresholdSlider );

/*
* Add cell probability threshold.
*/

gridy++;

final JLabel lblCellProb = new JLabel( "Mask threshold:" );
lblCellProb.setFont( SMALL_FONT );
final GridBagConstraints gbcLblCellProb = new GridBagConstraints();
gbcLblCellProb.anchor = GridBagConstraints.EAST;
gbcLblCellProb.insets = new Insets( 0, 5, 5, 5 );
gbcLblCellProb.gridx = 0;
gbcLblCellProb.gridy = gridy;
add( lblCellProb, gbcLblCellProb );

final SliderPanelDouble sliderPanelCellProbThreshold = StyleElements.linkedSliderPanel( cellProbThresholdEl, 3, 0.4 );
AdvancedCellposeDetectorConfigurationPanel.setFont( sliderPanelCellProbThreshold, SMALL_FONT );
final GridBagConstraints gbcCellProbThresholdSlider = new GridBagConstraints();
gbcCellProbThresholdSlider.anchor = GridBagConstraints.EAST;
gbcCellProbThresholdSlider.insets = new Insets( 0, 5, 5, 5 );
gbcCellProbThresholdSlider.fill = GridBagConstraints.HORIZONTAL;
gbcCellProbThresholdSlider.gridx = 1;
gbcCellProbThresholdSlider.gridwidth = 2;
gbcCellProbThresholdSlider.gridy = gridy;
add( sliderPanelCellProbThreshold, gbcCellProbThresholdSlider );
}

@Override
protected SpotDetectorFactoryBase< ? > getDetectorFactory()
{
return new AdvancedOmniposeDetectorFactory<>();
}

@Override
public void setSettings( final Map< String, Object > settings )
{
super.setSettings( settings );
flowThresholdEl.set( ( double ) settings.get( KEY_FLOW_THRESHOLD ) );
flowThresholdEl.update();
cellProbThresholdEl.set( ( double ) settings.get( KEY_CELL_PROB_THRESHOLD ) );
cellProbThresholdEl.update();
}

@Override
public Map< String, Object > getSettings()
{
final Map< String, Object > settings = super.getSettings();
settings.put( KEY_FLOW_THRESHOLD, flowThresholdEl.get() );
settings.put( KEY_CELL_PROB_THRESHOLD, cellProbThresholdEl.get() );
return settings;
}
}
Loading

0 comments on commit 8b266ca

Please sign in to comment.