Skip to content

Commit 147ac45

Browse files
committed
BUG: fix Statistics::Histogram::Mean calculation
This method was introduced by fb95a5e, but it never worked properly, always returning 1.
1 parent 0c02a5d commit 147ac45

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Modules/Filtering/Thresholding/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ itk_add_test(NAME itkIsoDataThresholdImageFilterTestNoAutoMinMax
121121
COMMAND ITKThresholdingTestDriver
122122
--compare-MD5 DATA{Baseline/itkIsoDataThresholdImageFilterTestNoAutoMinMax.png}
123123
9f844fd120ff49a7812e329a1b0216d8
124-
itkIsoDataThresholdImageFilterTest DATA{${ITK_DATA_ROOT}/Input/cthead1.png} ${ITK_TEST_OUTPUT_DIR}/itkIsoDataThresholdImageFilterTestNoAutoMinMax.png 32 0 1)
124+
itkIsoDataThresholdImageFilterTest DATA{${ITK_DATA_ROOT}/Input/cthead1.png} ${ITK_TEST_OUTPUT_DIR}/itkIsoDataThresholdImageFilterTestNoAutoMinMax.png 32 0 1023)
125125

126126
itk_add_test(NAME itkIsoDataMaskedThresholdImageFilterTest
127127
COMMAND ITKThresholdingTestDriver

Modules/Numerics/Statistics/include/itkHistogram.hxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,12 @@ double
645645
Histogram<TMeasurement, TFrequencyContainer>::Mean(unsigned int dimension) const
646646
{
647647
const unsigned int size = this->GetSize(dimension);
648-
auto totalFrequency = double(this->GetTotalFrequency());
648+
double totalFrequency = this->GetTotalFrequency();
649649
double sum = 0;
650650
for (unsigned int i = 0; i < size; i++)
651651
{
652-
sum += this->GetFrequency(i, dimension);
652+
double frequency = this->GetFrequency(i, dimension);
653+
sum += frequency * this->GetMeasurement(i, dimension);
653654
}
654655
return sum / totalFrequency;
655656
}

0 commit comments

Comments
 (0)