Skip to content

Commit 702cd59

Browse files
committed
Properly compute SNR and contrast with NaNs.
1 parent c1a1869 commit 702cd59

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

src/main/java/fiji/plugin/trackmate/features/spot/SpotContrastAndSNRAnalyzer.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,31 @@ public final void process( final Spot spot )
108108
final SpotRoi outterRoi = roi.copy();
109109
outterRoi.scale( alpha );
110110
final IterableInterval< T > neighborhood = SpotUtil.iterable( outterRoi, spot, img );
111-
double outterSum = 0.;
111+
double totalSum = 0.;
112+
int nTotal = 0; // Total number of non-NaN pixels
113+
114+
// Iterate over the big ROI.
112115
for ( final T t : neighborhood )
113116
{
114117
final double val = t.getRealDouble();
115118
if ( Double.isNaN( val ) )
116119
continue;
117-
outterSum += val;
120+
nTotal++;
121+
totalSum += val;
118122
}
119-
123+
124+
// Sum intensity inside (over non-NaN pixels).
120125
final String sumFeature = makeFeatureKey( TOTAL_INTENSITY, channel );
121-
final double innterSum = spot.getFeature( sumFeature );
122-
outterSum -= innterSum;
123-
meanOut = outterSum / ( outterRoi.area() - roi.area() );
126+
final double innerSum = spot.getFeature( sumFeature );
127+
128+
// Compute number of non-NaN pixels in the inner roi.
129+
final int nInner = ( int ) ( innerSum / meanIn );
130+
131+
// Total number of non-NaN pixels in the outer roi.
132+
final int nOut = nTotal - nInner;
133+
134+
final double outterSum = totalSum - innerSum;
135+
meanOut = outterSum / nOut;
124136
}
125137
else
126138
{
@@ -136,7 +148,7 @@ public final void process( final Spot spot )
136148
}
137149

138150
final double radius2 = radius * radius;
139-
int nOut = 0; // inner number of pixels
151+
int nOut = 0; // Outer number of non-NaN pixels.
140152
double sumOut = 0;
141153

142154
// Compute mean in the outer ring
@@ -147,10 +159,10 @@ public final void process( final Spot spot )
147159
final double dist2 = cursor.getDistanceSquared();
148160
if ( dist2 > radius2 )
149161
{
150-
nOut++;
151162
final double val = cursor.get().getRealDouble();
152163
if ( Double.isNaN( val ) )
153164
continue;
165+
nOut++;
154166
sumOut += val;
155167
}
156168
}

0 commit comments

Comments
 (0)