필터 지우기
필터 지우기

Using ROIPOLY in a GUI help!

조회 수: 3 (최근 30일)
Ellis Berry
Ellis Berry 2016년 5월 26일
답변: Geoff Hayes 2016년 5월 29일
Hi everybody,
I'm having a few issues using the roipoly function in a GUI. I want to use one pushbutton where you select the ROI and it saves the vertices of the polygon (xMin, yMin, xMax, yMax etc...) and I also want it to open in a separate figure to the GUI? My code so far makes it open in the gui screen which is ugly and doesn't save the xMin or xMax etc etc as variables :(!!! Here is my code at the moment:
% --- Executes on button press in pushbutton4. Choose Crop area
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
filename = uigetfile('*.*');
myimage = imread(filename);
[BW, xi, yi] = roipoly(myimage);
xMin = min(xi);
xMax = max(xi);
yMin = min(yi);
yMax = max(yi);
I want the vertices to be saved so that I can then use another pushbutton which calls them to use them! To do this do I use 'handles', if so, how?? Any help would be greatly appreciated.
Thanks,
Ellis

답변 (1개)

Geoff Hayes
Geoff Hayes 2016년 5월 29일
Ellis - save the variables to the handles structure as
function pushbutton4_Callback(hObject, eventdata, handles)
filename = uigetfile('*.*');
myimage = imread(filename);
[BW, xi, yi] = roipoly(myimage);
handles.xMin = min(xi);
handles.xMax = max(xi);
handles.yMin = min(yi);
handles.yMax = max(yi);
guidata(hObject, handles);
In the above, we create new fields in the handles structure and then save that updated structure using guidata. Now, any other callback that fire (after this one) will have access to these four elements.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by