How to store ROIs?
13 views (last 30 days)
Show older comments
The MightySpaceQuin
on 8 Dec 2019
Commented: Image Analyst
on 9 Dec 2019
Hello. I am writing a GUI that allows a user to plot multiple ROI's using the drawline function on an axes by interactively using the mouse. I want to be able to store each ROI as they are drawn by the user so that I can iterate over them individually. I am using GUIDE and I'm unsure how to do this. Any help would be appreciated.
0 Comments
Accepted Answer
Image Analyst
on 8 Dec 2019
Try this:
imshow('peppers.png');
uiwait(helpdlg('Draw a line'));
hLine = drawline('SelectedColor','yellow');
allROIs{1} = hLine.Position;
% Draw and save the second line.
uiwait(helpdlg('Draw another line'));
hLine = drawline('SelectedColor','yellow');
allROIs{2} = hLine.Position;
% Now clear lines
hLines = findobj(gca, 'type', 'images.roi.Line');
delete(hLines);
% Now have program draw them back again.
for k = 1 : length(allROIs)
message = sprintf('Click OK to see ROI #%d', k);
uiwait(helpdlg(message));
thisROI = allROIs{k}
drawline('Position', thisROI);
end
Adapt as needed.
4 Comments
Image Analyst
on 9 Dec 2019
Did you see the code I gave for clearing the lines:
% Now clear lines
hLines = findobj(gca, 'type', 'images.roi.Line');
delete(hLines);
It would be easier for me to debug if you just attached the complete .m and .fig files.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!