##### Contents

Demonstrate blob measurements and display.

# Description

In this example, a binary image with many blobs is processed. The objective is to measure the area of each blob. First the blobs are labeled. To display the correspondent label number of each blob, a trick is used to dilate each labeled centroid by a structuring element formed by the number of the blob label. At final, the area of each blob is plotted against its label number.

# Script

The binary image is read and then labeled. The number of blobs is measured as the maximum label value. Both images are displayed.

```01. from ia870 import ialabel
02. from ia870 import iaglblshow
03. from ia870 import iastats
04.
05.
07. fr = ialabel(f)
10. nblobs=iastats(fr,'max')
11. print 'nblos=',nblobs```
```nblos= 18
```

## Centroids

The centroids are computed from the labeled image. After, the centroid image is labeled, so that each centroid point has a label value varying from 1 to the maximum number of blobs. For display illustration, the centroids are overlayed on the original blob image on the left and the labeled centroids are enlarged and displayed on the right.

```1. from ia870 import iablob, iadil, iagshow
2.
3. c  = iablob(fr,'centroid')
4. cr = ialabel(c)

## Placing a number on a particular blob

To place a particular number on a particular blob, a number image is generated using the iatext function and converted to a structuring element. A particular centroid is selected by comparing the image with the labeled number. This output image is a binary image with a single point at that centroid. Dilating this image by the structuring element will stamp the structuring element on the centroid.

```1. from ia870 import iatext, iadil, iagshow
2.
3. fbin = (cr == 5)
4. b5   = iatext('5')

## Placing a label number to each labeled blob

To automate the process just described, a loop scans every label value and stamp its number in a final image. The stamps are accumulated with the iaunion function. The area is computed and plotted against each label blob number.

```01. from ia870 import iasubm
02. from ia870 import iaunion
03.
04. facc=iasubm(f,f)
05. for i in range(1,int(nblobs+1)):
06.   fbin = (cr == i)
07.   bi   = iatext(str(i))