I’ve added automatic thresholding to 3D Slicer’s segment editor and while testing it, I’ve got index out of range errors due to writing past the last element in a vector in LiThresholdCalculator<THistogram, TOutput>::GenerateData(void) in this line 94.
Exception thrown at 0x00007FFBF90CF218 in SlicerApp-real.exe: Microsoft C++ exception: itk::InvalidArgumentError at memory location 0x0000008369534A38.
For example, size of histogram was 64 (value of size variable was 64) and when I got the error when ih variable value was 64.
I don’t have time to further analyze this, but solution could be to add check to make sure that ih is lower that size (it is done later in the code). Or, maybe ih <= histthresh should be changed to ih < histthresh?
One more question, are you using the Calculator directly? And computing the histogram bounds yourself?
If you could provide a self contained example or reference the code that produces the problem, that would be great!. I’d like to closely look at this case to determine if the problem is just the access or if there a erroneous computation before hand, or if this is some type of degenerate case that need a special case.
I’ve noticed the error when used the calculator directly (in Segment editor in Slicer), but you can reproduce it when using through LiThresholdImageFilter (Simple Filters module) in debug mode.
How to reproduce:
Use LiThresholdImageFilter or calculator in debug mode in VisualStudio (or other compiler/settings that performs index range checks)
Great! I’ll look into this issue this week and dig into the formulation to see if there a a numeric error or some type of off by one error in the implementation.