如何使用 imfreehand 绘制多个 ROI?
How can I draw several ROI's using imfreehand?
我需要使用 MATLAB R2015a 中的 imfreehand 函数绘制多个 ROI。我需要的是绘制图像,用户必须 select he/she 想要的 ROI,完成后,他们必须单击(鼠标右键)才能完成 select离子。此外,用户必须能够 select 所需的 ROI 并将其删除。
这里的任何人都可以给我示例或关于如何实现它的任何想法吗?
提前致谢,
您可以通过为轴设置 ButtonDownFcn
回调来完成此操作。每当用户单击鼠标左键时,您就允许他们开始绘制新的 ROI。当他们单击鼠标右键时,它会停止并且 returns 一个包含 imfreehand
个对象的列表。当您右键单击 ROI 时,会出现一个上下文菜单,允许他们删除给定的 ROI。
function handles = multiROI()
hax = axes('ButtonDownFcn', @(src,evnt)buttondown(evnt))
handles = [];
% Keep this function open until we right click
waitfor(gca, 'UserData')
function buttondown(evnt)
switch evnt.Button
case 1
% On a left click draw a new ROI
handles = cat(1, handles, imfreehand());
case 3
% On a right click, remove empty ROIs and return
handles = handles(isvalid(handles));
set(gca, 'UserData', 'done')
end
end
end
更新
这是一个不需要那么多点击但使用转义键完成绘图的版本。
handles = imfreehand();
lastroi = handles;
while ~isempty(lastroi)
lastroi = imfreehand();
handles = cat(1, handles, lastroi);
end
handles = handles(isvalid(handles));
我需要使用 MATLAB R2015a 中的 imfreehand 函数绘制多个 ROI。我需要的是绘制图像,用户必须 select he/she 想要的 ROI,完成后,他们必须单击(鼠标右键)才能完成 select离子。此外,用户必须能够 select 所需的 ROI 并将其删除。
这里的任何人都可以给我示例或关于如何实现它的任何想法吗?
提前致谢,
您可以通过为轴设置 ButtonDownFcn
回调来完成此操作。每当用户单击鼠标左键时,您就允许他们开始绘制新的 ROI。当他们单击鼠标右键时,它会停止并且 returns 一个包含 imfreehand
个对象的列表。当您右键单击 ROI 时,会出现一个上下文菜单,允许他们删除给定的 ROI。
function handles = multiROI()
hax = axes('ButtonDownFcn', @(src,evnt)buttondown(evnt))
handles = [];
% Keep this function open until we right click
waitfor(gca, 'UserData')
function buttondown(evnt)
switch evnt.Button
case 1
% On a left click draw a new ROI
handles = cat(1, handles, imfreehand());
case 3
% On a right click, remove empty ROIs and return
handles = handles(isvalid(handles));
set(gca, 'UserData', 'done')
end
end
end
更新
这是一个不需要那么多点击但使用转义键完成绘图的版本。
handles = imfreehand();
lastroi = handles;
while ~isempty(lastroi)
lastroi = imfreehand();
handles = cat(1, handles, lastroi);
end
handles = handles(isvalid(handles));