OpenCV-仅保留python中的标记斑点 [英] OpenCV - Retaining only marked blobs in python

查看:218
本文介绍了OpenCV-仅保留python中的标记斑点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用OpenCV解决一个形态问题.我有两张图片.

I have a morphological problem i am attempting to solve using OpenCV. I have two images.

  1. 面具
  2. 种子

在蒙版图像中,尝试仅保留由种子图像标记的斑点,并除去其余斑点.

In the mask image am trying to retain only the blobs marked by a seed image and to remove the rest.

我在下面发布了蒙版和种子图像

Underneath I am posting the mask and seed image

蒙版图像:

种子图像:

为了进一步说明问题,我放大了图像并创建了一个子图.

To further illustrate a the problem I have zoomed into the image and created a subplot.

在此示例中,右侧的图是种子图像,左侧的图是蒙版图像.手术结束时,我想让象鼻形的斑点在左侧,因为它是用种子坐标(左)标记的.

In this example the plot on your right is the seed image, the plot your left is the mask image. At the end of the operation I would like to have the elephant trunk shaped blob on the left as the result as it is marked by the seed coordinates(left).

按位操作将只给我种子和蒙版之间的重叠区域(结果是相同的正方形斑点). 一种可能的解决方案是通过重建使用开放,但是OpenCV没有实现.

Bit-wise operations will give me only overlapping regions between seed and mask (result is the same square shaped blob). One possible solution is to use opening by reconstruction, however OpenCV doesn't have an implementation of it.

OpenCV-是否实现了opencv中基于标记的重构

任何指针都值得赞赏!

推荐答案

好的,谢谢所有花时间查看这篇文章的人.我无法在OpenCV中找到针对此特定问题的解决方案.因此,我求助于使用PYMORPH库.

Alright, Thank you everyone who had taken the time to view this post. I was unable to find a solution for this particular problem within OpenCV. Hence I resorted to using the PYMORPH library.

https://pythonhosted.org/pymorph/

函数Inf-reconstruction正是我想要的.

The function Inf-reconstruction does exactly what I wanted.

pymorph.infrec(f,g,Bc = {3x3 cross})

pymorph.infrec(f, g, Bc={3x3 cross})

infrec通过条件为g的Bc对f的扩张进行无限次的递归迭代(直到稳定为止的迭代)来创建图像y.我们说y是标记f的g的inf重构.有关算法和应用程序,请参见Vinc:93b.

infrec creates the image y by an infinite number of recursive iterations (iterations until stability) of the dilation of f by Bc conditioned to g. We say the y is the inf-reconstruction of g from the marker f. For algorithms and applications, see Vinc:93b.

参数:
f:标记图像(灰色或二进制). g:调节图像(灰色或二进制). Bc:连接结构元素(默认值:3x3交叉). 返回值:
y:图片

Parameters :
f : Marker image (gray or binary). g : Conditioning image (gray or binary). Bc : Connectivity Structuring element (default: 3x3 cross). Returns :
y : Image

希望这可以帮助其他人经历类似的障碍.

Hope this helps others traveling through similar hurdles.

谢谢

这篇关于OpenCV-仅保留python中的标记斑点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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