由于某种原因,以下代码仅显示带有高度和宽度100,100的10,10的roi的蒙版图像。这些是初始值。即使在getPosition函数之后,图像似乎也不会更新。任何人都可以解释这个问题吗?
`I = imread('/Users/imageuser/Documents/PT300.tif');
h = imshow(I);
% define circular roi by square bounding box
x = 10;
y = 10;
d1 = 100;
d2 = 100;
e = imellipse(gca, [x y d1 d2]);
% roi can be interactively moved/adjusted
% do not close figure window before createMask is called
%%% these lines are only needed if you move or resize the roi
pos = getPosition(e);
x = pos(1);
y = pos(2);
d1 = pos(3);
d2 = pos(4);
%%%
BW = createMask(e,h);
pause;
imshow(BW);`
答案 0 :(得分:0)
你需要把这些行(注意我颠倒了他们的顺序):
pause;
BW = createMask(e,h);
在致电getPosition
之前,否则新职位不会更新。
整个代码:
clear
clc
close all
I = imread('coins.png');
h = imshow(I);
% define circular roi by square bounding box
x = 10;
y = 10;
d1 = 100;
d2 = 100;
e = imellipse(gca, [x y d1 d2]);
pause;
BW = createMask(e,h);
% roi can be interactively moved/adjusted
% do not close figure window before createMask is called
%%% these lines are only needed if you move or resize the roi
pos = getPosition(e)
x = pos(1);
y = pos(2);
d1 = pos(3);
d2 = pos(4);
%%%
figure
imshow(BW);
拖动ROI后示例输出:
耶!
注意:正如juicestain所述,在用户完成创建GUI时,不是使用pause
来停止执行程序,而是可以使用wait
等待用户双击ROI对象,而不必像pause
命令那样按键。
因此,您可以通过拨打pause
来取代对wait(e)
的通话。