How to store ROIs?

16 Ansichten (letzte 30 Tage)
The MightySpaceQuin
The MightySpaceQuin am 8 Dez. 2019
Kommentiert: Image Analyst am 9 Dez. 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.

Akzeptierte Antwort

Image Analyst
Image Analyst am 8 Dez. 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 Kommentare
The MightySpaceQuin
The MightySpaceQuin am 9 Dez. 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 am 9 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by