【问题标题】:Extracting a binary boundary image for object of interest in a binary object mask image extracted from an instance segmentation mask在从实例分割掩码中提取的二进制对象掩码图像中提取感兴趣对象的二进制边界图像
【发布时间】:2021-09-03 10:34:47
【问题描述】:

我有一个来自Detectron 2 的实例分割 + 2D 边界框结构,我从中将 pred_masks 转换为二进制对象(感兴趣的)掩码。

所以,在这里,我的问题是如何将此二进制蒙版转换为二进制图像,其中整个图像是黑色的,但对象蒙版中感兴趣的对象周围的边界是白色的?

segmenter = get_pointrend_predictor()
instances = segmenter(image)["instances"]
vis = PointRendVisualizer(image, metadata=MetadataCatalog.get("coco_2017_val"))
Image.fromarray(vis.draw_instance_predictions(instances.to("cpu")).get_image())

instances2.pred_masks.shape

torch.Size([1, 224, 400])
na = instances[1].pred_masks.to('cpu').numpy()
print(na.shape)

(1, 224, 400)

na = na.reshape(224, 400)
na.shape

(224, 400)

na = np.where(na == False, 0, na)
na = np.where(na == True, 255, na)
plt.imshow(na)

在这个具体的例子中,我有兴趣在小象的边界上画一条白线(这是我在实例分割蒙版对象中的第二个实例)。

很遗憾,我没有小象的边界图,但这里有一个人类边界的示例(以白线显示): ^ 图片参考:https://www.programmersought.com/article/52814639867/

【问题讨论】:

  • 对二值图像应用边缘检测

标签: python deep-learning computer-vision mask image-segmentation


【解决方案1】:

我只是想出了提取位掩码边缘的方法。

如图所示:

na = outputs['instances'][1].pred_masks.to('cpu').numpy()
na = na.reshape(1024, 683)

from detectron2.utils.visualizer import GenericMask
gm = GenericMask(na, 1024, 683)
sg = gm.polygons[0].reshape(-1,2)
print(sg)

通过代码,我得到了一个多边形边列表。这是气球的面具。

为了验证它,我将多边形翻译成 JavaScript,如下图所示,然后运行它。显然它有效。

【讨论】:

    猜你喜欢
    • 2015-01-08
    • 1970-01-01
    • 2020-04-13
    • 1970-01-01
    • 2019-02-13
    • 2018-07-21
    • 2022-01-09
    • 2015-10-11
    • 1970-01-01
    相关资源
    最近更新 更多