Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ LiThresholdCalculator<THistogram, TOutput>
double tolerance; // threshold tolerance
double temp;

// If there are negative values then shift the values to zero.
const double bin_min = std::min(histogram->GetBinMin(0,0), 0.0);

tolerance = 0.5;
num_pixels = histogram->GetTotalFrequency();

Expand All @@ -82,6 +85,12 @@ LiThresholdCalculator<THistogram, TOutput>
typename HistogramType::IndexType local_index;
histogram->GetIndex(ot, local_index);
histthresh = local_index[0];

if( histogram->IsIndexOutOfBounds(local_index) )
{
itkWarningMacro("Unexpected histogram index out of bounds!");
break;
}
}

// Calculate the means of background and object pixels
Expand Down Expand Up @@ -114,6 +123,11 @@ LiThresholdCalculator<THistogram, TOutput>
//
//#define IS_NEG( x ) ( ( x ) < -DBL_EPSILON )
//

// Shift the mean by the minimum to have the range start at zero,
// and avoid the log of a negative value.
mean_back -= bin_min;
mean_obj -= bin_min;
temp = ( mean_back - mean_obj ) / ( std::log ( mean_back ) - std::log ( mean_obj ) );

double epsilon = itk::NumericTraits<double>::epsilon();
Expand All @@ -127,6 +141,11 @@ LiThresholdCalculator<THistogram, TOutput>
}
// Stop the iterations when the difference between the new and old threshold
// values is less than the tolerance

// Shift the result back.
new_thresh += bin_min;


}
while ( std::abs ( new_thresh - old_thresh ) > tolerance );

Expand Down