Erasing freehandrois in a stack shared via handles

1 view (last 30 days)
I want to be able to erase a collection of freehandrois that I've drawn on an image successively. I decided to use a stack-like vector that adds and erases its last elements. I declared it in OpeningFcn and shared it via handles using
handles.freehandrois =[];
I use a radiobutton to draw with imfreehand while its active and a pushbuton to order the erasing of the last freehandroi.
It isn't working, I'm getting the following error:
Subscript indices must either be real positive integers or logicals.
Error in PROTO_TESIS1>pushbutton6_Callback (line 333)
delete(handles.freehandrois(end));
What's wrong with this code?
function radiobutton1_Callback(hObject, eventdata, handles)
while(get (hObject, 'Value')) %while the radiobutton 'Draw Segmentation Seeds' is active
freehandroi=imfreehand('Closed', false)
handles.freehandrois= [handles.freehandrois;freehandroi]; %%add the new roi to the shared structure
end
guidata(hObject, handles);
function pushbutton6_Callback(hObject, eventdata, handles)
delete(handles.freehandrois(end));
guidata (hObject, handles);

Answers (1)

Image Analyst
Image Analyst on 2 Feb 2013
Edited: Image Analyst on 2 Feb 2013
freehandrois is a field of a structure. handles is a structure. To totally get rid of it you need to use
rmfield(handles, 'freehandrois');
But imfreehand returns a handle, not a list of x,y coordinates so you don't want to simply append the handle to an existing list like that because there would be no way to tell where one stops and the other begins and you keep overwriting the handle. You'd want to store the mask into a cell array, something like
handles.freehandrois(end+1) = {freehandroi.createMask};
then to delete the last one
handles.freehandrois(end) = [];

Categories

Find more on Interactive Control and Callbacks 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!