Skip to content

Commit

Permalink
Implement the smoothing scale in the threshold, mask and label detect…
Browse files Browse the repository at this point in the history
…ors.
  • Loading branch information
tinevez committed Nov 23, 2023
1 parent 38dd58a commit bf3e6c6
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ private < R extends IntegerType< R > > void processIntegerImg( final RandomAcces
{
spots = SpotRoiUtils.from2DLabelingWithROI(
labeling,
interval,
interval.minAsDoubleArray(),
calibration,
simplify,
smoothingScale,
null );
}
else if ( input.numDimensions() == 3 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static fiji.plugin.trackmate.io.IOUtils.writeAttribute;
import static fiji.plugin.trackmate.io.IOUtils.writeTargetChannel;
import static fiji.plugin.trackmate.util.TMUtils.checkMapKeys;
import static fiji.plugin.trackmate.util.TMUtils.checkOptionalParameter;
import static fiji.plugin.trackmate.util.TMUtils.checkParameter;

import java.util.ArrayList;
Expand Down Expand Up @@ -154,14 +155,16 @@ public boolean checkSettings( final Map< String, Object > lSettings )
final StringBuilder errorHolder = new StringBuilder();
ok = ok & checkParameter( lSettings, KEY_TARGET_CHANNEL, Integer.class, errorHolder );
ok = ok & checkParameter( lSettings, KEY_SIMPLIFY_CONTOURS, Boolean.class, errorHolder );
ok = ok & checkOptionalParameter( lSettings, KEY_SMOOTHING_SCALE, Double.class, errorHolder );
final List< String > mandatoryKeys = new ArrayList<>();
mandatoryKeys.add( KEY_TARGET_CHANNEL );
mandatoryKeys.add( KEY_SIMPLIFY_CONTOURS );
ok = ok & checkMapKeys( lSettings, mandatoryKeys, null, errorHolder );
final List< String > optionalKeys = new ArrayList<>();
optionalKeys.add( KEY_SMOOTHING_SCALE );
ok = ok & checkMapKeys( lSettings, mandatoryKeys, optionalKeys, errorHolder );
if ( !ok )
{
errorMessage = errorHolder.toString();
}

return ok;
}

Expand Down Expand Up @@ -218,6 +221,7 @@ public Map< String, Object > getDefaultSettings()
final Map< String, Object > lSettings = new HashMap<>();
lSettings.put( KEY_TARGET_CHANNEL, DEFAULT_TARGET_CHANNEL );
lSettings.put( KEY_SIMPLIFY_CONTOURS, true );
lSettings.put( KEY_SMOOTHING_SCALE, -1. );
return lSettings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import static fiji.plugin.trackmate.detection.DetectorKeys.DEFAULT_TARGET_CHANNEL;
import static fiji.plugin.trackmate.detection.DetectorKeys.KEY_TARGET_CHANNEL;
import static fiji.plugin.trackmate.io.IOUtils.readBooleanAttribute;
import static fiji.plugin.trackmate.io.IOUtils.readDoubleAttribute;
import static fiji.plugin.trackmate.io.IOUtils.readIntegerAttribute;
import static fiji.plugin.trackmate.io.IOUtils.writeAttribute;
import static fiji.plugin.trackmate.io.IOUtils.writeTargetChannel;
import static fiji.plugin.trackmate.util.TMUtils.checkMapKeys;
import static fiji.plugin.trackmate.util.TMUtils.checkOptionalParameter;
import static fiji.plugin.trackmate.util.TMUtils.checkParameter;

import java.util.ArrayList;
Expand Down Expand Up @@ -147,10 +149,13 @@ public boolean checkSettings( final Map< String, Object > lSettings )
final StringBuilder errorHolder = new StringBuilder();
ok = ok & checkParameter( lSettings, KEY_TARGET_CHANNEL, Integer.class, errorHolder );
ok = ok & checkParameter( lSettings, KEY_SIMPLIFY_CONTOURS, Boolean.class, errorHolder );
ok = ok & checkOptionalParameter( lSettings, KEY_SMOOTHING_SCALE, Double.class, errorHolder );
final List< String > mandatoryKeys = new ArrayList<>();
mandatoryKeys.add( KEY_TARGET_CHANNEL );
mandatoryKeys.add( KEY_SIMPLIFY_CONTOURS );
ok = ok & checkMapKeys( lSettings, mandatoryKeys, null, errorHolder );
final List< String > optionalKeys = new ArrayList<>();
optionalKeys.add( KEY_SMOOTHING_SCALE );
ok = ok & checkMapKeys( lSettings, mandatoryKeys, optionalKeys, errorHolder );
if ( !ok )
{
errorMessage = errorHolder.toString();
Expand All @@ -163,7 +168,8 @@ public boolean marshall( final Map< String, Object > lSettings, final Element el
{
final StringBuilder errorHolder = new StringBuilder();
final boolean ok = writeTargetChannel( lSettings, element, errorHolder )
&& writeAttribute( lSettings, element, KEY_SIMPLIFY_CONTOURS, Boolean.class, errorHolder );
&& writeAttribute( lSettings, element, KEY_SIMPLIFY_CONTOURS, Boolean.class, errorHolder )
&& writeAttribute( lSettings, element, KEY_SMOOTHING_SCALE, Double.class, errorHolder );

if ( !ok )
errorMessage = errorHolder.toString();
Expand All @@ -179,6 +185,7 @@ public boolean unmarshall( final Element element, final Map< String, Object > lS
boolean ok = true;
ok = ok & readIntegerAttribute( element, lSettings, KEY_TARGET_CHANNEL, errorHolder );
ok = ok & readBooleanAttribute( element, lSettings, KEY_SIMPLIFY_CONTOURS, errorHolder );
ok = ok & readDoubleAttribute( element, lSettings, KEY_SMOOTHING_SCALE, errorHolder );
if ( !ok )
{
errorMessage = errorHolder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public boolean process()
calibration,
threshold,
simplify,
smoothingScale,
numThreads,
null );
final long end = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static fiji.plugin.trackmate.io.IOUtils.writeAttribute;
import static fiji.plugin.trackmate.io.IOUtils.writeTargetChannel;
import static fiji.plugin.trackmate.util.TMUtils.checkMapKeys;
import static fiji.plugin.trackmate.util.TMUtils.checkOptionalParameter;
import static fiji.plugin.trackmate.util.TMUtils.checkParameter;

import java.util.ArrayList;
Expand Down Expand Up @@ -119,7 +120,7 @@ public SpotDetector< T > getDetector( final Interval interval, final int frame )
{
final double intensityThreshold = ( Double ) settings.get( KEY_INTENSITY_THRESHOLD );
final boolean simplifyContours = ( Boolean ) settings.get( KEY_SIMPLIFY_CONTOURS );
final double smoothingScale = ( Double ) settings.get( KEY_SMOOTHING_SCALE );
final double smoothingScale = ( Double ) settings.getOrDefault( KEY_SMOOTHING_SCALE, -1. );
final double[] calibration = TMUtils.getSpatialCalibration( img );
final int channel = ( Integer ) settings.get( KEY_TARGET_CHANNEL ) - 1;
final RandomAccessible< T > imFrame = DetectionUtils.prepareFrameImg( img, channel, frame );
Expand Down Expand Up @@ -167,15 +168,17 @@ public boolean checkSettings( final Map< String, Object > lSettings )
ok = ok & checkParameter( lSettings, KEY_TARGET_CHANNEL, Integer.class, errorHolder );
ok = ok & checkParameter( lSettings, KEY_INTENSITY_THRESHOLD, Double.class, errorHolder );
ok = ok & checkParameter( lSettings, KEY_SIMPLIFY_CONTOURS, Boolean.class, errorHolder );
ok = ok & checkOptionalParameter( lSettings, KEY_SMOOTHING_SCALE, Double.class, errorHolder );
final List< String > mandatoryKeys = new ArrayList<>();
mandatoryKeys.add( KEY_TARGET_CHANNEL );
mandatoryKeys.add( KEY_INTENSITY_THRESHOLD );
mandatoryKeys.add( KEY_SIMPLIFY_CONTOURS );
ok = ok & checkMapKeys( lSettings, mandatoryKeys, null, errorHolder );
final List< String > optionalKeys = new ArrayList<>();
optionalKeys.add( KEY_SMOOTHING_SCALE );
ok = ok & checkMapKeys( lSettings, mandatoryKeys, optionalKeys, errorHolder );
if ( !ok )
{
errorMessage = errorHolder.toString();
}

return ok;
}

Expand All @@ -185,7 +188,8 @@ public boolean marshall( final Map< String, Object > lSettings, final Element el
final StringBuilder errorHolder = new StringBuilder();
final boolean ok = writeTargetChannel( lSettings, element, errorHolder )
&& writeAttribute( lSettings, element, KEY_INTENSITY_THRESHOLD, Double.class, errorHolder )
&& writeAttribute( lSettings, element, KEY_SIMPLIFY_CONTOURS, Boolean.class, errorHolder );
&& writeAttribute( lSettings, element, KEY_SIMPLIFY_CONTOURS, Boolean.class, errorHolder )
&& writeAttribute( lSettings, element, KEY_SMOOTHING_SCALE, Double.class, errorHolder );

if ( !ok )
errorMessage = errorHolder.toString();
Expand All @@ -202,6 +206,7 @@ public boolean unmarshall( final Element element, final Map< String, Object > lS
ok = ok & readIntegerAttribute( element, lSettings, KEY_TARGET_CHANNEL, errorHolder );
ok = ok & readDoubleAttribute( element, lSettings, KEY_INTENSITY_THRESHOLD, errorHolder );
ok = ok & readBooleanAttribute( element, lSettings, KEY_SIMPLIFY_CONTOURS, errorHolder );
ok = ok & readDoubleAttribute( element, lSettings, KEY_SMOOTHING_SCALE, errorHolder );
if ( !ok )
{
errorMessage = errorHolder.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
*/
package fiji.plugin.trackmate.gui.components.detector;

import static fiji.plugin.trackmate.detection.DetectorKeys.KEY_TARGET_CHANNEL;
import static fiji.plugin.trackmate.detection.ThresholdDetectorFactory.KEY_INTENSITY_THRESHOLD;

import java.util.Map;

import fiji.plugin.trackmate.Model;
import fiji.plugin.trackmate.Settings;
import fiji.plugin.trackmate.detection.LabelImageDetectorFactory;
import fiji.plugin.trackmate.detection.SpotDetectorFactory;
import fiji.plugin.trackmate.detection.ThresholdDetectorFactory;

/**
* Configuration panel for spot detectors based on label images.
Expand Down Expand Up @@ -59,15 +58,14 @@ public LabelImageDetectorConfigurationPanel(
public Map< String, Object > getSettings()
{
final Map< String, Object > lSettings = super.getSettings();
lSettings.remove( ThresholdDetectorFactory.KEY_INTENSITY_THRESHOLD );
lSettings.remove( KEY_INTENSITY_THRESHOLD );
return lSettings;
}

@Override
public void setSettings( final Map< String, Object > settings )
{
sliderChannel.setValue( ( Integer ) settings.get( KEY_TARGET_CHANNEL ) );
chkboxSimplify.setSelected( ( Boolean ) settings.get( ThresholdDetectorFactory.KEY_SIMPLIFY_CONTOURS ) );
setSettingsNonIntensity( settings );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
*/
package fiji.plugin.trackmate.gui.components.detector;

import static fiji.plugin.trackmate.detection.DetectorKeys.KEY_TARGET_CHANNEL;

import java.util.Map;

import fiji.plugin.trackmate.Model;
Expand Down Expand Up @@ -66,8 +64,7 @@ public Map< String, Object > getSettings()
@Override
public void setSettings( final Map< String, Object > settings )
{
sliderChannel.setValue( ( Integer ) settings.get( KEY_TARGET_CHANNEL ) );
chkboxSimplify.setSelected( ( Boolean ) settings.get( ThresholdDetectorFactory.KEY_SIMPLIFY_CONTOURS ) );
setSettingsNonIntensity( settings );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,20 @@ public Map< String, Object > getSettings()
return lSettings;
}

@Override
public void setSettings( final Map< String, Object > settings )
protected void setSettingsNonIntensity( final Map< String, Object > settings )
{
sliderChannel.setValue( ( Integer ) settings.get( KEY_TARGET_CHANNEL ) );
chkboxSimplify.setSelected( ( Boolean ) settings.get( ThresholdDetectorFactory.KEY_SIMPLIFY_CONTOURS ) );
final Object scaleObj = settings.get( KEY_SMOOTHING_SCALE );
final double scale = scaleObj == null ? -1. : ( ( Number ) scaleObj ).doubleValue();
smoothingPanel.setScale( scale );
}

final Double intensityThreshold = Double.valueOf( ( Double ) settings.get( ThresholdDetectorFactory.KEY_INTENSITY_THRESHOLD ) );
@Override
public void setSettings( final Map< String, Object > settings )
{
setSettingsNonIntensity( settings );
final Double intensityThreshold = Double.valueOf( ( Double ) settings.get( KEY_INTENSITY_THRESHOLD ) );
if ( intensityThreshold == null || intensityThreshold == 0. )
autoThreshold();
else
Expand Down

0 comments on commit bf3e6c6

Please sign in to comment.