Update image data in existing imshow



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, and this post). 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.sliders 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:

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.



Solved it myself!

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

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:

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

and it works!

Can ImageViewer be used to display dynamically changing data?

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: https://www.mathworks.com/help/images/building-guis-with-modular-interactive-tools.html


Sure, but it will practically be the same as here. 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…