python - 在 numpy 数组中裁剪 ROI 区域
问题描述
我正在编写一些代码来切割 numpy 数组中的两个单独的 ROI 区域。该数组是一个带有布尔值的掩码数组,它由左右两个主要部分组成。
我需要从我原来的 numpy 数组中裁剪出左右部分。我的代码如下,它们是函数的一部分(图像和蒙版被传递给这个函数)
if mask.shape[-1] > 0:
# We're treating all instances as one, so collapse the mask into one layer
mask = (np.sum(mask, -1, keepdims=True) >= 1)
zeros=np.zeros(image.shape)
#splash = np.where(mask, image, gray).astype(np.uint8)
splash = np.where(mask, image, zeros).astype(np.uint8)
我不确定如何实现这一点,因为我对颠簸真的很陌生。我可以飞溅图像,但我需要裁剪左右两个部分,为此我需要裁剪或重塑蒙版阵列。我已将飞溅的输出示例附加到此线程
解决方案
这是计算机视觉中一个非常典型的问题。一种流行的解决方案是连接组件标签(或 CCL)。OpenCV 已经有一个实现:
https://docs.opencv.org/3.4/d3/dc0/group__imgproc__shape.html#gaedef8c7340499ca391d459122e51bef5
然后您可以使用 blob 分析来裁剪对象:
https://docs.opencv.org/3.4/d0/d7a/classcv_1_1SimpleBlobDetector.html
推荐阅读
- wordpress - WooCommerce:创建产品页面而不是使用产品过滤器
- amazon-web-services - CMD 上是否有命令通过无服务器框架列出 AWS 上的所有部署 lambdas(Functions)?
- c - 在 C 中比较两个字符串的问题
- node.js - NodeJS 中的异步 foreach 或 for 循环
- javascript - 我的应用程序可以更改用户的浏览器设置吗?
- datagrip - Datagrip - 无法启动
- ios - Swift - 放置正确的导航箭头方向
- javascript - onbeforeunload 事件确认
- javascript - 如何用更多跨度标签包装html跨度标签数组?
- python-3.x - ModuleNotFoundError:没有名为“dbn”的模块