From 23d9b50d8a069e2a4722c6a1a0c61d768b377aa4 Mon Sep 17 00:00:00 2001 From: Philip Cook Date: Sat, 24 Aug 2024 10:18:04 -0400 Subject: [PATCH] BUG: float type for posterior sum caused overflow on large images --- .../antsAtroposSegmentationImageFilter.hxx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ImageSegmentation/antsAtroposSegmentationImageFilter.hxx b/ImageSegmentation/antsAtroposSegmentationImageFilter.hxx index e3f17cd25..c0740f99a 100644 --- a/ImageSegmentation/antsAtroposSegmentationImageFilter.hxx +++ b/ImageSegmentation/antsAtroposSegmentationImageFilter.hxx @@ -1149,7 +1149,7 @@ template typename AtroposSegmentationImageFilter::RealType AtroposSegmentationImageFilter::UpdateClassLabeling() { - RealType maxPosteriorSum = 0.0; + double maxPosteriorSum = 0.0; if (this->m_UseAsynchronousUpdating) { @@ -1166,7 +1166,7 @@ AtroposSegmentationImageFilter::Updat NeighborhoodIterator ItO(radius, this->GetOutput(), this->GetOutput()->GetRequestedRegion()); maxPosteriorSum = 0.0; - RealType oldMaxPosteriorSum = -1.0; + double oldMaxPosteriorSum = -1.0; unsigned int numberOfIterations = 0; while (maxPosteriorSum > oldMaxPosteriorSum && numberOfIterations++ < this->m_MaximumNumberOfICMIterations) { @@ -1214,7 +1214,7 @@ AtroposSegmentationImageFilter::Updat unsigned int totalNumberOfClasses = this->m_NumberOfTissueClasses + this->m_NumberOfPartialVolumeClasses; - Array sumPosteriors(totalNumberOfClasses); + Array sumPosteriors(totalNumberOfClasses); sumPosteriors.Fill(0.0); typename SampleType::Pointer sample = SampleType::New(); @@ -1269,7 +1269,7 @@ AtroposSegmentationImageFilter::Updat ItO.Set(static_cast(n + 1)); } } - sumPosteriors[n] += posteriorProbability; + sumPosteriors[n] += static_cast(posteriorProbability); } ++ItP; ++ItM; @@ -1299,7 +1299,7 @@ AtroposSegmentationImageFilter::Updat if (this->m_UseMixtureModelProportions) { - this->m_MixtureModelProportions[n] = sumPosteriors[n] / static_cast(totalSampleSize); + this->m_MixtureModelProportions[n] = static_cast(sumPosteriors[n] / static_cast(totalSampleSize)); } else { @@ -1482,12 +1482,12 @@ AtroposSegmentationImageFilter::Updat if (!this->GetMaskImage() || this->GetMaskImage()->GetPixel(ItM.GetIndex()) != NumericTraits::ZeroValue()) { - maxPosteriorSum += ItM.Get(); + maxPosteriorSum += static_cast(ItM.Get()); } } } - return maxPosteriorSum / static_cast(totalSampleSize); + return static_cast(maxPosteriorSum / static_cast(totalSampleSize)); } template