在图像上徒手绘制多个区域 [英] Draw multiple regions on an image- imfreehand

查看:131
本文介绍了在图像上徒手绘制多个区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在图像上手动绘制多个区域,以创建绘制区域的二进制蒙版(地面实况).

I'd like to manually draw multiple regions on an image to create a binary mask of the drawn regions (ground truth).

我附加了使用imfreehand进行编码的代码,该编码可对一个区域执行此操作,但是一旦释放鼠标按钮,就会显示该单个区域的二进制掩码.有没有办法绘制多个区域然后显示二进制蒙版? (多次拨打不打扰的电话可能不起作用,因为每个图片的区域数量会有所不同.)

I attached the code to do it using imfreehand that does the job for one region, but once in release the mouse button, binary mask for that single region is displayed. Is there a way to draw multiple regions and then display the binary mask? (Calling imfreehand multiple times may not work because the number of regions varies with each image).

h= imfreehand();

h = imfreehand(gca);
setColor(h,'red');

position = wait(h); 
BW = createMask(h);
figure,imshow(BW);
axis on;

谢谢.

推荐答案

您可以循环播放直到获得空的蒙版-这将表明用户已完成所有蒙版的绘制.
sz为输出掩码的所需大小,然后

You can loop until you get an empty mask - this will indicate that the user finished drawing all masks.
Let sz be the desired size of the output mask, then

totMask = false( sz ); % accumulate all single object masks to this one
h = imfreehand( gca ); setColor(h,'red');
position = wait( h );
BW = createMask( h );
while sum(BW(:)) > 10 % less than 10 pixels is considered empty mask
      totMask = totMask | BW; % add mask to global mask
      % you might want to consider removing the old imfreehand object:
      delete( h ); % try the effect of this line if it helps you or not.

      % ask user for another mask
      h = imfreehand( gca ); setColor(h,'red');
      position = wait( h );
      BW = createMask( h );
end
% show the resulting mask
figure; imshow( totMask ); title('multi-object mask');

这篇关于在图像上徒手绘制多个区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆