STYLE: Use GetNumberOfPixels() for STAPLE pixel count - #6764
Conversation
The pixel count came from a double accumulator incremented once per pixel in the scanline loop. The region already knows its pixel count exactly. Closes InsightSoftwareConsortium#6763
|
There was a problem hiding this comment.
Thanks Hans!
Minor note: Now that N is only used at line 124, its declaration might be moved to line 123, reducing its scope and visibility. But I leave that up to you. Approved anyway.
PS I'm surprised that greptile did not already suggest you to reduce the scope of N. It's a C++ Core Guideline: Keep scopes small. Still approved anyway, just slightly disappointed about greptile!
Replaces a per-pixel
doubleaccumulator withGetRequestedRegion().GetNumberOfPixels()inSTAPLEImageFilter::GenerateData(). No behavior change — cleanup only, closing #6763.Why this is cleanup and not a bug fix
Nwas accumulated asN = N + 1.0inside the scanline loop.doublecarries a 53-bit mantissa, so the increment stays exact to 2^53 pixels and the counter never actually breaks. Filed and fixed only because it is the same idiom as thefloatcounter in #6759, where it is a live defect (floatsaturates at 2^24 = 16,777,216, reached easily by a 3D image), so anyone auditing for that pattern lands here and has to re-derive that this instance is benign.The change also removes one add from the inner loop.
What else in the file was checked and deliberately left alone
g_taccumulates fractional per-pixel values, not counts — staysdouble.p_num/p_denom/q_num/q_denomaccumulateW_iand1 - W_iover all pixels. Fractional, alreadydouble, not counters.out.Set(out.Get() + 1.0)is bounded by the input file count, so it carries no precision risk.alpha1/beta1are per-pixel products, not accumulations.itkLabelVotingImageFilterwas checked separately and already counts votes inunsigned int.Local verification
Includes
itkSTAPLEImageFilterTest, which is a baseline image comparison — the filter's output is bit-identical to before.pre-commit run --all-filesexits 0 on this tree.PR Checklist