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

Technical Source
2 min readMar 4, 2022

--

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

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

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

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet