Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A utility that returns an iterable over a spot in an ImgPlus.
Takes into account whether the spot has a ROI or not, and borderline cases.
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package fiji.plugin.trackmate.util; | ||
|
||
import fiji.plugin.trackmate.Spot; | ||
import fiji.plugin.trackmate.SpotRoi; | ||
import fiji.plugin.trackmate.detection.DetectionUtils; | ||
import net.imagej.ImgPlus; | ||
import net.imglib2.FinalInterval; | ||
import net.imglib2.Interval; | ||
import net.imglib2.IterableInterval; | ||
import net.imglib2.type.numeric.RealType; | ||
import net.imglib2.view.Views; | ||
|
||
public class SpotUtil | ||
{ | ||
|
||
public static final < T extends RealType< T > > IterableInterval< T > iterable( final Spot spot, final ImgPlus< T > img ) | ||
{ | ||
// Prepare neighborhood | ||
final IterableInterval< T > neighborhood; | ||
final SpotRoi roi = spot.getRoi(); | ||
if ( null != roi && DetectionUtils.is2D( img ) ) | ||
{ | ||
// Operate on ROI only if we have one and the image is 2D. | ||
neighborhood = roi.sample( spot, img ); | ||
} | ||
else | ||
{ | ||
// Otherwise default to circle / sphere. | ||
neighborhood = new SpotNeighborhood<>( spot, img ); | ||
} | ||
|
||
final int npixels = ( int ) neighborhood.size(); | ||
if ( npixels <= 1 ) | ||
{ | ||
final double[] calibration = TMUtils.getSpatialCalibration( img ); | ||
final long[] min = new long[ img.numDimensions() ]; | ||
final long[] max = new long[ img.numDimensions() ]; | ||
for ( int d = 0; d < min.length; d++ ) | ||
{ | ||
final long center = Math.round( spot.getFeature( Spot.POSITION_FEATURES[ d ] ).doubleValue() / calibration[ d ] ); | ||
min[ d ] = center; | ||
max[ d ] = center + 1; | ||
} | ||
|
||
final Interval interval = new FinalInterval( min, max ); | ||
return Views.interval( img, interval ); | ||
} | ||
else | ||
{ | ||
return neighborhood; | ||
} | ||
} | ||
} |