簡體   English   中英

當我在 MATLAB 圖像上移動鼠標光標時,如何獲取坐標?

[英]How to obtain the coordinates in a MATLAB image as I move the cursor of the mouse on it?

我獲得了以下圖像(這是一個二進制文件)。 我想知道是否有一種方法可以獲取 MATLAB 圖中粉紅色線的坐標,這樣當我在 matlab 圖中移動鼠標光標時,我可以獲得有關我用鼠標指向的當前坐標的信息.

廣義 voronoi 圖配額 90

您可以使用drawcrosshair()函數來獲取圖像上任何位置的坐標。

例如,

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

如果您還輸入一些代碼來查找粉紅色線條的位置,也許使用簡單的顏色匹配,例如

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

那么您可以使用這些“pinkIndices”四舍五入到最接近的已知粉色索引,而不是簡單地四舍五入到最接近的整數(如上面的第一組代碼所做的那樣)。

請注意,此方法僅在執行單擊后為您提供光標的位置,但您可以將這樣的代碼放入循環中,以生成在每次單擊后報告光標新位置的內容。 您也可以嘗試在每次更改鼠標位置時自動單擊(請參閱此處),但這可能比它的價值更麻煩。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM