# Update image within itkwidgets.view

**URL:** <https://discourse.itk.org/t/update-image-within-itkwidgets-view/5366>\
**Category:** Beginner Questions\
**Created:** [September 26, 2022, 3:02pm UTC](https://discourse.itk.org/t/update-image-within-itkwidgets-view/5366 "2022-09-26T15:02:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Sweeney](https://discourse.itk.org/user_avatar/discourse.itk.org/kevin_sweeney/32/2947_2.png) [@Kevin\_Sweeney](https://discourse.itk.org/u/Kevin_Sweeney)\
**Post date:** [September 26, 2022, 3:02pm UTC](https://discourse.itk.org/t/update-image-within-itkwidgets-view/5366/1 "2022-09-26T15:02:57Z")

</div>

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

If I run the following, it shows as expected:

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

```

 ![Screenshot 2022-09-26 at 15.59.48](https://discourse.itk.org/uploads/default/original/2X/2/28fdd9d3ea0726b8da3e4fdcd7c8aaa798dd17f4.png)

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.

```auto
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

 ![Screenshot 2022-09-26 at 16.01.19](https://discourse.itk.org/uploads/default/original/2X/0/0af2dccc61ad4027930e3f753b87979524e080f4.png) After ![Screenshot 2022-09-26 at 16.01.59](https://discourse.itk.org/uploads/default/original/2X/1/12e5d0d8b161fc83fbcbc5dac36ea805bea7e0d2.png)

Am I missing something needed to update the image part?

Many thanks

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [September 26, 2022, 3:07pm UTC](https://discourse.itk.org/t/update-image-within-itkwidgets-view/5366/2 "2022-09-26T15:07:06Z")

</div>

@PaulHax can you answer?

---

<div class="post-metadata">

**Author:** ![PaulHax](https://discourse.itk.org/user_avatar/discourse.itk.org/paulhax/32/2949_2.png) [@PaulHax](https://discourse.itk.org/u/PaulHax)\
**Post date:** [September 26, 2022, 6:38pm UTC](https://discourse.itk.org/t/update-image-within-itkwidgets-view/5366/3 "2022-09-26T18:38:54Z")

</div>

Hello, I am not to familiar with itkwidgets but I would try activeView.set\_image(new\_image), if you have not already.

---

<div class="post-metadata">

**Author:** ![Kevin\_Sweeney](https://discourse.itk.org/user_avatar/discourse.itk.org/kevin_sweeney/32/2947_2.png) [@Kevin\_Sweeney](https://discourse.itk.org/u/Kevin_Sweeney)\
**Post date:** [September 26, 2022, 8:47pm UTC](https://discourse.itk.org/t/update-image-within-itkwidgets-view/5366/4 "2022-09-26T20:47:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [September 26, 2022, 8:49pm UTC](https://discourse.itk.org/t/update-image-within-itkwidgets-view/5366/5 "2022-09-26T20:49:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kevin\_Sweeney](https://discourse.itk.org/user_avatar/discourse.itk.org/kevin_sweeney/32/2947_2.png) [@Kevin\_Sweeney](https://discourse.itk.org/u/Kevin_Sweeney)\
**Post date:** [September 26, 2022, 9:01pm UTC](https://discourse.itk.org/t/update-image-within-itkwidgets-view/5366/6 "2022-09-26T21:01:03Z")

</div>

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:

```auto
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:

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

display(activeView1)

```

… and then I try to update:

```auto
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)

---

<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:** [September 27, 2022, 1:58pm UTC](https://discourse.itk.org/t/update-image-within-itkwidgets-view/5366/7 "2022-09-27T13:58:55Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Kevin\_Sweeney](https://discourse.itk.org/user_avatar/discourse.itk.org/kevin_sweeney/32/2947_2.png) [@Kevin\_Sweeney](https://discourse.itk.org/u/Kevin_Sweeney)\
**Post date:** [September 27, 2022, 2:22pm UTC](https://discourse.itk.org/t/update-image-within-itkwidgets-view/5366/8 "2022-09-27T14:22:36Z")

</div>

Thanks @matt.mccormick
