Update image within itkwidgets.view

I am using itkwidgets.view to show a .vtk object in Jupyter.

If I run the following, it shows as expected:

image = itk.imread('exampleImageData/mri.vtk')
self.activeView = itkwidgets.view(image=image, rotate=True, background=[0.3, 0.3, 0.3])

However, if I set the view to be blank to start, i.e. self.activeView = itkwidgets.view(image=None, ...) and then try to update the image at a later time it does not work.

image = itk.imread('exampleImageData/mri.vtk')
self.activeView.image = image
self.activeView.background = [1.0, 1.0, 1.0]
self.activeView.rotate = False

In the case shown, the view background does indeed change colour and the rotation stops, but I do not see the desired .vtk object.

Before

After

Am I missing something needed to update the image part?

Many thanks

@PaulHax can you answer?

Hello, I am not to familiar with itkwidgets but I would try activeView.set_image(new_image), if you have not already.

Thanks @PaulHax but unfortunately not
AttributeError: 'Viewer' object has no attribute 'set_image'

Maybe self.activeView.image = None, followed by self.activeView.image = image?

Thanks again @dzenanz but not working. I have pulled the code out into a Jupyter notebook with the following cells to ensure that I am doing nothing silly

This works fine:

import ipywidgets, itk, itkwidgets

image = itk.imread('exampleImageData/mri.vtk')
activeView = itkwidgets.view(image=image, rotate=True, background=[0.3, 0.3, 0.3])

display(activeView)

This creates a ‘blank’ view with a grey background:

activeView1 = itkwidgets.view(image=None, rotate=True, background=[0.3, 0.3, 0.3])

display(activeView1)

… and then I try to update:

activeView1.image = None

activeView1.image = image
activeView1.background = [1.0, 1.0, 1.0]
activeView1.rotate = False

display(activeView1)

Result is as before. Background changes colour to white and rotation stops (as can be seen from the axis symbols on bottom left)

Hi @Kevin_Sweeney ,

With itkwidgets-0.X, the image must be passed on initialization. This limitation has been removed in itkwidgets-1.X (under heavy development).

2 Likes

Thanks @matt.mccormick