简体   繁体   English

如何使用openCV识别连接组件的最窄部分?

[英]How to recognize the narrowest part of a connected component with openCV?

Given a connected component such as this: 给定这样的连接组件:

在此处输入图片说明

I'd like to slice the image into two images where the narrowest part appears, so the output would look like this: 我想将图像切成两幅图像,其中出现最窄的部分,因此输出如下所示:

在此处输入图片说明 , 在此处输入图片说明

note: I have added few more examples (as requested):. 注意:我还添加了一些示例(根据要求):。

1) 1) 在此处输入图片说明

在此处输入图片说明 在此处输入图片说明

2) 2) 在此处输入图片说明 result with: 结果: 在此处输入图片说明 , 在此处输入图片说明 ,

A really general and quite robust approach would be using erosion and watershed transformation: 一个真正通用且相当强大的方法是使用侵蚀和分水岭转换:

  1. Erode the binary image with a square kernel of size k 用大小为k的平方核腐蚀二进制图像
  2. Check for the number of components. 检查组件数量。 If the number of components < 2 set k = k + 1 and repeat from step 1. 如果分量数<2,则设置k = k + 1并从步骤1开始重复。

This will eventually result in 2 (or more) separated components. 最终将导致2个(或更多)分离的组件。 Now: 现在:

  1. Calculate markers for the watershed transformation using the components as labels you received in the previous step. 使用您在上一步中收到的组件作为标签,为分水岭转换计算标记。
  2. Perform a marker-based watershed transformation with your markers and obtain your different components including the borders for each component. 使用标记执行基于标记的分水岭转换,并获得不同的组件,包括每个组件的边框。

For a code reference, you may want to take a look at this watershed segmentation guide from OpenCV . 对于代码参考,您可能想看一下OpenCV的分水岭分割指南 They have a use case quite similar to your own application. 他们的用例与您自己的应用程序非常相似。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM