Usage examples of VT tools¶
from timagetk.io import imread
from timagetk.io.image import _image_from_url
/builds/J-gEBwyb/0/mosaic/timagetk/src/timagetk/components/labelled_image.py:31: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from tqdm.autonotebook import tqdm
tmp_path = _image_from_url('https://zenodo.org/record/7151866/files/p58-t0-imgSeg.inr.gz',
hash_value='3e9259e801c39ec5f8f235deeb8e936c', hash_method='md5')
image = imread(tmp_path)
0%| | 0.00/2.51M [00:00<?, ?B/s]
37%|███▋ | 960k/2.51M [00:00<00:00, 9.70MB/s]
79%|███████▊ | 1.97M/2.51M [00:00<00:00, 10.1MB/s]
2.53MB [00:00, 10.4MB/s]
from vt.cellproperties import cellProperties
from vt import vtCellProperties
Using cellProperties¶
cp = cellProperties(image.to_vtimage())
volumes = cp.volume()
print(len(volumes))
1040
dir(cp)
['__class__',
'__delattr__',
'__dict__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__le__',
'__lt__',
'__module__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__sizeof__',
'__str__',
'__subclasshook__',
'__weakref__',
'barycenter',
'contactsurface',
'covariance',
'eigenvalue',
'eigenvector',
'print',
'properties',
'surface',
'volume',
'write']
Using vtCellProperties¶
vtcp = vtCellProperties(image.to_vtimage())
labels = vtcp.getLabels()
print(len(labels))
1040
volumes = {l: vtcp.getVolume(l) for l in labels}
print(len(volumes))
1040
print(f"List of methods from `vtCellProperties`: {[m for m in dir(vtcp) if not m.startswith('__')]}")
List of methods from `vtCellProperties`: ['getBarycenter', 'getCovariance', 'getEigenvalues', 'getEigenvectors', 'getLabels', 'getNeighborsLabels', 'getNeighborsSurfaces', 'getSurface', 'getVolume', 'print', 'write']
Using handmade test array¶
import numpy as np
from timagetk.components.labelled_image import LabelledImage
from vt import vtCellProperties
image = LabelledImage(np.ones((10,10,10), dtype='uint16'), voxelsize=[0.5, 0.5, 0.5], not_a_label=0)
zsh, ysh, xsh = (5, 10, 10) # the shape of label `2`, ZYX sorted
image[:zsh, :ysh, :xsh] = 2
WARNING [timagetk.components.spatial_image] Undefined parameter ``axes_order``, using default: ZYX
WARNING [timagetk.components.spatial_image] Undefined parameter ``origin``, using default: [0, 0, 0]
WARNING [timagetk.components.spatial_image] Undefined parameter ``unit``, using default: 1e-06
vtcp = vtCellProperties(image.to_vtimage())
Labels¶
labels = vtcp.getLabels()
print(labels)
[1 2]
Volumes¶
volume = vtcp.getVolume(2)
print(volume) # should be equal to: 'zsh * ysh * xsh'
500
np.prod((zsh, ysh, xsh))
500
Areas¶
area = vtcp.getSurface(2)
print(area) # should be equal to: '(ysh-1) * (xsh-1)'
75.08695983886719
np.prod((ysh-1, xsh-1))
81