查看单个帖子
旧 2019-12-14, 20:13   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 在用户指定的图像上绘制圆圈/正方形

我在使用guide创建的MATLAB中有一个GUI。到目前为止,用户可以导入图像并保存图像。我的下一步是允许用户单击图像以放置一个圆圈/正方形,无论哪一个都更容易实现。理想情况下,我想这样做,因此创建的最新版本是不可撤消的,但基本实现至关重要。

我假设对圆的实际绘制来说,使用PLOT可以很好,正如其他几个问题所述。我不确定该如何在鼠标单击的图像中获取位置,然后将PLOT放置在该位置。

编辑:这是我目前用于工作部件的主要代码。

function V1Open_Callback(hObject, eventdata, handles) % hObject handle to V1Open (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) hMainGui = getappdata(0, 'hMainGui'); fileName = uigetfile('*.jpg'); setappdata(hMainGui, 'fileName', fileName); updateAxes1 function updateAxes1 hMainGui = getappdata(0, 'hMainGui'); fileName = getappdata(hMainGui, 'fileName'); imshow(imread(fileName)) % --- Executes on button press in V1Save. function V1Save_Callback(hObject, eventdata, handles) % hObject handle to V1Save (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) imsave;

回答:

我使用图像处理工具箱提供的像imellipse和imrect这样的功能来做到这一点:

用户可以单击按钮以开始放置椭圆,这将它们放到图形中,并允许他们放置和调整椭圆的大小。调整大小后,他们可以双击并获得结果。我倾向于存储椭圆对象的句柄及其实际位置。

% --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) axes(handles.axes1); if (isfield(handles, 'ellipse')) delete(handles.ellipse); end handles.ellipse = imellipse(); handles.eps = getPosition(handles.ellipse); guidata(hObject, handles);

更多&回答...
poster 当前离线   回复时引用此帖