Hi, I want an image to open and the user to draw ROI with imfreehand() until they are finished - with the co-ordinates saved into structured array - - the following code does it for 3 regions of interest - - but how can i do this until the user is finished? Would be good to have an undo button too - which not only deletes the region of interest but also deletes xy co-ordinates in the array. Thanks!! img = imread('myfig.jpg') imshow(img) i = 1; for i = 1:3 hFH(i) = imfreehand(); xy{i} = hFH(i).getPosition; end
Kshitij Singh answered .
2025-11-20
You could use
img = imread('myfig.jpg')
imshow(img)
i = 1;
finished = 'NO';
i = 1;
while strcmpi(finished,'NO')
hFH(i) = imfreehand();
finished = questdlg('Finished?', ...
'confirmation', ...
'YES', 'NO', 'UNDO', 'NO');
if strcmpi(finished, 'UNDO')
delete(hFH(i))
finished = 'NO';
else
xy{i} = hFH(i).getPosition;
i = i + 1;
end
end