OpenCV - Retaining only marked blobs in python

China☆狼群 提交于 2019-12-11 01:52:01

问题


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

  1. Mask
  2. Seed

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

Mask Image :

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).

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 - Is there an implementation of marker based reconstruction in opencv

Any pointers are appreciated!


回答1:


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/

The function Inf-reconstruction does exactly what I wanted.

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

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.

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.

Thank you



来源:https://stackoverflow.com/questions/42151348/opencv-retaining-only-marked-blobs-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!