从matlab中的图像中的任何对象获取信息
问题描述:
我从事基于颜色对象的图像分割。现在我需要获取用户对对象的单击值以便在另一个对象中使用此信息(单击值)处理。我如何在matlab中获得这个值。任何人都可以帮助我。从matlab中的图像中的任何对象获取信息
问候
答
如果您希望用户点击一个情节或图像,让他们点击的坐标,您可以使用ginput。例如,
[x,y] = ginput(1);
会给你一个点击的坐标。然后,您可以使用自己的逻辑来确定与哪个对象相对应。
如果这不是你想要做的,你必须更清楚地解释。
答
我不知道这是否回答你的问题,但情节的对象(即lines,patches,images等)有ButtonDownFcn
回调,当你按下鼠标按钮时鼠标指针在对象将执行。
下面是一个简单的例子(使用nested functions和function handles)您可以如何使用ButtonDownFcn
回调来获取有关所选对象的信息。首先,保存该函数在m文件:
function colorFcn = colored_patches
selectedColor = [1 0 0]; %# The default selected color
figure; %# Create a new figure
axes; %# Create a new axes
patch([0 0 1 1],[0 1 1 0],'r',... %# Plot a red box
'ButtonDownFcn',@patch_callback);
hold on; %# Add to the existing plot
patch([2 2 4 4],[1 2 2 1],'g',... %# Plot a green box
'ButtonDownFcn',@patch_callback);
patch([1 1 2 2],[3 4 4 3],'b',... %# Plot a blue box
'ButtonDownFcn',@patch_callback);
axis equal; %# Set axis scaling
colorFcn = @get_color; %# Return a function handle for get_color
%#---Nested functions below---
function patch_callback(src,event)
selectedColor = get(src,'FaceColor'); %# Set the selected color to the
%# color of the patch clicked on
end
function currentColor = get_color
currentColor = selectedColor; %# Return the last color selected
end
end
接下来,运行上述代码并保存返回的函数手柄在一个变量:
colorFcn = colored_patches;
这将创建3个彩色框的图,像这样:
现在,当您从colorFcn
点击鼠标的彩色框一个,输出将瓒GE:
%# Click the red box, then call colorFcn
>> colorFcn()
ans =
1 0 0 %# Returns red
%# Click the blue box, then call colorFcn
>> colorFcn()
ans =
0 0 1 %# Returns blue
%# Click the green box, then call colorFcn
>> colorFcn()
ans =
0 1 0 %# Returns green
感谢您的回复......是的,我希望用户点击图像(图像中的所有对象),并得到他们点击...如果我得到这个坐标可我会努力的坐标申请输入功能...非常感谢你 – zenab 2010-12-02 13:23:29
对于这个错误感到抱歉...我会继续我的问题...如果我得到对象坐标,我可以把这个对象看作一个图像吗? – zenab 2010-12-02 13:25:39