Skip to content

Commit f538ff5

Browse files
committed
fix more bugs in moment handling
1 parent fa536c8 commit f538ff5

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/machinevisiontoolbox/ImageBlobs.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ def __init__(self, image=None, kulpa=True, **kwargs):
353353
for child in blob.children:
354354
# subtract moments of the child
355355
M = {key: M[key] - allblobs[child].moments[key] for key in M}
356+
blob.moments = M
356357

357358
## centroid
358359
if M["m00"] == 0:
@@ -393,8 +394,9 @@ def __init__(self, image=None, kulpa=True, **kwargs):
393394
) ** 2
394395

395396
for blob in allblobs:
397+
M = blob.moments
396398
# convert moments dict to named tuple, easier to access using dot notation
397-
blob.moments = namedtuple("moment_tuple", moments.keys())(*moments.values())
399+
blob.moments = namedtuple("moment_tuple", M.keys())(*M.values())
398400

399401
## third pass, region tree coloring to determine vertex depth
400402
# level 0 is a parent, level > 0 is a child
@@ -2127,6 +2129,25 @@ def blobs(self, **kwargs):
21272129
from machinevisiontoolbox import Image
21282130
import matplotlib.pyplot as plt
21292131

2132+
im = Image.String(
2133+
r"""
2134+
..........
2135+
..###.....
2136+
..###.....
2137+
..###.....
2138+
..........
2139+
....####..
2140+
....####..
2141+
....####..
2142+
....####..
2143+
..........
2144+
""",
2145+
binary=True,
2146+
)
2147+
blobs = im.blobs()
2148+
print(blobs)
2149+
pass
2150+
21302151
# im = Image.Read("sharks.png")
21312152
# blobs = im.blobs()
21322153
# im.disp()

0 commit comments

Comments
 (0)