2

In the context of analysing images to find zones with movement, here's what I've got as an intermediate result, using opencv with python (assume these are 100% binary):

Binary image

So my question is: is there a way to locate blobs of white with a specific "thickness" threshold ?

Here's what it could look like, roughly:

Resulting image

I've been looking for transforms and manipulations such as connected components and morphological transformations but those won't work and I can't quite figure out where to start other than that.

1 Answer 1

3

The morphological opening is ideal for this problem. It removes all the white parts thinner than a given diameter.

In OpenCV it is implemented in cv2.morphologyEx using op=cv2.MORPH_OPEN:

kernel = cv2.getStructuringElement(cv2.cv.MORPH_ELLIPSE, diameter)
output = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel)

But note that this removes parts of objects that are thin, it doesn't leave the full object if a part of it is wide enough. That can be done using an opening by reconstruction, an erosion followed by a morphological reconstruction (also known as geodesic dilation).

OpenCV doesn't have that algorithm. This Q&A gives a rough outline for how to implement it in OpenCV, but that is a very expensive algorithm, there are much more efficient ones.

There might be an implementation in Scikit-image, I haven't looked for it.

DIPlib (with Python bindings called PyDIP) (also, I'm an author) has a dip.OpeningByReconstruction. Install the Python module with pip install diplib.

Sign up to request clarification or add additional context in comments.

2 Comments

I would also add this webpage containing articles for more extensive explanation regarding morphological operations. After performing an opening you can call cv.boundingRect(img) from openCV to locate the remaining objects.
@RobertMoga: Though I appreciate Bob’s work in putting that web site together, the page you link provide a highly incomplete view of Mathematical Morphology. That was the state more or less 50 years ago when the field was created. A lot of things have happened in 50 years.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.