voxel 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
voxel-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.4
2
+ Name: voxel
3
+ Version: 0.1.1
4
+ Summary: Torch framework for volumetric medical imaging structures
5
+ Author: Andrew Hoopes
6
+ Keywords: medical imaging,deep-learning,AI,MRI
7
+ Classifier: Topic :: Scientific/Engineering
8
+ Classifier: Intended Audience :: Science/Research
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: numpy
15
+ Requires-Dist: torch>=1.12
16
+
17
+ # Voxel
18
+
19
+ Core utilities for volumetric (3D) medical image analysis, written in pytorch. Voxel provides methods for working with image grid data and triangular meshes, with consideration of their representation in a world (or scanner) coordinate system. The toolbox is fully GPU compatible and developed with particular emphasis on its use for deep-learning applications. More documentation to come soon!
20
+
21
+ Voxel can be installed with:
22
+
23
+ ```
24
+ pip install voxel
25
+ ```
26
+
27
+ If you find this package useful in your work, please cite the following publication (for which this package was originally developed).
28
+ > [VoxelPrompt: A Vision Agent for End-to-End Medical Image Analysis](https://arxiv.org/abs/2410.08397)<br>
29
+ > Andrew Hoopes, Neel Dey, Victor Ion Butoi, John V. Guttag, Adrian V. Dalca
@@ -0,0 +1,31 @@
1
+ [project]
2
+ name = 'voxel'
3
+ description = 'Torch framework for volumetric medical imaging structures'
4
+ readme = 'readme.md'
5
+ keywords = ['medical imaging', 'deep-learning', 'AI', 'MRI']
6
+ classifiers = [
7
+ 'Topic :: Scientific/Engineering',
8
+ 'Intended Audience :: Science/Research',
9
+ 'Programming Language :: Python :: 3',
10
+ 'License :: OSI Approved :: MIT License',
11
+ 'Operating System :: OS Independent',
12
+ ]
13
+ authors = [
14
+ {name = 'Andrew Hoopes'}
15
+ ]
16
+ requires-python = '>=3.8'
17
+ dynamic = ['version']
18
+ dependencies = [
19
+ 'numpy',
20
+ 'torch >= 1.12',
21
+ ]
22
+
23
+ [build-system]
24
+ requires = ['setuptools']
25
+ build-backend = 'setuptools.build_meta'
26
+
27
+ [tool.setuptools]
28
+ packages = ['voxel', 'voxel.io']
29
+
30
+ [tool.setuptools.dynamic]
31
+ version = {attr = 'voxel.__version__'}
voxel-0.1.1/readme.md ADDED
@@ -0,0 +1,13 @@
1
+ # Voxel
2
+
3
+ Core utilities for volumetric (3D) medical image analysis, written in pytorch. Voxel provides methods for working with image grid data and triangular meshes, with consideration of their representation in a world (or scanner) coordinate system. The toolbox is fully GPU compatible and developed with particular emphasis on its use for deep-learning applications. More documentation to come soon!
4
+
5
+ Voxel can be installed with:
6
+
7
+ ```
8
+ pip install voxel
9
+ ```
10
+
11
+ If you find this package useful in your work, please cite the following publication (for which this package was originally developed).
12
+ > [VoxelPrompt: A Vision Agent for End-to-End Medical Image Analysis](https://arxiv.org/abs/2410.08397)<br>
13
+ > Andrew Hoopes, Neel Dey, Victor Ion Butoi, John V. Guttag, Adrian V. Dalca
voxel-0.1.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,86 @@
1
+ import itertools
2
+ import torch
3
+ import random
4
+ import voxel as vx
5
+
6
+
7
+ def all_orientations() -> list:
8
+ """
9
+ Returns all 48 possible grid orientations in world space.
10
+ """
11
+ data = ['LR', 'PA', 'IS']
12
+ choices = [(item[0], item[1]) for item in data]
13
+ orders = list(itertools.permutations(choices))
14
+ orientations = []
15
+ for order in orders:
16
+ perms = list(itertools.product(*order))
17
+ orientations.extend([''.join(p) for p in perms])
18
+ return orientations
19
+
20
+
21
+ def test_orientation_init() -> None:
22
+
23
+ # test construction from a few hardcoded orientation matrices
24
+
25
+ assert 'RAS' == vx.Orientation(vx.AffineMatrix(torch.tensor([
26
+ [1, 0, 0],
27
+ [0, 1, 0],
28
+ [0, 0, 1]])))
29
+
30
+ assert 'ILA' == vx.Orientation(vx.AffineMatrix(torch.tensor([
31
+ [ 0, -1, 0],
32
+ [ 0, 0, 1],
33
+ [-1, 0, 0]])))
34
+
35
+ assert 'PSR' == vx.Orientation(vx.AffineMatrix(torch.tensor([
36
+ [ 0, 0, 1],
37
+ [-1, 0, 0],
38
+ [ 0, 1, 0]])))
39
+
40
+
41
+ def test_orientation_equality() -> None:
42
+
43
+ # test that all orientations are equal to themselves
44
+ for name in all_orientations():
45
+ orientation = vx.Orientation(name)
46
+ assert orientation.name == name
47
+ assert orientation == vx.Orientation(name)
48
+ assert orientation == name
49
+ assert name == orientation
50
+
51
+ # double check that inequality works
52
+ assert vx.Orientation('RAS') != vx.Orientation('LPI')
53
+
54
+
55
+ def test_reorientation() -> None:
56
+
57
+ # random volume
58
+ vol = vx.Volume(torch.rand(10, 20, 30), torch.diag(torch.tensor([1, 1.2, 0.8, 1])))
59
+
60
+ # cycle through all orientations
61
+ reoriented = vol
62
+ orientations = all_orientations()
63
+ random.shuffle(orientations)
64
+ for name in orientations:
65
+
66
+ # reorienting back should give the same original volume
67
+ assert vx.volumes_equal(vol, vol.reorient(name).reorient('RAS'))
68
+
69
+ # reorient the volume
70
+ reoriented = reoriented.reorient(name)
71
+ assert reoriented.geometry.orientation == name
72
+
73
+ # make sure we get back to the original volume
74
+ assert vx.volumes_equal(vol, reoriented.reorient('RAS'))
75
+
76
+
77
+ def test_orientation_slice_direction() -> None:
78
+
79
+ shape = (10, 20, 30)
80
+ geometry = vx.AcquisitionGeometry(shape, slice_direction=1)
81
+ vol = vx.Volume(torch.ones(shape), geometry)
82
+
83
+ # make sure the explicitly-set slice direction is propagated correctly
84
+ assert vol.reorient('RAS').geometry._explicit_slice_direction == 1
85
+ assert vol.reorient('SRA').geometry._explicit_slice_direction == 2
86
+ assert vol.reorient('PIL').geometry._explicit_slice_direction == 0
@@ -0,0 +1,61 @@
1
+ import torch
2
+ import voxel as vx
3
+
4
+ from . import utility
5
+
6
+
7
+ # TODO: add a mult-frame case to all of these tests
8
+
9
+
10
+ def test_resample():
11
+
12
+ # resampling to the same resolution should not change the underlying data
13
+ vol = utility.brain_t1w()
14
+ assert vol.tensor is vol.resample_like(vol.geometry).tensor
15
+
16
+ # simple test to make sure linear and nearest interpolation are different
17
+ assert not vx.volumes_equal(vol.resample(2, mode='linear'),
18
+ vol.resample(2, mode='nearest').float())
19
+
20
+ # shifted volume should be identical to a rolled volume
21
+ resampled = vol.resample_like(vol.geometry.shift((1, 0, 0), 'voxel'))
22
+ rolled = resampled.new(vol.tensor.roll(-1, 1))
23
+ assert vx.volumes_equal(rolled[:, :-1], resampled[:, :-1])
24
+
25
+ # 2x trilinear resampling should be (nearly) identical to average pooling
26
+ resampled = vol.resample(2)
27
+ pool = torch.nn.functional.avg_pool3d
28
+ pooled = resampled.new(pool(vol.tensor.unsqueeze(0).float(), 2, 2).squeeze(0))
29
+ assert vx.volumes_equal(resampled, pooled, vol_tol=3e-3)
30
+
31
+
32
+ def test_antialiasing():
33
+
34
+ # verify that antialiasing works as expected by assuming the result
35
+ # is within a certain (manually computed) bound of the non-antialiased result.
36
+ # use source and target volumes with different non-isotropic resolutions and orientations
37
+ vol = utility.brain_t1w().reorient('LIA').resample((0.8, 0.9, 0.8))
38
+ target = vol.geometry.reorient('SPL').resample((1.5, 1.5, 5)).rotate((-10, 15, 10), 'world')
39
+ aa = vol.resample_like(target, antialias=True)
40
+ noaa = vol.resample_like(target, antialias=False)
41
+ error = (aa - noaa).abs().quantile(0.99)
42
+ assert error > 35 and error < 36
43
+
44
+ # make sure smoothing is not applied in situations where it should not be
45
+ # i.e. when the downsampling factor is less than 2
46
+ vol = utility.brain_t1w().reorient('IRP').resample((1.8, 1.8, 2))
47
+ target = vol.geometry.reorient('ALS').resample((2.5, 0.6, 0.6))
48
+ aa = vol.resample_like(target, antialias=True)
49
+ noaa = vol.resample_like(target, antialias=False)
50
+ assert vx.volumes_equal(aa, noaa)
51
+
52
+
53
+ def test_point_sampling():
54
+
55
+ # make sure that sampling a volume at its own grid points and reshaping
56
+ # the result back to the original shape gives the original volume
57
+ vol = utility.brain_t1w()
58
+ points = vx.volume.volume_grid(vol.baseshape).view(-1, 3)
59
+ sampled = vol.sample(points, space='voxel', mode='nearest').swapaxes(0, 1)
60
+ reshaped = vol.new(sampled.view(vol.shape))
61
+ assert (reshaped == vol).all()
@@ -0,0 +1,37 @@
1
+ __version__ = '0.1.1'
2
+
3
+ from . import caching
4
+ from . import slicing
5
+ from . import filters
6
+
7
+ from . import space
8
+ from .space import Space
9
+
10
+ from . import affine
11
+ from .affine import AffineMatrix
12
+ from .affine import AffineVolumeTransform
13
+
14
+ from . import bounds
15
+ from .bounds import BoundingBox
16
+ from .bounds import load_bounding_box
17
+
18
+ from . import acquisition
19
+ from .acquisition import AcquisitionGeometry
20
+ from .acquisition import Orientation
21
+ from .acquisition import cast_orientation
22
+ from .acquisition import cast_acquisition_geometry
23
+
24
+ from . import volume
25
+ from .volume import Volume
26
+ from .volume import volumes_equal
27
+
28
+ from . import mesh
29
+ from .mesh import Mesh
30
+
31
+ from . import io
32
+ from .io.volume import load_volume
33
+ from .io.volume import save_volume
34
+ from .io.mesh import load_mesh
35
+ from .io.mesh import save_mesh
36
+ from .io.affine import load_affine
37
+ from .io.affine import save_affine