MATLAB Answers

Create and save imfreehand() positions until the user clicks a button to finish

5 views (last 30 days)
cgenes
cgenes on 7 Oct 2016
Commented: Hashir Tanveer on 20 Feb 2020
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

Accepted Answer

Marc Jakobi
Marc Jakobi on 7 Oct 2016
Edited: Marc Jakobi on 7 Oct 2016
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
  7 Comments
Hashir Tanveer
Hashir Tanveer on 20 Feb 2020
Hi Marc, How can i extract or separate the ROI based on the coordinates of that same ROI. I want to use those coordinates to crop the ROI of many images of same scene. Can you help me in that?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!