我正在編程一個GUI,用於在圖像中選擇感興趣區域(ROI)。 幾種區域可以使用內置MATLAB函數來選擇,如impoly
/imellipse
。中斷/禁用GUI中的ROI繪圖功能
下面,我提供了一個GUI的最小工作示例,可以解決我的問題。
問題是:假設一個用戶誤選其中一個ROI選擇按鈕(即,當目標是選擇一個多邊形時選擇一個橢圓)如何取消用於ROI選擇的交互工具避免工作區中的錯誤?
我知道按下「Esc」鍵會取消交互式工具,但我想避免錯誤。
一個想法是有另一個按鈕(中止)來執行中斷,但我一直無法拿出代碼來執行此操作。
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
這是一個很好的問題,當我想要做類似的事情時,我無法想象這個問題。我會研究這個。當時我的工作是基本上強制用戶繪製他們選擇的任何東西,但是在完成後他們可以通過覆蓋「UIContextMenu」來刪除imroi。 – Justin 2013-03-17 23:33:13