SMIL  1.0.3
Operations using blobs

Detailed Description

+ Collaboration diagram for Operations using blobs:

Functions

template<typename T >
RES_T areaThreshold (const Image< T > &imIn, const int threshold, Image< T > &imOut, const bool gt=true)
 areaThreshold() - More...
 
template<typename T , typename labelT >
map< labelT, Vector_doubleblobsInertiaMatrix (const Image< T > &imIn, map< labelT, Blob > &blobs, const bool central=false)
 blobsInertiaMatrix() - More...
 
template<typename T >
map< T, Vector_doubleblobsInertiaMatrix (const Image< T > &imLbl, const bool onlyNonZero=true, const bool central=false)
 blobsInertiaMatrix() - More...
 

Function Documentation

◆ areaThreshold()

RES_T smil::areaThreshold ( const Image< T > &  imIn,
const int  threshold,
Image< T > &  imOut,
const bool  gt = true 
)

areaThreshold() -

Parameters
[in]imIn: input binary image
[in]threshold: threshold level
[out]imOut: output image
[in]gt: blobs which area is greater than will be retained if gt is true, and lesser than if gt is false.
Note
  • output image is of the same kind of input image : binary or labeled.

Example

import smilPython as sp
import time
thresh = 1000
im = sp.Image("https://smil.cmm.minesparis.psl.eu/images/balls.png")
iml = sp.Image(im)
img = sp.Image(im)
ims = sp.Image(im)
sp.label(im, iml)
im.show("balls.png")
iml.showLabel("iml")
sp.areaThreshold(iml, thresh, True, img)
img.showLabel("img")
sp.areaThreshold(im, thresh, False, ims)
ims.show("ims")
nlold = 0
for threshold in range(1, 6000, 20):
sp.areaThreshold(im, threshold, True, ims)
nl = sp.label(ims, iml)
if nl != nlold:
print(' Threshold {:6d} : {:3d} blobs'.format(threshold, nl))
sp.Gui.processEvents()
time.sleep(1)
if nl == 0:
break
nlold = nl

◆ blobsInertiaMatrix() [1/2]

map<labelT, Vector_double> smil::blobsInertiaMatrix ( const Image< T > &  imIn,
map< labelT, Blob > &  blobs,
const bool  central = false 
)

blobsInertiaMatrix() -

Parameters
[in]imIn: input image
[in]blobs: blobs in the image
[in]central: blobs centered on their barycenters

Example

import smilPython as sp
import numpy as np
from numpy import linalg as la
# get image
imIn = sp.Image("https://smil.cmm.minesparis.psl.eu/images/tools.png")
# labelize input image
imThr = sp.Image(imIn)
sp.topHat(imIn, imThr, sp.hSE(20))
sp.threshold(imThr, imThr)
imLbl = sp.Image(imIn, "UINT16")
sp.label(imThr, imLbl)
# compute blobs and get their data
blobs = sp.computeBlobs(imLbl)
central = True
inertia = sp.blobsInertiaMatrix(imIn, blobs, central)
barys = sp.blobsBarycenter(imIn, blobs)
nshape = (2, 2)
if imIn.getDimension() == 3:
nshape = (3, 3)
for k in inertia.keys():
print("=" * 64)
s = ""
for v in barys[k]:
s += " {:6.1f}".format(v)
print("Blob label : {:3d} - Barycenter :{:}".format(k, s))
# Smil returns inertia matrix as a vector. Reshape it.
xi = np.array(inertia[k])
xi = xi.reshape(nshape)
np.set_printoptions(precision=3)
print(" ====== Inertia Matrix")
print(xi)
# let numpy evaluate eingenvalues and eingenvectors
w, v = la.eig(xi)
print(" ====== Eingenvalues")
print(w)
print(" ====== Eingenvectors")
print(v)

◆ blobsInertiaMatrix() [2/2]

map<T, Vector_double> smil::blobsInertiaMatrix ( const Image< T > &  imLbl,
const bool  onlyNonZero = true,
const bool  central = false 
)

blobsInertiaMatrix() -

Parameters
[in]imLbl: input labeled image
[in]onlyNonZero:
[in]central: blobs centered on their barycenters