MATLAB Answers

How to store ROIs?

7 views (last 30 days)
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

Sign in to comment.

Accepted Answer

Image Analyst
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

Show 1 older comment
Image Analyst
Image Analyst on 9 Dec 2019
You aren't specifying the number of rows for handles.linePosition so using colon there will throw an error because it doesn't know how many rows there are. Also, you're not indexing anything so all your ROI's will jsut overwrite the same one all the time.
The MightySpaceQuin
The MightySpaceQuin on 9 Dec 2019
I seem to have got past the overwrite issue, but I have a problem plotting intersections for all the lines. As well as clearing the array of all handle objects. This is what I have so far:
function plotLine_Callback(hObject, eventdata, handles)
handles.line = drawline(handles.axes1, ...
'Type','Line',...
'LineWidth', 1.325, ...
'InteractionsAllowed', 'none');
if not(isfield(handles, 'lineHandles'))
handles.lineHandles = {};
end
handles.linePos = handles.line.Position;
handles.xln = handles.linePos(:,1);
handles.yln = handles.linePos(:,2);
handles.lineHandles = [handles.lineHandles, handles.line];
disp(handles.lineHandles);
function intersects(hObject, eventdata, handles)
[xi,yi] = polyxpoly(handles.xC, handles.yC, handles.xln, handles.yln);
hold on;
plot(xi, yi, 'r*', 'MarkerSize', 15, 'LineWidth', 1.95, 'Color', '#900C3F');
This is what the command view reports from the disp function: Capture.PNG
Image Analyst
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.

Sign in to comment.

More Answers (0)

Sign in to answer this question.