Index out of range error in LiThresholdCalculator


(Andras Lasso) #1

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?


How to report ITK issues
(Bradley Lowekamp) #2

Thanks for reporting the issue. Anything odd about the input data? Perhaps a constant image or something generated?


(Andras Lasso) #3

The error does not happen with all data sets, but it happens with completely normal images (for example, CTChest 3D Slicer sample data set).


(Bradley Lowekamp) #4

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.

Thanks!


(Andras Lasso) #5

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:

Thank you!


(Bradley Lowekamp) #6

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.


(Bradley Lowekamp) #7

Your image has a negative mean. The calculator tries to take the log of the foreground and background.

So that is not going to work…

I believe the method was published here:

digging


(Bradley Lowekamp) #8

http://review.source.kitware.com/#/c/23533/