# vtkITKImageThresholdCalculator failure - due to ITK update?

**URL:** <https://discourse.slicer.org/t/vtkitkimagethresholdcalculator-failure-due-to-itk-update/8251>\
**Category:** Development\
**Tags:** itk\
**Created:** [September 1, 2019, 2:06pm UTC](https://discourse.slicer.org/t/vtkitkimagethresholdcalculator-failure-due-to-itk-update/8251 "2019-09-01T14:06:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 1, 2019, 2:06pm UTC](https://discourse.slicer.org/t/vtkitkimagethresholdcalculator-failure-due-to-itk-update/8251/1 "2019-09-01T14:06:15Z")

</div>

vtkITKImageThresholdCalculator fails with errors like this recently (and crashes or just provides invalid result):

```auto
Failed to compute threshold value using method Shanbhag. Details: 
itk::ExceptionObject (00000076F88F6C90)
Location: "void __cdecl itk::ImageConstIterator<class itk::Image<int,3> >::SetRegion(const class itk::ImageRegion<3> &)" 
File: c:\d\s4d\itk\modules\core\common\include\itkImageConstIterator.h
Line: 210
Description: itk::ERROR: Region ImageRegion (00000076F88F6E68)
  Dimension: 3
  Index: [0, 0, 0]
  Size: [512, 512, 9]
 is outside of buffered region ImageRegion (0000019E5F947430)
  Dimension: 3
  Index: [0, 0, 0]
  Size: [0, 0, 0]

```

It still worked fine in Slicer 4.11.0-2019-08-11 (revision 28433), so I guess it is due to recent ITK updates.

How to reproduce: Load a volume, go to segment editor, select Threshold effect, click on left or right arrow buttons in “Automatic threshold” row.

**Does anyone have a clue why could this happen? I don’t see anything special in [vtkITKImageThresholdCalculator.cxx](https://github.com/Slicer/Slicer/blob/master/Libs/vtkITK/vtkITKImageThresholdCalculator.cxx) that I would expect to break due to an ITK update.**

@jcfr @Sam_Horvath @pieper@hjmjohnson

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [September 1, 2019, 3:04pm UTC](https://discourse.slicer.org/t/vtkitkimagethresholdcalculator-failure-due-to-itk-update/8251/2 "2019-09-01T15:04:04Z")

</div>

I have no idea. Adding @thewtex and @blowekamp to the list of people who might be able to help.

---

<div class="post-metadata">

**Author:** ![thewtex](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/thewtex/32/32_2.png) [@thewtex](https://discourse.slicer.org/u/thewtex)\
**Post date:** [September 2, 2019, 12:27am UTC](https://discourse.slicer.org/t/vtkitkimagethresholdcalculator-failure-due-to-itk-update/8251/3 "2019-09-02T00:27:48Z")

</div>

@blowekamp may know – this change may be involved:

> <https://github.com/InsightSoftwareConsortium/ITK/commit/9bb0f0cc4bc65b80461ca0027c252dc6d16440b4#diff-b6070cacd90df4d5a68edbaa6b688db4>

---

<div class="post-metadata">

**Author:** ![blowekamp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/blowekamp/32/1386_2.png) [@blowekamp](https://discourse.slicer.org/u/blowekamp)\
**Post date:** [September 3, 2019, 8:32pm UTC](https://discourse.slicer.org/t/vtkitkimagethresholdcalculator-failure-due-to-itk-update/8251/4 "2019-09-03T20:32:58Z")

</div>

As Matt pointed out in the PR the base class of the `ImageToHistogramFilter` was changed to a the new `ImageSink` which add streaming pipelining support. So the method called in the ITK pipeline may be a little different from ITKv4.

I expect the quick solution is to add `itkImporter->UpdateLargestPossibleRegion()` after it’s connected to VTK.

What is wrong with the pipeline connectivity to cause this to be needed is a harder question.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 4, 2019, 3:53am UTC](https://discourse.slicer.org/t/vtkitkimagethresholdcalculator-failure-due-to-itk-update/8251/5 "2019-09-04T03:53:45Z")

</div>

@blowekamp @thewtex @pieper Thanks for your help!

Adding `UpdateLargestPossibleRegion()` indeed [fixed the problem](https://github.com/Slicer/Slicer/commit/f45acbfddaae5d356c8b1523351a4545f48ac05b).

It would be useful if the filter would run on the largest possible region by default.

---

<div class="post-metadata">

**Author:** ![blowekamp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/blowekamp/32/1386_2.png) [@blowekamp](https://discourse.slicer.org/u/blowekamp)\
**Post date:** [September 4, 2019, 2:16pm UTC](https://discourse.slicer.org/t/vtkitkimagethresholdcalculator-failure-due-to-itk-update/8251/6 "2019-09-04T14:16:06Z")

</div>

> [@lassoan](#):
>
> It would be useful if the filter would run on the largest possible region by default.

Of course it should work without this extra call. I narrowed down the issue to streamed execution and the computation of the extrema with the `AutoMinimumMaximum` option enabled. So it’s not related to the VTK/ITK pipeline interaction as first susspected. I will work on a patch to fix this in ITK.
