且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过MATLAB的像素位置

更新时间:2023-02-26 14:57:28

尝试在MATLAB中使用ginput(...)函数,如下所示:

Try using the ginput(...) function in MATLAB, like this:

% Load some image:
data = imread('fishy 01.jpg');

% display the image:
figure(88);
clf;
h = imagesc(data);
axis image

% Get a value from the screen:
[x, y] = ginput(1);

msgbox(['You want pixel: ' num2str(round([x,y]))]);

这将为您提供当前轴中像素的位置。或者你可以使用图形回调 WindowButtonUpFcn 获取当前数据然后,图中的鼠标位置将其转换为您想要的相对轴,然后缩放到当前轴xlim和ylim。但是ginput(1)会容易得多。

This will give you the location of the pixel in the current axis. Alternately you, could use the figure callback WindowButtonUpFcn to get the current mouse position in the figure then translate that over to the axis you want it relative to, then scale to the current axis xlim and ylim. But ginput(1) will be much easier.