SMIL  0.8
 All Classes Functions Variables Groups Pages
blob_measures.py

1 from smilPython import *
2 
3 # Load an image
4 imIn = Image("http://cmm.ensmp.fr/~faessel/smil/images/DNA_small.png")
5 imIn.show()
6 
7 imThr = Image(imIn)
8 threshold(imIn, imThr)
9 
10 imLbl = Image(imIn, "UINT16")
11 label(imThr, imLbl)
12 imLbl.showLabel()
13 
14 # Bounding boxes
15 bboxes = measBoundBoxes(imLbl)
16 imRec = Image(imIn)
17 drawRectangles(imRec, bboxes)
18 imIn.getViewer().drawOverlay(imRec)
19 
20 # Blobs measures
21 blobs = computeBlobs(imLbl)
22 # areas
23 areas = measAreas(imLbl, blobs) # equivalent but faster than measAreas(imLbl)
24 # barycenters
25 barys = measBarycenters(imLbl, blobs)
26 # volume of blobs in imIn
27 vols = measVolumes(imIn, blobs)
28 print("Label\tarea\tvolume\tbarycenter (x,y)")
29 for lbl in blobs.keys():
30  print(str(lbl) + "\t" + str(areas[lbl]) + "\t" + str(vols[lbl]) + "\t" + str(barys[lbl]))
31