通过MATLAB的像素位置

Moe*_*Moe 4 matlab image image-processing

我正在开展一个项目,我必须通过MATLAB使用附加的相机在平台上找到某个对象.我想过将平台用作网格,但我被告知使用相机的像素,我可以通过点击相机窗口/屏幕并选择某个像素(对象的位置)来精确地获得该位置将在相机窗口/屏幕上显示).

有没有办法计算对象的位置(点击像素)或有什么方法可以做到这一点?

Ste*_*eve 6

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

% 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]))]);
Run Code Online (Sandbox Code Playgroud)

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

示例运行