#!/usr/bin/env python # coding: utf-8 # # Doing Measures on Images # In[1]: # import smilPython import smilPython as sp # functions using matplotlib to display images on jupyter notebooks from smilPlot import * import numpy as np # ## Let's begin # # In[2]: # Load an image imIn = sp.Image("http://smil.cmm.mines-paristech.fr/images/DNA_small.png") #imIn.show() imThr = sp.Image(imIn) sp.threshold(imIn, imThr) imLbl = sp.Image(imIn, "UINT16") sp.label(imThr, imLbl) smilPlot([imIn, imLbl], label = [False, True]) # In[3]: # Bounding boxes bboxes = sp.measBoundBoxes(imLbl) imRec = sp.Image(imIn) #sp.drawRectangles(imRec, bboxes) imIn.getViewer().drawOverlay(imRec) # Blobs measures blobs = sp.computeBlobs(imLbl) # areas areas = sp.measAreas(blobs) # equivalent but faster than measAreas(imLbl) # barycenters barys = sp.measBarycenters(imLbl, blobs) # volume of blobs in imIn vols = sp.measVolumes(imIn, blobs) # Print results print("{0:5s} {1:6s} {2:8s} {3:s}".format("Label", " Area", " Volume", " Barycenter (x,y)")) for lbl in blobs.keys(): print("{0:5d} {1:6.1f} {2:8.1f} ( {3:8.3f} {4:8.3f} )". format(lbl, areas[lbl], vols[lbl], barys[lbl][0], barys[lbl][1])) # In[ ]: