SMIL  0.11.3-dev
Operations using blobs

Detailed Description

+ Collaboration diagram for Operations using blobs:

Functions

template<typename T1 , typename T2 >
RES_T areaThreshold (const Image< T1 > &imIn, const int threshold, const bool gt, Image< T2 > &imOut)
 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< T1 > &  imIn,
const int  threshold,
const bool  gt,
Image< T2 > &  imOut 
)

areaThreshold() -

Parameters
[in]imIn: input image (binary or labeled)
[in]threshold: threshold level
[in]gt: blobs which area is greater than will be retained if gt is true, and lesser than if gt is false.
[out]imOut: output image
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