从 Matlab 中的单个图像裁剪多个部分
Cropping multiple parts from the single image in Matlab
我想从图像中裁剪多个部分以使用鼠标指针制作地面实况。每个对象的数量不同,因此我无法 运行 for
循环特定次数。但是,我可以使用 while
循环。但是我怎么能阻止呢?
for i=1:10
[tt bb]=imcrop(img);
crop.img{i,:}=tt;
crop.bb(i,:)=bb;
end
您可以使用 if
condition with waitforbuttonpress
for this. When you're done cropping an image portion and want to crop another portion, click any mouse button and the loop will continue. When you don't want to crop any other portion, press any keyboard button and the loop will break
.
演示代码:
img = imread('peppers.png');
f = figure;
k = 1;
while 1
[tt, bb] = imcrop(img);
crop.img{k,:} = tt;
crop.bb{k,:} = bb;
if waitforbuttonpress
break;
end
k = k+1;
end
请注意,它需要您的身材 window 处于焦点。
想退出时直接按 Esc 怎么样?
img = imread('peppers.png');
k = 1;
f = figure;
imshow(img)
while true
title('Double click to select next area, press Esc when finished')
[tt, bb] = imcrop(f);
if isempty(tt)
close(f)
break
end
crop.img{k,:} = tt;
crop.bb{k,:} = bb;
k = k+1;
end
我想从图像中裁剪多个部分以使用鼠标指针制作地面实况。每个对象的数量不同,因此我无法 运行 for
循环特定次数。但是,我可以使用 while
循环。但是我怎么能阻止呢?
for i=1:10
[tt bb]=imcrop(img);
crop.img{i,:}=tt;
crop.bb(i,:)=bb;
end
您可以使用 if
condition with waitforbuttonpress
for this. When you're done cropping an image portion and want to crop another portion, click any mouse button and the loop will continue. When you don't want to crop any other portion, press any keyboard button and the loop will break
.
演示代码:
img = imread('peppers.png');
f = figure;
k = 1;
while 1
[tt, bb] = imcrop(img);
crop.img{k,:} = tt;
crop.bb{k,:} = bb;
if waitforbuttonpress
break;
end
k = k+1;
end
请注意,它需要您的身材 window 处于焦点。
想退出时直接按 Esc 怎么样?
img = imread('peppers.png');
k = 1;
f = figure;
imshow(img)
while true
title('Double click to select next area, press Esc when finished')
[tt, bb] = imcrop(f);
if isempty(tt)
close(f)
break
end
crop.img{k,:} = tt;
crop.bb{k,:} = bb;
k = k+1;
end