Skip to content

Commit

Permalink
Fixed one more bug with the labkit importer.
Browse files Browse the repository at this point in the history
When editing the whole movie, if the label of a new spot was using
the label of an existing spot in another time-point, the existing
one was removed. Because the new spot was identified as a modification
of the existing one.
The solution is to pass to the importer only the list of existing
spots in the current time-frame.
  • Loading branch information
tinevez committed Jul 22, 2024
1 parent 2f9583e commit 9d3c58e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/main/java/fiji/plugin/trackmate/gui/editor/LabkitImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import fiji.plugin.trackmate.Model;
import fiji.plugin.trackmate.Spot;
import fiji.plugin.trackmate.detection.MaskUtils;
import ij.IJ;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.loops.LoopBuilder;
import net.imglib2.roi.labeling.ImgLabeling;
Expand All @@ -27,6 +28,8 @@
public class LabkitImporter< T extends IntegerType< T > & NativeType< T > >
{

private static final boolean DEBUG = false;

private final Model model;

private final double[] calibration;
Expand Down Expand Up @@ -127,6 +130,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
Expand Down Expand Up @@ -191,6 +195,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.
Expand All @@ -204,6 +211,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 ) );
}
}

Expand All @@ -214,6 +224,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 ) );
}
}

Expand Down Expand Up @@ -261,4 +274,19 @@ private Map< Integer, List< Spot > > getSpots( final RandomAccessibleInterval< T
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,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( "" );
Expand Down

0 comments on commit 9d3c58e

Please sign in to comment.