# itk imageToVTKImageFilter does not seem to update vtkImageViewer2

**URL:** https://discourse.itk.org/t/itk-imagetovtkimagefilter-does-not-seem-to-update-vtkimageviewer2/395
**Category:** Beginner Questions
**Created:** [November 6, 2017, 3:10am UTC](https://discourse.itk.org/t/itk-imagetovtkimagefilter-does-not-seem-to-update-vtkimageviewer2/395 "2017-11-06T03:10:21Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![benjaminhon](https://discourse.itk.org/user_avatar/discourse.itk.org/benjaminhon/32/83_2.png) [@benjaminhon](https://discourse.itk.org/u/benjaminhon)
#### Post date: [November 6, 2017, 3:10am UTC](https://discourse.itk.org/t/itk-imagetovtkimagefilter-does-not-seem-to-update-vtkimageviewer2/395/1 "2017-11-06T03:10:21Z")

</div>

Hi I have a pipeline as follows:

itkReader -\> itkThreshold -\> itkImageToVTKImageFilter -\> vtkImageViewer2

im using SetInput, GetOutput to connect the pipeline. However, when I change the threshold parameters, and call Update on itkThreshold and itkImageToVTKImageFilter, and Render on the renderer in vtkImageViewer2, it does not seem to update the image.

Am I doing something wrong here or is it supposed to me this way?

Thanks

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [November 6, 2017, 2:06pm UTC](https://discourse.itk.org/t/itk-imagetovtkimagefilter-does-not-seem-to-update-vtkimageviewer2/395/2 "2017-11-06T14:06:30Z")

</div>

Hi Benjamin,

To help understand what is happening, could you please post the code and data so the behavior can be reproduced?

Thanks,  
Matt

---

<div class="post-metadata">

### Author: ![benjaminhon](https://discourse.itk.org/user_avatar/discourse.itk.org/benjaminhon/32/83_2.png) [@benjaminhon](https://discourse.itk.org/u/benjaminhon)
#### Post date: [November 7, 2017, 2:18am UTC](https://discourse.itk.org/t/itk-imagetovtkimagefilter-does-not-seem-to-update-vtkimageviewer2/395/3 "2017-11-07T02:18:03Z")

</div>

Hi Matt,  
thx here is basically what I am trying to do

```auto
thresholdFilter = itk.BinaryThresholdImageFilter[ItkTypes.IUC3, ItkTypes.IUC3].New()
thresholdFilter.SetInput(rescaler.GetOutput())
thresholdFilter.SetLowerThreshold(100)
thresholdFilter.SetUpperThreshold(255)
thresholdFilter.SetOutsideValue(0)
thresholdFilter.SetInsideValue(1)

...

imageToVTKImageFilter = itk.ImageToVTKImageFilter[Some.type].New()
imageToVTKImageFilter.SetInput(SomeITKFilter.GetOutput())

...

imageViewer = vtk.vtkImageViewer2()
imageViewer.SetInputData(imageToVTKImageFilter.GetOutput())

```

On some event, I will change thresholdFilter.SetLowerThreshold(ToSomeValue) and call Update on imageToVTKImageFilter. Then I will call Render on imageViewer, but it doesn’t seem to be rerendering

---

<div class="post-metadata">

### Author: ![benjaminhon](https://discourse.itk.org/user_avatar/discourse.itk.org/benjaminhon/32/83_2.png) [@benjaminhon](https://discourse.itk.org/u/benjaminhon)
#### Post date: [November 7, 2017, 6:17am UTC](https://discourse.itk.org/t/itk-imagetovtkimagefilter-does-not-seem-to-update-vtkimageviewer2/395/4 "2017-11-07T06:17:49Z")

</div>

here is the relevant part of my test code

```auto
NII_PATH = os.path.join(os.getcwd(), 'notebooks/220259.nii')
DICOM_PATH = os.path.join(os.getcwd(), 'notebooks/220259')
(series, seriesUIDs) = generateSeries(DICOM_PATH)

imageSeriesReader = itk.ImageSeriesReader[ItkTypes.IF3].New()
imageSeriesReader.SetFileNames(series[seriesUIDs[2]])
imageSeriesReader.Update()

rescaler = itk.RescaleIntensityImageFilter[ItkTypes.IF3, ItkTypes.IF3].New()
rescaler.SetInput(imageSeriesReader.GetOutput())
rescaler.SetOutputMaximum(255)
rescaler.SetOutputMinimum(0)
rescaler.Update()

caster = itk.CastImageFilter[ItkTypes.IF3, ItkTypes.IUC3].New()
caster.SetInput(rescaler.GetOutput())
caster.Update()

thresholdFilter = itk.BinaryThresholdImageFilter[ItkTypes.IUC3, ItkTypes.IUC3].New()
thresholdFilter.SetInput(caster.GetOutput())
thresholdFilter.SetLowerThreshold(100)
thresholdFilter.SetUpperThreshold(255)
thresholdFilter.SetOutsideValue(0)
thresholdFilter.SetInsideValue(1)
thresholdFilter.Update()

labelImageToLabelMapFilter = itk.LabelImageToLabelMapFilter[ItkTypes.IUC3, ItkTypes.LMLOUL3].New()
labelImageToLabelMapFilter.SetInput(thresholdFilter.GetOutput())
labelImageToLabelMapFilter.Update()

labelMapToRGBImageFilter = itk.LabelMapToRGBImageFilter[ItkTypes.LMLOUL3, ItkTypes.IRGBUC3].New()
labelMapToRGBImageFilter.SetInput(labelImageToLabelMapFilter.GetOutput())
labelMapToRGBImageFilter.Update()

imageToVTKImageFilter = itk.ImageToVTKImageFilter[ItkTypes.IRGBUC3].New()
imageToVTKImageFilter.SetInput(labelMapToRGBImageFilter.GetOutput())
imageToVTKImageFilter.Update()

app = QApplication([])

viewer = Viewer()
viewer.setMinimumWidth(400)
viewer.setMinimumHeight(300)

imageViewer = vtk.vtkImageViewer2()
imageViewer.SetRenderWindow(viewer.GetRenderWindow())

# viewer.AddRenderer(imageViewer.GetRenderer())

imageViewer.SetInputData(imageToVTKImageFilter.GetOutput())

imageViewer.Render()

viewer.show()
viewer.startEventLoop()

sys.exit(app.exec_())

...

threshold = 100
def shiftThreshold(t):
  global threshold 
  threshold = threshold + t
  thresholdFilter.SetLowerThreshold(100)
  print(threshold)
  thresholdFilter.Update()
  imageToVTKImageFilter.Update()
  imageViewer.Render()

```

---

<div class="post-metadata">

### Author: ![benjaminhon](https://discourse.itk.org/user_avatar/discourse.itk.org/benjaminhon/32/83_2.png) [@benjaminhon](https://discourse.itk.org/u/benjaminhon)
#### Post date: [November 8, 2017, 7:27am UTC](https://discourse.itk.org/t/itk-imagetovtkimagefilter-does-not-seem-to-update-vtkimageviewer2/395/5 "2017-11-08T07:27:48Z")

</div>

ahh I managed to get it to work, was a bug of mine thresholdFilter.SetLowerThreshold(100) should be threshold. closing

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [November 8, 2017, 2:01pm UTC](https://discourse.itk.org/t/itk-imagetovtkimagefilter-does-not-seem-to-update-vtkimageviewer2/395/6 "2017-11-08T14:01:25Z")

</div>

@benjaminhon Great, thanks for following up with the update!
