# ImageView update image

**URL:** https://discourse.julialang.org/t/imageview-update-image/16737
**Category:** Visualization
**Created:** [October 24, 2018, 1:50pm UTC](https://discourse.julialang.org/t/imageview-update-image/16737 "2018-10-24T13:50:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![harven](https://avatars.discourse-cdn.com/v4/letter/h/3da27b/32.png) [@harven](https://discourse.julialang.org/u/harven)
#### Post date: [October 24, 2018, 1:50pm UTC](https://discourse.julialang.org/t/imageview-update-image/16737/1 "2018-10-24T13:50:46Z")

</div>

I have an img that I display using `ImageView.imshow(img)`. When img is modified, I would like to tell imshow to update the image. A thread on discourse suggest to call again imshow as follows.

> canvas = imshow(img)[“gui”][“canvas”]  
> … some modification to img  
> imshow(canvas, img)

Unfortunately the second call to imshow is slow.  
If instead I update the margins of the canvas, the redraw is faster (x10 at least)

> Gtk.set\_gtk\_property!(canvas, :margin\_top, some\_value)

The problem is, I don’t want to change the margins! There should be another way to get a quick update of the image but I can’t find it. Any idea?

---

<div class="post-metadata">

### Author: ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)
#### Post date: [October 25, 2018, 8:28am UTC](https://discourse.julialang.org/t/imageview-update-image/16737/2 "2018-10-25T08:28:14Z")

</div>

There’s a bit of documentation about precisely this with `?imshow`, but perhaps it’s a bit too terse for it to be obvious. I improved the docstrings for `imshow` and `imshow!`, and in responding to this I noticed a bug; you’ll get all of this if you update your package(s).

Want to see if you can figure it out now? (Hint: check docstrings for `imshow` and `imshow!`, which is a lower-level approach.) I’m not being deliberately cagey, I’m deliberately using you as a testcase to see if the documentation is good enough now. If not, a PR would be appreciated!

My results:

```julia
julia> @time for i in axes(mri, 3); push!(imgsig, view(mri, :, :, i)); sleep(0.005); end
  0.168816 seconds (2.10 k allocations: 26.071 MiB, 1.43% gc time)

```

which since there are 27 frames is dominated by the `sleep`.

That doesn’t mean that there isn’t performance work to be done on ImageView, but perhaps it’s good enough for your purposes.

---

<div class="post-metadata">

### Author: ![harven](https://avatars.discourse-cdn.com/v4/letter/h/3da27b/32.png) [@harven](https://discourse.julialang.org/u/harven)
#### Post date: [October 25, 2018, 5:09pm UTC](https://discourse.julialang.org/t/imageview-update-image/16737/3 "2018-10-25T17:09:28Z")

</div>

Thanks for your answer.

Yes, the documentation of `imshow` is clear now and I get the same performance by pushing the image onto the Signal than by resizing the margins. Note that in the docstring example of `imshow`, you may want to add GtkReactive to the list of library used since `Signal` is part of it.

> @doc imshow
> 
> […]
> 
> Example  
> ≡≡≡≡≡≡≡≡≡
> 
> using ImageView, TestImages, Gtk # ← GtkReactive is also used in the example.  
> mri = testimage(“mri”);  
> […]  
> imgsig = Signal(mri[:,:,1]) # GtkReactive.Signal here

Is there a way to catch and update the signal from the output of imshow without using Gtk and GtkReactive? I tried to push onto `guidict["roi"]["image roi"]` without success.

> let img = rand(600,600),  
> guidict = imshow(img),  
> canvas = guidict[“gui”][“canvas”],  
> signal = guidict[“roi”][“image roi”]  
> sleep(1)  
> img[:,:] .= 0  
> sleep(1)  
> push!(signal, img) # imshow!(canvas, img) works  
> sleep(1)  
> “done”  
> end

---

<div class="post-metadata">

### Author: ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)
#### Post date: [October 25, 2018, 7:39pm UTC](https://discourse.julialang.org/t/imageview-update-image/16737/4 "2018-10-25T19:39:50Z")

</div>

> [@harven](#):
>
> Note that in the docstring example of `imshow` , you may want to add GtkReactive to the list of library used since `Signal` is part of it

Doesn’t have to be me, _anyone_ can do this if they have a web browser: [Editing files - GitHub Docs](https://help.github.com/articles/editing-files-in-your-repository/). People unfamiliar with the code can make awesome documentation improvements since they catch errors that the developer might not (like in this case).
