How to delete previously made ROIs within a GUI

4 views (last 30 days)
Hello all, I'm working on an image processing program, and I need to make a mask on an image using the imellipse and imrect within a GUI.
I would like to be able to choose either to mask the image with imellipse or with imrect. So I made the toggle buttons for each.
I would like to delete the previously created ROI shape, if I click the button of the other. I know you can delete ROIs with the delete(Roi_handle) command, but I cannot delete handle just like that because in GUIs we pass around the variables using the handles structure, and the error 'Root object may not be deleted' came up when I tried to delete the handle field of the ROI.
I'm quite inexperienced with structures and GUIs for your information. Below is the thing I tried to do but with no success whatsoever.
I really appreciate any ideas or help from you.
Fuad
% --- Executes on button press in ellipse_button.
function ellipse_button_Callback(hObject, eventdata, handles)
% hObject handle to ellipse_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of ellipse_button
s= get(hObject,'Value');
if s==1;
set(handles.none_button,'Value',0)
set(handles.rectangle_button,'Value',0)
oldMask= handles.mask2;
delete(oldMask)
mask=imellipse(handles.axes1);
handles.output2=wait(mask);
guidata(hObject,handles);
else
end
% --- Executes on button press in rectangle_button.
function rectangle_button_Callback(hObject, eventdata, handles)
% hObject handle to rectangle_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of rectangle_button
s= get(hObject,'Value');
if s==1;
set(handles.ellipse_button,'Value',0)
set(handles.none_button,'Value',0)
oldMask= handles.mask1;
delete(oldMask)
mask=imrect(handles.axes1);
handles.output2= wait(mask);
guidata(hObject,handles);
else
end

Answers (1)

Image Analyst
Image Analyst on 27 Aug 2013
Why have special buttons for deleting the masks? What is the purpose of handles.output2? Where do you ever assign handles.mask1 or handles.mask2?
  2 Comments
Fuad Rahiman
Fuad Rahiman on 27 Aug 2013
they are not special buttons to delete the mask. I mean to do it like this: if i click button (rectangle) i will be able to make a rectangle mask, and if i click button (ellipse) the rectangle mask from before would disappear and i will be able to make a new ellipse mask.
the handles.output2 is intended to pass the imroi handle to the output fcn to be used in the createMask fcn.
The handles.mask1 and handles.mask2 are just my attempts to pass the handle of one imroi to the other
Image Analyst
Image Analyst on 27 Aug 2013
But you never set handles.mask1 equal to anything, at least nowhere that I could see. Same for mask2.

Sign in to comment.

Categories

Find more on Author Block Masks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!