Skip to content

Commit

Permalink
ENH: Propagate StatisticsLabelMapFilter's default NumberOfBins
Browse files Browse the repository at this point in the history
  • Loading branch information
Leengit committed May 4, 2021
1 parent 1fba0db commit 509751d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ BinaryImageToStatisticsLabelMapFilter<TInputImage, TFeatureImage, TOutputImage>:
m_FullyConnected = false;
m_ComputeFeretDiameter = false;
m_ComputePerimeter = true;
m_NumberOfBins = 128;
m_NumberOfBins = LabelObjectValuatorType::GetDefaultNumberOfBins();
m_ComputeHistogram = true;
this->SetNumberOfRequiredInputs(2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ LabelImageToStatisticsLabelMapFilter<TInputImage, TFeatureImage, TOutputImage>::
m_BackgroundValue = NumericTraits<OutputImagePixelType>::NonpositiveMin();
m_ComputeFeretDiameter = false;
m_ComputePerimeter = true;
m_NumberOfBins = 128;
m_NumberOfBins = LabelObjectValuatorType::GetDefaultNumberOfBins();
m_ComputeHistogram = true;
this->SetNumberOfRequiredInputs(2);
}
Expand Down
18 changes: 11 additions & 7 deletions Modules/Filtering/LabelMap/include/itkStatisticsLabelMapFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ class ITK_TEMPLATE_EXPORT StatisticsLabelMapFilter
itkSetMacro(NumberOfBins, unsigned int);
itkGetConstReferenceMacro(NumberOfBins, unsigned int);

// Set the default number of bins to match the number of values for 8 or 16-bit integers; otherwise 128
static constexpr unsigned int
GetDefaultNumberOfBins()
{
return NumericTraits<FeatureImagePixelType>::IsInteger && sizeof(FeatureImagePixelType) <= 2
? 1 << (8 * sizeof(FeatureImagePixelType))
: 128;
}

protected:
StatisticsLabelMapFilter();
~StatisticsLabelMapFilter() override = default;
Expand All @@ -149,13 +158,8 @@ class ITK_TEMPLATE_EXPORT StatisticsLabelMapFilter
private:
FeatureImagePixelType m_Minimum{ NumericTraits<FeatureImagePixelType>::ZeroValue() };
FeatureImagePixelType m_Maximum{ NumericTraits<FeatureImagePixelType>::ZeroValue() };
// Set the number of bins to match the number of values for 8,16-bit integers.
static constexpr bool m_DefaultNumberOfBinsToNumberOfValues =
NumericTraits<typename Self::FeatureImagePixelType>::IsInteger && sizeof(typename Self::FeatureImagePixelType) <= 2;
unsigned int m_NumberOfBins{ m_DefaultNumberOfBinsToNumberOfValues
? 1 << (8 * sizeof(typename Self::FeatureImagePixelType))
: 128 };
bool m_ComputeHistogram{ true };
unsigned int m_NumberOfBins{ GetDefaultNumberOfBins() };
bool m_ComputeHistogram{ true };
}; // end of class
} // end namespace itk

Expand Down

0 comments on commit 509751d

Please sign in to comment.