Matlab 中断/禁用GUI中的ROI绘图功能
我正在为图像中感兴趣区域(ROI)的选择编写GUI。 可以使用内置的MATLAB函数选择几种区域,例如Matlab 中断/禁用GUI中的ROI绘图功能,matlab,user-interface,selection,roi,Matlab,User Interface,Selection,Roi,我正在为图像中感兴趣区域(ROI)的选择编写GUI。 可以使用内置的MATLAB函数选择几种区域,例如impolly/imellipse 下面,我提供了一个GUI的最小工作示例,可以解决我的问题 问题是:假设一个用户错误地点击了一个ROI选择按钮(即,当目标是选择多边形时选择椭圆),我如何取消用于ROI选择的交互式工具以避免工作区中的错误 我知道按“Esc”键会取消交互式工具,但我希望避免出现错误 一个想法是使用另一个按钮(Abort)来执行中断,但我一直无法找到执行此操作的代码 functio
impolly
/imellipse
下面,我提供了一个GUI的最小工作示例,可以解决我的问题
问题是:假设一个用户错误地点击了一个ROI选择按钮(即,当目标是选择多边形时选择椭圆),我如何取消用于ROI选择的交互式工具以避免工作区中的错误
我知道按“Esc”键会取消交互式工具,但我希望避免出现错误
一个想法是使用另一个按钮(Abort)来执行中断,但我一直无法找到执行此操作的代码
function roiData = testGUI(sourceImage)
% Initialize main figure
hdl.mainfig = figure();
% Initialize roiData and roiCounter
roiData = [];
roiCounter = 0;
% Select Elliptical ROI button
hdl.selectEllipseButton = uicontrol(hdl.mainfig, 'Units', 'normalized', 'Position',[0.05 0.7 0.2 0.1], 'String', 'Select Ellipse', 'Callback', @selectEllipse);
% Select Polygonal ROI button
hdl.selectPolygonButton = uicontrol(hdl.mainfig, 'Units', 'normalized', 'Position',[0.05 0.6 0.2 0.1], 'String', 'Select Polygon', 'Callback', @selectPolygon);
% Abort Button
hdl.abort = uicontrol(hdl.mainfig, 'Units', 'normalized', 'Position',[0.05 0.2 0.2 0.2], 'String', 'Abort', 'Callback', @abort);
% Axes
hdl.axes = axes('Parent',hdl.mainfig, 'Units', 'Normalized', 'Position', [0.35 0.2 0.6 0.6]);
function selectEllipse(~, ~, ~)
imshow(sourceImage, [], 'Parent', hdl.axes);
roiCounter = roiCounter + 1;
h = imellipse(hdl.axes);
mask = uint16(createMask(h));
wait(h);
roiData(roiCounter).mask = mask;
end
function selectPolygon(~, ~, ~)
imshow(sourceImage, [], 'Parent', hdl.axes);
roiCounter = roiCounter + 1;
h = impoly(hdl.axes);
mask = uint16(createMask(h));
wait(h);
roiData(roiCounter).mask = mask;
end
function abort(~, ~, ~)
cla(hdl.axes)
% I need something else here... (see above)
end
% Pause until figure is closed
waitfor(hdl.mainfig);
end
试试这个:
function roiData = testGUI(sourceImage)
% Initialize main figure
hdl.mainfig = figure();
% Initialize roiData and roiCounter
roiData = [];
roiCounter = 0;
% Select Elliptical ROI button
hdl.selectEllipseButton = uicontrol(hdl.mainfig, 'Units', 'normalized', 'Position',[0.05 0.7 0.2 0.1], 'String', 'Select Ellipse', 'Callback', @selectEllipse);
% Select Polygonal ROI button
hdl.selectPolygonButton = uicontrol(hdl.mainfig, 'Units', 'normalized', 'Position',[0.05 0.6 0.2 0.1], 'String', 'Select Polygon', 'Callback', @selectPolygon);
% Abort Button
hdl.abort = uicontrol(hdl.mainfig, 'Units', 'normalized', 'Position',[0.05 0.2 0.2 0.2], 'String', 'Abort', 'Callback', @abort);
% Axes
hdl.axes = axes('Parent',hdl.mainfig, 'Units', 'Normalized', 'Position', [0.35 0.2 0.6 0.6]);
% Callbackrunning parameter
callbackrunning = false;
function selectEllipse(hObject,eventdata)
if(callbackrunning)
return;
end
callbackrunning = true;
imshow(sourceImage, [], 'Parent', hdl.axes);
roiCounter = roiCounter + 1;
h = imellipse(hdl.axes);
if(~callbackrunning)
return;
end
mask = uint16(createMask(h));
roiData(roiCounter).mask = mask;
callbackrunning = false;
end
function selectPolygon(hObject,eventdata)
if(callbackrunning)
return;
end
callbackrunning = true;
imshow(sourceImage, [], 'Parent', hdl.axes);
roiCounter = roiCounter + 1;
h = impoly(hdl.axes);
if(~callbackrunning)
return;
end
mask = uint16(createMask(h));
roiData(roiCounter).mask = mask;
callbackrunning = false;
end
function abort(hObject,eventdata)
if(callbackrunning)
disp('Fire escape key to cancel previous imrect');
% Create robot that fires an escape key
robot = java.awt.Robot;
robot.keyPress (java.awt.event.KeyEvent.VK_ESCAPE);
robot.keyRelease (java.awt.event.KeyEvent.VK_ESCAPE);
callbackrunning = false;
end
end
% Pause until figure is closed
waitfor(hdl.mainfig);
end
机器人对象触发退出键,该键将取消imrect。尝试以下操作:
function roiData = testGUI(sourceImage)
% Initialize main figure
hdl.mainfig = figure();
% Initialize roiData and roiCounter
roiData = [];
roiCounter = 0;
% Select Elliptical ROI button
hdl.selectEllipseButton = uicontrol(hdl.mainfig, 'Units', 'normalized', 'Position',[0.05 0.7 0.2 0.1], 'String', 'Select Ellipse', 'Callback', @selectEllipse);
% Select Polygonal ROI button
hdl.selectPolygonButton = uicontrol(hdl.mainfig, 'Units', 'normalized', 'Position',[0.05 0.6 0.2 0.1], 'String', 'Select Polygon', 'Callback', @selectPolygon);
% Abort Button
hdl.abort = uicontrol(hdl.mainfig, 'Units', 'normalized', 'Position',[0.05 0.2 0.2 0.2], 'String', 'Abort', 'Callback', @abort);
% Axes
hdl.axes = axes('Parent',hdl.mainfig, 'Units', 'Normalized', 'Position', [0.35 0.2 0.6 0.6]);
% Callbackrunning parameter
callbackrunning = false;
function selectEllipse(hObject,eventdata)
if(callbackrunning)
return;
end
callbackrunning = true;
imshow(sourceImage, [], 'Parent', hdl.axes);
roiCounter = roiCounter + 1;
h = imellipse(hdl.axes);
if(~callbackrunning)
return;
end
mask = uint16(createMask(h));
roiData(roiCounter).mask = mask;
callbackrunning = false;
end
function selectPolygon(hObject,eventdata)
if(callbackrunning)
return;
end
callbackrunning = true;
imshow(sourceImage, [], 'Parent', hdl.axes);
roiCounter = roiCounter + 1;
h = impoly(hdl.axes);
if(~callbackrunning)
return;
end
mask = uint16(createMask(h));
roiData(roiCounter).mask = mask;
callbackrunning = false;
end
function abort(hObject,eventdata)
if(callbackrunning)
disp('Fire escape key to cancel previous imrect');
% Create robot that fires an escape key
robot = java.awt.Robot;
robot.keyPress (java.awt.event.KeyEvent.VK_ESCAPE);
robot.keyRelease (java.awt.event.KeyEvent.VK_ESCAPE);
callbackrunning = false;
end
end
% Pause until figure is closed
waitfor(hdl.mainfig);
end
机器人对象触发了退出键,该键取消了imrect。这是一个很好的问题,在我想做类似的事情时,我还没有弄清楚。我会调查的。我当时的工作是强迫用户画出他们选择的任何东西,但在完成后,他们可以通过覆盖
'UIContextMenu'
来删除imroi。这是一个很好的问题,在我想做类似的事情时,我还没有弄清楚。我会调查的。我当时的工作基本上是强迫用户绘制他们选择的任何内容,但在完成后,他们可以通过覆盖'UIContextMenu'
来删除imroi。谢谢,它可以工作:)。非常感谢您向我介绍java机器人类@fnery哥们,我刚发现它,它看起来真的很酷。这里有更多关于它的信息:。此外,您可能需要确保java robot没有内存泄漏。您可能需要在脚本末尾使用clear java
。谢谢,它可以工作:)。非常感谢您向我介绍java机器人类@fnery哥们,我刚发现它,它看起来真的很酷。这里有更多关于它的信息:。此外,您可能需要确保java robot没有内存泄漏。您可能需要在脚本末尾使用clear java
。