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
4 changes: 2 additions & 2 deletions src/machinevisiontoolbox/ImagePointFeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ def gridify(self, nbins: int | tuple[int, int], nfeat: int) -> "BaseFeature2D":
bins = np.zeros((nh, nw), dtype="int")

for f in self:
ix = f.p[0] // binwidth
iy = f.p[1] // binheight
ix = int(f.p[0].item() // binwidth)
iy = int(f.p[1].item() // binheight)

if bins[iy, ix] < nfeat:
keep.append(f)
Expand Down
20 changes: 20 additions & 0 deletions tests/test_image_point_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,26 @@ def test_features_list_operations(self):
except:
pass

def test_gridify_scalar_nbins(self):
"""gridify() with a scalar nbins must not raise (regression: numpy
float // int stayed float64, bins[iy, ix] then rejected as an index)"""
img = Image.Read("monalisa.png", mono=True)
sift = img.SIFT()
self.assertGreater(len(sift), 0)

gridded = sift.gridify(nbins=4, nfeat=2)
self.assertLessEqual(len(gridded), len(sift))

def test_gridify_tuple_nbins(self):
"""gridify() with a (nw, nh) tuple must not raise, same root cause
as the scalar case above."""
img = Image.Read("monalisa.png", mono=True)
sift = img.SIFT()
self.assertGreater(len(sift), 0)

gridded = sift.gridify(nbins=(4, 3), nfeat=2)
self.assertLessEqual(len(gridded), len(sift))

def test_feature_properties(self):
"""Test feature properties"""
img = Image.Read("monalisa.png", mono=True)
Expand Down
Loading