# The best approach to interact with images by clicking on them and retreiving position of the pixel I clicked on

**URL:** https://discourse.julialang.org/t/the-best-approach-to-interact-with-images-by-clicking-on-them-and-retreiving-position-of-the-pixel-i-clicked-on/79078
**Category:** New to Julia
**Tags:** images
**Created:** [April 6, 2022, 1:53am UTC](https://discourse.julialang.org/t/the-best-approach-to-interact-with-images-by-clicking-on-them-and-retreiving-position-of-the-pixel-i-clicked-on/79078 "2022-04-06T01:53:26Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![MK-1138](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@MK-1138](https://discourse.julialang.org/u/MK-1138)
#### Post date: [April 6, 2022, 1:53am UTC](https://discourse.julialang.org/t/the-best-approach-to-interact-with-images-by-clicking-on-them-and-retreiving-position-of-the-pixel-i-clicked-on/79078/1 "2022-04-06T01:53:26Z")

</div>

I’m loading an image via imshow() which allows me to track coordinates of the mouse as I hover it over the image. I’m using the coordinates as inputs for some other stuff.

I wonder if it’s possible instead to display an image, click somewhere on it, and have some code pick up and store the coordinates of the pixel I clicked on.

Some similar questions I found here mention use of Gtk but I’m wondering if there is a more “natural” way to accomplish this.

I’m only asking pointers and references for what’s suitable for this purpose, not for anyone to do this for me. Thank you in advance.

---

<div class="post-metadata">

### Author: ![Ashwani\_Rathee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashwani_rathee/32/49551_2.png) [@Ashwani\_Rathee](https://discourse.julialang.org/u/Ashwani_Rathee)
#### Post date: [April 6, 2022, 4:03am UTC](https://discourse.julialang.org/t/the-best-approach-to-interact-with-images-by-clicking-on-them-and-retreiving-position-of-the-pixel-i-clicked-on/79078/2 "2022-04-06T04:03:13Z")

</div>

I think GtkReactive is what you might be looking for:  
[https://juliagizmos.github.io/GtkReactive.jl/stable/index.html](https://juliagizmos.github.io/GtkReactive.jl/stable/index.html)

Issue similiar to your problem mentioned here:  
[https://github.com/JuliaImages/ImageView.jl/issues/240](https://github.com/JuliaImages/ImageView.jl/issues/240)

---

<div class="post-metadata">

### Author: ![MK-1138](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@MK-1138](https://discourse.julialang.org/u/MK-1138)
#### Post date: [April 6, 2022, 12:42pm UTC](https://discourse.julialang.org/t/the-best-approach-to-interact-with-images-by-clicking-on-them-and-retreiving-position-of-the-pixel-i-clicked-on/79078/3 "2022-04-06T12:42:20Z")

</div>

Thank you @Ashwani_Rathee. I searched here but not at GitHub.

---

<div class="post-metadata">

### Author: ![MLackner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mlackner/32/2789_2.png) [@MLackner](https://discourse.julialang.org/u/MLackner)
#### Post date: [April 6, 2022, 2:37pm UTC](https://discourse.julialang.org/t/the-best-approach-to-interact-with-images-by-clicking-on-them-and-retreiving-position-of-the-pixel-i-clicked-on/79078/4 "2022-04-06T14:37:51Z")

</div>

`GLMakie` can also do this.

This piece of code plots a red cross on the position you click in the image:

```julia
using GLMakie

img = rand(50,50)

fig, ax = image(img)

display(fig)

on(events(fig).mousebutton, priority=0) do event
    if event.button == Mouse.left
        x, y = mouseposition(ax.scene)
        scatter!(ax, [x], [y], marker='+', color=:red, markersize=30)
    end
end

```

---

<div class="post-metadata">

### Author: ![MK-1138](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@MK-1138](https://discourse.julialang.org/u/MK-1138)
#### Post date: [April 6, 2022, 4:00pm UTC](https://discourse.julialang.org/t/the-best-approach-to-interact-with-images-by-clicking-on-them-and-retreiving-position-of-the-pixel-i-clicked-on/79078/5 "2022-04-06T16:00:29Z")

</div>

Many thanks @MLackner, I’m more comfortable working with GLMakie than Gtk. I appreciate it.
