Update image with itkwidget view 3D data


I’ve recently started using the Python bindings for the latest version of ITK and it is working really great so far!

I’m currently building an interactive application for testing effects of different filters with my own reconstructed MRI data. However, when I’m using the itkwidgets view function to look at the data I’m noticing some strange behaviour when I’m updating the current image, the apparent intensity levels in the image changes, eventhough the image haven’t changed.

Example: I have produced an image as an itk image object and view it as

viewer = view(img, mode='x', vmin=0, vmax=70)

Now I add in another line to just update the viewer with the same image again, as I need to do when testing out different filters interactively, and the image comes out much darker, eventhough I have the same window levels. Any ideas why?

viewer = view(img, mode='x', vmin=0, vmax=70)
viewer.image = img               # <-- New line

For debug purpose


>>> itk.itkImagePython.itkImageD3

What I didn’t show here is that the viewer will also override the values I set for vmin and vmax when I update the image.

I got the syntax for updating the current image (viewer.image = image) from your tutorial 3 on filtering at https://github.com/KitwareMedical/CourseInBiomedicalImageAnalysisVisualizationAndArtificialIntelligence

Is there something I’m missing in terms of updating the current image?

Thank you very much!

1 Like

Hello @emilljungberg,

Welcome to the ITK community! :sun_with_face:

Excellent! :motorcycle:

Thank you for the nice description of the issue!

I was able to reproduce the reset of vmin and vmax when updating the image – a fix has been created, and it will be in a new release cut over the next few days.

Thanks @matt.mccormick,

I’m still having the issue that my image comes out much darker in the second example above even when I reset the vmin/vmax. The image the I attached has the same window limits but comes out very different for some reason. Or is this still related to the vmin/vmax being changed behind the scenes eventhuogh I adjusted it on the UI?

It could be related or an independent issue – let’s see if it persists after vmin / vmax are addressed.