Skip to content

Filtering blobs when only one blob is detected #17

Closed

Description

@dschaele

Hey,
I noticed that when I apply filters to the list of detected blobs and only one blob is in the list, this blob will not be returned even though it is within the filter criteria. I am not sure if that behavior is intended, but for my applications at least it's unfortunate.

Consider this minimal example:

from machinevisiontoolbox import Image
from matplotlib import pyplot as plt

img = Image.Zeros(1000, dtype="uint8")
img.A[300:400, 200:300] = 255
#img.A[100:105, 100:105] = 255
img.disp(block=False)

blobs=img.blobs()
print(blobs)
print('Blob_0 area:')
print(blobs[0].area)
blobs.plot_box(color='g')
blobs.plot_centroid(label=True)
plt.show(block=True)

blobs_filtered = blobs.filter(area=100)
print("Filtered blobs:")
print(blobs_filtered)

The terminal output is:

Image

So even though the blob has an area > 100 it is not returned from the filtering.
When applying the same filter with two detected blobs, everything works fine.

A potential fix is in ImageBlobs.py, Line 482 to flatten the mask variable m:
return self[m] -> return self[m.flatten()]

Activity

  1. petercorke commented on Aug 2, 2026

    @petercorke
    Owner

    Thank you for your interest in MVTB, and for the clear repro and suggested fix — you were exactly right about m.flatten(). A fix is up for review in #35, including regression tests built from your example. I'll leave this open until it merges, at which point it'll close automatically.

  2. dschaele commented on Aug 5, 2026

    @dschaele
    Author

    Cool! thanks! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions