Home > Mobile >  How to obtain the coordinates in a MATLAB image as I move the cursor of the mouse on it?
How to obtain the coordinates in a MATLAB image as I move the cursor of the mouse on it?

Time:06-05

I have obtained the following image (which is a binary). I would like to know if there is a way to get the coordinates of the pink lines in the MATLAB plot, so that as I move the mouse cursor in the matlab plot, I get information about the current coordinates that I am pointing with the mouse.

generalized voronoi diagram quota 90

CodePudding user response:

You can use the drawcrosshair() function to get the coordinates of any location on an image.

For example,

figure
imshow(myImage) %generates a figure that shows your figure (maybe myImage is a 2-dimensional matrix)
ch = drawcrosshair(); %click on a location in the image that you would like to get the coordinates for
p = round(ch.Position); %grab the (rounded) coordinates of the crosshair location

If you also put in some code to find where the pink lines are, perhaps using a simple color matching, e.g.

pinkIndices = find((img(:, :, 1) == 1) & (img(:, :, 2) == 0) & (img(:, :, 3) == 1)); %pink when red and blue channels == 1 but green channel == 0

then you could use these "pinkIndices" to round to the nearest known pink index instead of simply rounding to the nearest integer (as the first set of code above does).

Note that this method only gives you the location of your cursor after a click is performed, but you can put code like this into a loop in order to generate something that reports the new location of your cursor after every click. You could also try automating clicks on every change of mouse position (see here) but that might be more trouble than it's worth.

  • Related