Skip to content

Commit

Permalink
BUG: fix Statistics::Histogram::Mean calculation
Browse files Browse the repository at this point in the history
This method was introduced by fb95a5e,
but it never worked properly, always returning 1.
  • Loading branch information
dzenanz committed Jun 14, 2020
1 parent 0c02a5d commit 147ac45
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Modules/Filtering/Thresholding/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ itk_add_test(NAME itkIsoDataThresholdImageFilterTestNoAutoMinMax
COMMAND ITKThresholdingTestDriver
--compare-MD5 DATA{Baseline/itkIsoDataThresholdImageFilterTestNoAutoMinMax.png}
9f844fd120ff49a7812e329a1b0216d8
itkIsoDataThresholdImageFilterTest DATA{${ITK_DATA_ROOT}/Input/cthead1.png} ${ITK_TEST_OUTPUT_DIR}/itkIsoDataThresholdImageFilterTestNoAutoMinMax.png 32 0 1)
itkIsoDataThresholdImageFilterTest DATA{${ITK_DATA_ROOT}/Input/cthead1.png} ${ITK_TEST_OUTPUT_DIR}/itkIsoDataThresholdImageFilterTestNoAutoMinMax.png 32 0 1023)

itk_add_test(NAME itkIsoDataMaskedThresholdImageFilterTest
COMMAND ITKThresholdingTestDriver
Expand Down
5 changes: 3 additions & 2 deletions Modules/Numerics/Statistics/include/itkHistogram.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,12 @@ double
Histogram<TMeasurement, TFrequencyContainer>::Mean(unsigned int dimension) const
{
const unsigned int size = this->GetSize(dimension);
auto totalFrequency = double(this->GetTotalFrequency());
double totalFrequency = this->GetTotalFrequency();
double sum = 0;
for (unsigned int i = 0; i < size; i++)
{
sum += this->GetFrequency(i, dimension);
double frequency = this->GetFrequency(i, dimension);
sum += frequency * this->GetMeasurement(i, dimension);
}
return sum / totalFrequency;
}
Expand Down

0 comments on commit 147ac45

Please sign in to comment.