问题
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?
回答1:
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.
回答2:
I think this is what you want:
A=imread('filename.jpg');
image(A)
[x,y]=ginput()
来源:https://stackoverflow.com/questions/6541444/getting-pixel-coordinates-efficiently-in-matlab