diff --git a/src/main/java/fiji/plugin/trackmate/gui/editor/LabkitImporter.java b/src/main/java/fiji/plugin/trackmate/gui/editor/LabkitImporter.java index fb77fdc46..677022642 100644 --- a/src/main/java/fiji/plugin/trackmate/gui/editor/LabkitImporter.java +++ b/src/main/java/fiji/plugin/trackmate/gui/editor/LabkitImporter.java @@ -34,6 +34,7 @@ import fiji.plugin.trackmate.Model; import fiji.plugin.trackmate.Spot; import fiji.plugin.trackmate.detection.SpotRoiUtils; +import ij.IJ; import net.imglib2.RandomAccessibleInterval; import net.imglib2.loops.LoopBuilder; import net.imglib2.roi.labeling.ImgLabeling; @@ -48,6 +49,8 @@ public class LabkitImporter< T extends IntegerType< T > & NativeType< T > > { + private static final boolean DEBUG = false; + private final Model model; private final double[] calibration; @@ -148,6 +151,7 @@ else if ( novelSpotList == null || novelSpotList.isEmpty() ) * One I had in the previous spot list, but that has * disappeared. Remove it. */ + IJ.log( " - Removed spot " + str( previousSpot ) ); model.removeSpot( previousSpot ); } else @@ -212,6 +216,9 @@ else if ( target == previousSpot ) else throw new IllegalArgumentException( "The edge of a spot does not have the spot as source or target?!?" ); } + if ( DEBUG ) + IJ.log( " - Modified spot " + str( previousSpot ) + " -> " + str( mainNovelSpot ) ); + model.removeSpot( previousSpot ); // Deal with the other ones. @@ -225,6 +232,9 @@ else if ( target == previousSpot ) s.putFeature( Spot.POSITION_T, currentTimePoint * dt ); s.putFeature( Spot.QUALITY, -1. ); model.addSpotTo( s, Integer.valueOf( currentTimePoint ) ); + + if ( DEBUG ) + IJ.log( " - Added spot " + str( s ) ); } } @@ -235,6 +245,9 @@ private void addNewSpot( final Iterable< Spot > novelSpotList, final int current spot.putFeature( Spot.POSITION_T, currentTimePoint * dt ); spot.putFeature( Spot.QUALITY, -1. ); model.addSpotTo( spot, Integer.valueOf( currentTimePoint ) ); + + if ( DEBUG ) + IJ.log( " - Added spot " + str( spot ) ); } } @@ -276,10 +289,25 @@ private Map< Integer, List< Spot > > getSpots( final RandomAccessibleInterval< T final ImgLabeling< Integer, ? > labeling = ImgLabeling.fromImageAndLabels( rai, indices ); final Map< Integer, List< Spot > > spots = SpotRoiUtils.from2DLabelingWithROIMap( labeling, - labeling.minAsDoubleArray(), + new double[] { 0., 0. }, calibration, simplify, rai ); return spots; } + + private static final String str( final Spot spot ) + { + return spot.ID() + " (" + + roundToN( spot.getDoublePosition( 0 ), 1 ) + ", " + + roundToN( spot.getDoublePosition( 1 ), 1 ) + ", " + + roundToN( spot.getDoublePosition( 2 ), 1 ) + ") " + + "@ t=" + spot.getFeature( Spot.FRAME ).intValue(); + } + + private static double roundToN( final double num, final int n ) + { + final double scale = Math.pow( 10, n ); + return Math.round( num * scale ) / scale; + } } diff --git a/src/main/java/fiji/plugin/trackmate/gui/editor/LabkitLauncher.java b/src/main/java/fiji/plugin/trackmate/gui/editor/LabkitLauncher.java index 3a1ba7ffc..ff5212662 100644 --- a/src/main/java/fiji/plugin/trackmate/gui/editor/LabkitLauncher.java +++ b/src/main/java/fiji/plugin/trackmate/gui/editor/LabkitLauncher.java @@ -218,9 +218,18 @@ public void run() log.setStatus( "Re-importing from Labkit..." ); for ( int t = 0; t < nTimepoints; t++ ) { + // The spots of this time-point: + final Map< Integer, Spot > spotLabelsThisFrame = new HashMap<>(); + for ( final Integer label : spotLabels.keySet() ) + { + final Spot spot = spotLabels.get( label ); + if ( spot.getFeature( Spot.FRAME ).intValue() == t ) + spotLabelsThisFrame.put( label, spot ); + } + final RandomAccessibleInterval< T > novelIndexImgThisFrame = Views.hyperSlice( indexImg, timeDim, t ); final RandomAccessibleInterval< T > previousIndexImgThisFrame = Views.hyperSlice( previousIndexImg, timeDim, t ); - reimporter.reimport( novelIndexImgThisFrame, previousIndexImgThisFrame, t, spotLabels ); + reimporter.reimport( novelIndexImgThisFrame, previousIndexImgThisFrame, t, spotLabelsThisFrame ); log.setProgress( t / ( double ) nTimepoints ); } log.setStatus( "" );