From f77c0b172e50619d712aa9d931b33890f5e3dd12 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Thu, 13 Aug 2026 15:53:54 -0500 Subject: [PATCH] STYLE: Use GetNumberOfPixels() for STAPLE pixel count 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 #6763 --- .../ImageCompare/include/itkSTAPLEImageFilter.hxx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Modules/Filtering/ImageCompare/include/itkSTAPLEImageFilter.hxx b/Modules/Filtering/ImageCompare/include/itkSTAPLEImageFilter.hxx index 90647ea6a65..891a8677024 100644 --- a/Modules/Filtering/ImageCompare/include/itkSTAPLEImageFilter.hxx +++ b/Modules/Filtering/ImageCompare/include/itkSTAPLEImageFilter.hxx @@ -107,8 +107,8 @@ STAPLEImageFilter::GenerateData() // Divide sum by num of files, calculate the estimate of g_t - double N = 0.0; - double g_t = 0.0; + const SizeValueType N = W->GetRequestedRegion().GetNumberOfPixels(); + double g_t = 0.0; { ImageScanlineIterator out(W, W->GetRequestedRegion()); while (!out.IsAtEnd()) @@ -117,12 +117,11 @@ STAPLEImageFilter::GenerateData() { out.Set(out.Get() / static_cast(number_of_input_files)); g_t += out.Get(); - N = N + 1.0; ++out; } // end of scanline out.NextLine(); } - g_t = (g_t / N) * m_ConfidenceWeight; + g_t = (g_t / static_cast(N)) * m_ConfidenceWeight; } unsigned int iter = 0; for (; iter < m_MaximumIterations; ++iter)