Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/machinevisiontoolbox/ImageBlobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ def filter(
return self[:]
m: np.ndarray = np.array(mask).all(axis=0) # type: ignore[assignment]

return self[m]
return self[m.flatten()]

def sort(self, by: str = "area", reverse: bool = False) -> "Blobs": # type: ignore[override]
"""
Expand Down
13 changes: 13 additions & 0 deletions tests/test_image_blobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,19 @@ def test_filter_touch(self):
removed = self.blobs4.filter(touch=True)
self.assertEqual(len(removed), 0)

def test_filter_area_single_blob_keeps_match(self):
# Regression for GH issue #17: a single-blob Blobs mask came out
# 2D (from np.array(mask).all(axis=0)) and indexing self[m] with
# it dropped the blob even though it matched the filter.
area = self.blobs1[0].area
kept = self.blobs1.filter(area=area * 0.5)
self.assertEqual(len(kept), 1)

def test_filter_area_single_blob_removes_non_match(self):
area = self.blobs1[0].area
removed = self.blobs1.filter(area=area * 2)
self.assertEqual(len(removed), 0)

# --- sort --------------------------------------------------------------- #

def test_sort_returns_blobs(self):
Expand Down
Loading