SMIL  1.0.4
blob_measures.py
1 from smilPython import *
2 
3 # Load an image
4 imIn = Image("https://smil.cmm.minesparis.psl.eu/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 = blobsBoundBox(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 = blobsArea(imLbl, blobs) # equivalent but faster than measAreas(imLbl)
24 # barycenters
25 barys = blobsBarycenter(imLbl, blobs)
26 # volume of blobs in imIn
27 vols = blobsVolume(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 
map< T, Vector_double > blobsBarycenter(const Image< T > &imLbl, const bool onlyNonZero=true)
blobsBarycenter() - Measure barycenter of a labeled image.
Definition: DBlobMeasures.hpp:209
map< labelT, double > blobsVolume(const Image< T > &imIn, map< labelT, Blob > &blobs)
blobsVolume() - Measure the sum of values of each blob in imIn.
Definition: DBlobMeasures.hpp:91
map< T, Blob > computeBlobs(const Image< T > &imIn, bool onlyNonZero=true)
Create a map of blobs from a labeled image.
Definition: DBlob.hpp:98
map< T, vector< size_t > > blobsBoundBox(const Image< T > &imLbl, const bool onlyNonZero=true)
blobsBoundBox() - Measure bounding boxes of labeled image.
Definition: DBlobMeasures.hpp:239
map< T, double > blobsArea(const Image< T > &imLbl, const bool onlyNonZero=true)
blobsArea() - Calculate the area of each region in a labeled image
Definition: DBlobMeasures.hpp:60
RES_T drawOverlay(const Image< T > &imToDraw, Image< T > &imOut)
Draw overlay.
Definition: DImage.hpp:516
RES_T drawRectangles(Image< T > &imOut, const map< MapT, vector< size_t >> &coordsVectMap, bool fill=false)
Draw a list of rectangles.
Definition: DImageDraw.hpp:197
RES_T threshold(const Image< T > &imIn, T minVal, T maxVal, T_out trueVal, T_out falseVal, Image< T_out > &imOut)
threshold() - Image threshold
Definition: DImageHistogram.hpp:269
size_t label(const Image< T1 > &imIn, Image< T2 > &imOut, const StrElt &se=DEFAULT_SE)
label() - Image labelization
Definition: DMorphoLabel.hpp:564