@@ -1190,18 +1190,42 @@ def parent(self):
11901190
11911191 A parent of -1 is the image background.
11921192
1193- :seealso: :meth:`children` :meth:`level` :meth:`dotfile`
1193+ :seealso: :meth:`id` :meth:` children` :meth:`level` :meth:`dotfile`
11941194 """
11951195 return [b .parent for b in self .data ]
11961196
1197+ @property
1198+ @scalar_result
1199+ def id (self ):
1200+ """
1201+ Blob id number
1202+
1203+ :return: index of this blob
1204+ :rtype: int
1205+
1206+ Example:
1207+
1208+ .. runblock:: pycon
1209+
1210+ >>> from machinevisiontoolbox import Image
1211+ >>> im = Image.Read('multiblobs.png')
1212+ >>> blobs = im.blobs()
1213+ >>> print(blobs)
1214+ >>> blobs[5].id
1215+ >>> blobs[6].id
1216+
1217+
1218+ :seealso: :meth:`parent` :meth:`children` :meth:`level` :meth:`dotfile`
1219+ """
1220+ return [b .id for b in self .data ]
1221+
11971222 @property
11981223 @array_result
11991224 def children (self ):
12001225 """
12011226 Child blobs
12021227
1203- :return: list of indices of this blob's children
1204- :rtype: list of int
1228+ :return: list of indices of this blob's children :rtype: list of int
12051229
12061230 Example:
12071231
@@ -1708,10 +1732,12 @@ def plot_labelbox(self, label=None, **kwargs):
17081732 :seealso: :meth:`plot_box` :meth:`plot_centroid` :meth:`plot_perimeter` :func:`~machinevisiontoolbox.base.graphics.plot_labelbox`
17091733 """
17101734
1711- for blob in enumerate ( self ) :
1735+ for blob in self :
17121736 if label is None :
1713- label = f"{ blob .id } "
1714- plot_labelbox (text = label , lrbt = blob .bbox , ** kwargs )
1737+ text = f"{ blob .id } "
1738+ else :
1739+ text = label
1740+ plot_labelbox (text = text , lrbt = blob .bbox , ** kwargs )
17151741
17161742 def plot_centroid (self , label = False , ** kwargs ):
17171743 """
@@ -2171,6 +2197,9 @@ def blobs(self, **kwargs):
21712197
21722198 im = Image .Read ("sharks.png" )
21732199 blobs = im .blobs ()
2200+ im .disp ()
2201+ blobs .plot_labelbox (color = "yellow" )
2202+ plt .show (block = True )
21742203 # frames = SE2.Empty()
21752204 # for blob in blobs:
21762205 # frames.append(SE2(*blob.centroid, blob.orientation))
0 commit comments