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 19e981a commit ddd2520
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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 ) );
}
}

Expand All @@ -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 ) );
}
}

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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( "" );
Expand Down

0 comments on commit ddd2520

Please sign in to comment.