3
votes

I would like to create a function in Matlab that, given an image, will allow one to select a pixel by clicking on it in the image and return the coordinates of the pixel. Ideally, one would be able to click on several pixels in the image in succession, and the function would store all the respective coordinates in a matrix. Is there a way to do this in Matlab?

2

2 Answers

8
votes

ginput

Graphical input from mouse or cursor Syntax

    [x,y] = ginput(n) 
    [x,y] = ginput 
    [x,y,button] = ginput(...)

Description

[x,y] = ginput(n) enables you to identify n points from the current axes and returns their x- and y-coordinates in the x and y column vectors. Press the Return key to terminate the input before entering n points.

-1
votes

I think this is what you want:

A=imread('filename.jpg');
image(A)
[x,y]=ginput()