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
Hi Benjamin,
To help understand what is happening, could you please post the code and data so the behavior can be reproduced?
Thanks,
Matt
Hi Matt,
thx here is basically what I am trying to do
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
here is the relevant part of my test code
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()
ahh I managed to get it to work, was a bug of mine thresholdFilter.SetLowerThreshold(100) should be threshold. closing
1 Like
@benjaminhon Great, thanks for following up with the update!