diff --git a/image_analysis/scale_merge/RotationScaleMerge.cpp b/image_analysis/scale_merge/RotationScaleMerge.cpp index 6470a8a0..680e0004 100644 --- a/image_analysis/scale_merge/RotationScaleMerge.cpp +++ b/image_analysis/scale_merge/RotationScaleMerge.cpp @@ -1869,8 +1869,13 @@ void RotationScaleMerge::ApplyCellSurface(const std::vector &cell, int std::fill(swI.begin(), swI.end(), 0.0); for (const int32_t i : sel) { const Obs &o = fulls[i]; - const double a = A[cell[i]], sc = static_cast(o.sigma) * o.corr * a, w = 1.0 / (sc * sc); - sw[o.group] += w; swI[o.group] += w * static_cast(o.I) * o.corr * a; + // Keep the intensity's own product together before it is weighted: w * ((I*corr)*a) is + // what the loops this replaced summed, and w * I * corr * a rounds differently. The + // score decides whether a surface is kept, so a last-place difference here can flip a + // gain gate that is otherwise sitting on the fence. + const double a = A[cell[i]], Is = static_cast(o.I) * o.corr * a; + const double sc = static_cast(o.sigma) * o.corr * a, w = 1.0 / (sc * sc); + sw[o.group] += w; swI[o.group] += w * Is; } };