【问题标题】:Cropping multiple parts from the single image in Matlab在 Matlab 中从单个图像中裁剪多个部分
【发布时间】:2019-01-19 16:46:14
【问题描述】:

我想从图像中裁剪多个部分以使用鼠标指针制作真实的图像。每个对象中有不同数量的对象,因此我无法运行 for 循环特定次数。但是,我可以使用while 循环。但我怎么能阻止呢?

for i=1:10

    [tt bb]=imcrop(img);
    crop.img{i,:}=tt;
    crop.bb(i,:)=bb;
end

【问题讨论】:

  • 请说明你是如何回答这个问题的
  • @Raha 我已经更新了代码。再次使用for 循环。我想使用while 或其他可以停止的东西

标签: image matlab crop


【解决方案1】:

您可以为此使用if 条件和waitforbuttonpress。当您完成裁剪图像部分并想要裁剪另一部分时,单击任意鼠标按钮,循环将继续。当您不想裁剪任何其他部分时,按任意键盘按钮,循环将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

请注意,它需要您的图形窗口处于焦点。

【讨论】:

    【解决方案2】:

    想退出时按 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-03
      • 2020-11-11
      • 2014-08-03
      • 2016-12-05
      • 2014-07-20
      • 2020-09-29
      相关资源
      最近更新 更多