# Update image data in existing imshow

**URL:** <https://discourse.julialang.org/t/update-image-data-in-existing-imshow/9609>\
**Category:** Visualization\
**Tags:** question, images, gtk\
**Created:** [March 9, 2018, 12:37pm UTC](https://discourse.julialang.org/t/update-image-data-in-existing-imshow/9609 "2018-03-09T12:37:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [March 9, 2018, 12:37pm UTC](https://discourse.julialang.org/t/update-image-data-in-existing-imshow/9609/1 "2018-03-09T12:37:31Z")

</div>

Because of its zoom and pan capabilities, I’m hijacking `ImageView.imshow` as a UI for a user to pick points from an image. To accomplish that I connected to the `canvas` button presses (for more details see the [drawing example in `GtkReactive`](https://github.com/JuliaGizmos/GtkReactive.jl/blob/8179c208ff5fa16d6d4879c8dce578cc68eff59b/examples/drawing.jl#L12), and [this post](https://discourse.julialang.org/t/identify-button-modifiers-in-gtk/9411)). The presented image is a `Images.colorview` of two images. Because each of these two images can have very different intensities, I’ve added two `GtkReactive.slider`s to `ImageView.imshow`’s `window` that use `Images.imadjustintensity` to adjust each of the images’ intensity.

To update the image data I used the solution here:

> [@Update existing imshow with new image data](https://discourse.julialang.org/t/update-existing-imshow-with-new-image-data/8296/7):
>
> Here’s a way with ImageView.imshow: using ImageView, Images img = rand(640,480) guidict = ImageView.imshow(img) canvas = guidict["gui"]["canvas"] img2 = rand(640,480) ImageView.imshow(canvas, img2)

The problem with that solution is that we call `imshow(canvas, new_img)`, thus reseting the `canvas` and loosing the button-press events I connected to the previous `canvas`. So I need some way, if it exists, to either:

1. Update the image data in an existing instance of `imshow` without changing anything else in that structure.
2. Adjust the intensity in individual RGB channels (currently intensity adjusting is supported only for Gray images).

Ideally, there would be **a way to `imshow(img::Signal)` and then `push!` into that signal to update the shown image**.

Thanks…!

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [March 9, 2018, 1:24pm UTC](https://discourse.julialang.org/t/update-image-data-in-existing-imshow/9609/2 "2018-03-09T13:24:40Z")

</div>

Solved it myself!

So the image data that imshow displays is the exact data I should be changing:

```julia
data = rand(RGB, n, n)
g = imshow(data)
data[1] = RGB(1,1,1) # update the image data

```

Now nothing has yet been updated in the window, so I need to fake an update event. I do this by:

```julia
zr = g["roi"]["zoomregion"]
push!(zr, value(zr).currentview)

```

and it works!

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [March 9, 2018, 5:32pm UTC](https://discourse.julialang.org/t/update-image-data-in-existing-imshow/9609/3 "2018-03-09T17:32:22Z")

</div>

Could you share your point selection code? It’d be great to bring ImageView’s interaction facilities in line with what’s available in Matlab: [Build Interactive Tools - MATLAB & Simulink](https://www.mathworks.com/help/images/building-guis-with-modular-interactive-tools.html)

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [March 9, 2018, 8:37pm UTC](https://discourse.julialang.org/t/update-image-data-in-existing-imshow/9609/4 "2018-03-09T20:37:50Z")

</div>

Sure, but it will practically be the same as [here](https://github.com/JuliaGizmos/GtkReactive.jl/blob/8179c208ff5fa16d6d4879c8dce578cc68eff59b/examples/drawing.jl#L12). But I think you are totally correct about building these kind of tools. I’m not sure however if there will be a split between using Images, Gtk, Reactive/Observables, and GtkReactive or if Makie will take over that as well…
