# Update existing imshow with new image data

**URL:** <https://discourse.julialang.org/t/update-existing-imshow-with-new-image-data/8296>\
**Category:** General Usage\
**Tags:** question, images, visualization\
**Created:** [January 11, 2018, 8:04pm UTC](https://discourse.julialang.org/t/update-existing-imshow-with-new-image-data/8296 "2018-01-11T20:04:48Z")\
**Posts on this page:** 12\
**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:** [January 11, 2018, 8:04pm UTC](https://discourse.julialang.org/t/update-existing-imshow-with-new-image-data/8296/1 "2018-01-11T20:04:48Z")

</div>

I want to set up a rapid loop of updating a screen with some image data and then fetching the result with a webcam that is pointed at the screen (the idea is to sample hundreds of cycles, change some external filter between the screen and camera, and sample again).

**How can I update an already existing `imshow` `Dict` with new image data?** The new data has the same dimensions and type as the old one. The updated `imshow` window should _not_ move in relation to the physical screen from update to update.

I’m convinced that I need to connect the call to `imshow` with a `Signal` of an image, and then just `push!` to that signal, but I can’t get it to work…

Thanks!!!

---

<div class="post-metadata">

**Author:** ![ssfrr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssfrr/32/3736_2.png) [@ssfrr](https://discourse.julialang.org/u/ssfrr)\
**Post date:** [January 11, 2018, 8:13pm UTC](https://discourse.julialang.org/t/update-existing-imshow-with-new-image-data/8296/2 "2018-01-11T20:13:35Z")

</div>

Not sure what plotting library you’re using, but I’ve been playing around with Makie.jl for this sort of thing and it’s great (though still in development).

I’ve got [some code here](https://gist.github.com/ssfrr/89f6e4a0de6eec1828901fffdfbd286a) that updates a `heatmap` display with a 2D matrix representing an scrolling audio spectrogram, which seems to perform really well.

---

<div class="post-metadata">

**Author:** ![ssfrr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssfrr/32/3736_2.png) [@ssfrr](https://discourse.julialang.org/u/ssfrr)\
**Post date:** [January 11, 2018, 8:16pm UTC](https://discourse.julialang.org/t/update-existing-imshow-with-new-image-data/8296/3 "2018-01-11T20:16:02Z")

</div>

Also note that code isn’t a particularly great audio DSP example because it doesn’t do any windowing so there’s a lot of spectral leakage. It should get the point across, though

---

<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:** [January 11, 2018, 8:29pm UTC](https://discourse.julialang.org/t/update-existing-imshow-with-new-image-data/8296/4 "2018-01-11T20:29:51Z")

</div>

Cool! Well, because I’m only updating an image, I thought `ImageView.imshow` would do. But I’ve been meaning to try `Makie` for a while now, so maybe this should be it!

---

<div class="post-metadata">

**Author:** ![ssfrr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssfrr/32/3736_2.png) [@ssfrr](https://discourse.julialang.org/u/ssfrr)\
**Post date:** [January 11, 2018, 8:46pm UTC](https://discourse.julialang.org/t/update-existing-imshow-with-new-image-data/8296/5 "2018-01-11T20:46:17Z")

</div>

I do think there’s a way to get ImageView to do what you want, I’m pretty sure I’ve seen Tim demo animations and videos before. Unhelpfully I don’t know how though. 🙁

---

<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:** [January 11, 2018, 8:48pm UTC](https://discourse.julialang.org/t/update-existing-imshow-with-new-image-data/8296/6 "2018-01-11T20:48:21Z")

</div>

Same here 🙂

Maybe someone will. Thanks for the Makie tip though!

---

<div class="post-metadata">

**Author:** ![tshort](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tshort/32/43_2.png) [@tshort](https://discourse.julialang.org/u/tshort)\
**Post date:** [January 12, 2018, 3:15pm UTC](https://discourse.julialang.org/t/update-existing-imshow-with-new-image-data/8296/7 "2018-01-12T15:15:59Z")

</div>

Here’s a way with `ImageView.imshow`:

```julia
using ImageView, Images
img = rand(640,480)
guidict = ImageView.imshow(img)
canvas = guidict["gui"]["canvas"]
img2 = rand(640,480)
ImageView.imshow(canvas, img2)

```

---

<div class="post-metadata">

**Author:** ![tshort](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tshort/32/43_2.png) [@tshort](https://discourse.julialang.org/u/tshort)\
**Post date:** [January 12, 2018, 3:51pm UTC](https://discourse.julialang.org/t/update-existing-imshow-with-new-image-data/8296/8 "2018-01-12T15:51:37Z")

</div>

I think this is how you do the same thing with Makie:

```julia
using Makie, FileIO, GeometryTypes, Colors
scene = Scene(resolution = (500, 500), color = :black);
img = rand(RGB{N0f8}, 256, 256);
image(img);
center!(scene);
img2 = rand(RGB{N0f8}, 256, 256);
image(img2);

```

(I overloaded on the semicolons at the line ends because some of these spit out pretty big output at the REPL.)

---

<div class="post-metadata">

**Author:** ![ssfrr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssfrr/32/3736_2.png) [@ssfrr](https://discourse.julialang.org/u/ssfrr)\
**Post date:** [January 12, 2018, 4:01pm UTC](https://discourse.julialang.org/t/update-existing-imshow-with-new-image-data/8296/9 "2018-01-12T16:01:55Z")

</div>

rather than creating a new `image` object you can just update the data for the existing one with `img = image(olddata); img[:image] = newdata`. Not sure how much overhead this saves, but I’d guess it’s at least slightly more efficient. This might act strangely if the image size changes though.

---

<div class="post-metadata">

**Author:** ![tshort](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tshort/32/43_2.png) [@tshort](https://discourse.julialang.org/u/tshort)\
**Post date:** [January 12, 2018, 6:06pm UTC](https://discourse.julialang.org/t/update-existing-imshow-with-new-image-data/8296/10 "2018-01-12T18:06:18Z")

</div>

> [@ssfrr](#):
>
> img = image(olddata); img[:image] = newdata

Thanks @ssfrr, that approach is much faster with Makie.

---

<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:** [January 13, 2018, 4:56am UTC](https://discourse.julialang.org/t/update-existing-imshow-with-new-image-data/8296/11 "2018-01-13T04:56:15Z")

</div>

Cool guys!!! Thanks!

---

<div class="post-metadata">

**Author:** ![AlfTetzlaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alftetzlaff/32/13124_2.png) [@AlfTetzlaff](https://discourse.julialang.org/u/AlfTetzlaff)\
**Post date:** [January 9, 2020, 2:18pm UTC](https://discourse.julialang.org/t/update-existing-imshow-with-new-image-data/8296/12 "2020-01-09T14:18:59Z")

</div>

When this is called in a loop RAM is slowly filled until it is full. Didnt find a solution yet.
