Skip to content
Snippets Groups Projects
Commit b825447b authored by Stéphane Albert's avatar Stéphane Albert
Browse files

ENH: Small optimization in mvd::HistogramModel::Percentile().

parent 537d574a
No related branches found
No related tags found
No related merge requests found
......@@ -163,19 +163,28 @@ HistogramModel
// Contruct 1D measurement vector.
assert( histogram->GetMeasurementVectorSize()==1 );
Histogram::MeasurementVectorType measurement( 1 );
measurement[ 0 ] = intensity;
// Due to float/double conversion, it can happen
// that the minimum or maximum value go slightly outside the histogram
// Clamping the value solves the issue and avoid RangeError
// itk::NumericsTraits<>::Clamp(...) was removed
// TODO : when otb::Clamp will be developped, use this function
measurement[0] =
measurement[0] < histogram->GetBinMin(0, 0)
? histogram->GetBinMin(0, 0)
: ( measurement[0] > histogram->GetBinMax(0, histogram->GetSize(0) - 1)
? histogram->GetBinMax(0, histogram->GetSize(0) - 1)
: measurement[0] );
{
assert( histogram->GetSize( 0 ) > 0 );
Histogram::MeasurementType binMin( histogram->GetBinMin( 0, 0 ) );
Histogram::MeasurementType binMax(
histogram->GetBinMax( 0, histogram->GetSize( 0 ) - 1 )
);
// Due to float/double conversion, it can happen
// that the minimum or maximum value go slightly outside the histogram
// Clamping the value solves the issue and avoid RangeError
// itk::NumericsTraits<>::Clamp(...) was removed
// TODO : when otb::Clamp will be developped, use this function
measurement[ 0 ] =
intensity < binMin
? binMin
: ( intensity > binMax
? binMax
: intensity );
}
// Get the index of measurement in 1D-histogram.
Histogram::IndexType index;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment