I need to make an interactive plot that takes mouse clicks on an image plot as input. There will be a series of plots with an image on top and a ‘Done’ button at the bottom. The program should plot each image in its own window (one after another in a loop), and then a person clicks on the image and only the last mouse click should be plotted on the image. Once the scatter point is correct, click ‘Done’ and the window closes, and then the next image gets plotted until it reaches the end. I have found a way to plot one image and how to close the window, but I’m not sure how to exit out of the code and return the final scatter point location in each image.
Any input or comments on what I have so far would be appreciated. GLMakie wizards, I need your help!!
Here’s what I have so far:
using GLMakie, Images
GLMakie.activate!()
image_name = "IMG.tif"
img = load(image_name)
function makefig(img,image_name)
target = Observable(Point2f[])
fig = Figure(resolution = (1600, 900))
image(fig[1,1],img,
axis = (title = image_name, aspect = DataAspect()))
xlims!(1,size(img,1)), ylims!(1,size(img,2))
fig[2,1] = buttongrid = GridLayout(tellwidth = false)
buttons = buttongrid[1, 1] = [
Button(fig, label = "Done",
height = 60, width = 250, fontsize = 30)]
fig[2,1] = GridLayout(height = 150)
display(fig)
return fig, buttons, target
end
function return_mouse_position(img, image_name)
fig, buttons, target = makefig(img,image_name)
ax = content(fig[1,1])
Makie.deactivate_interaction!(ax, :rectanglezoom)
open_window = fig.scene.events.window_open
on(events(ax).mousebutton) do event
if event.button == Mouse.left && event.action == Mouse.press
mp = mouseposition(ax)
pushfirst!(target[],mp),
notify(target)
scatter!(ax, target;
marker = :circle, strokewidth = 2,
strokecolor = :red, color = :black, markersize = [12])
end
on(buttons[1].clicks) do click
open_window[] = false
end
off(events(ax).mousebutton)
end
return mp
end
mouse_location = return_mouse_position(img,image_name)
[I’m running Julia @v1.8 on Windows 10 and using GLMakie@v0.8.2]