Skip to content

Commit ab6430c

Browse files
committed
get rid of transforms3d dependency
1 parent 6e407a1 commit ab6430c

3 files changed

Lines changed: 55 additions & 11 deletions

File tree

.github/workflows/test_and_deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
python --version
3838
conda install -y pyopencl
3939
python -m pip install --upgrade pip
40-
pip install setuptools wheel pytest pytest-cov pytest-benchmark dask networkx igraph pandas scikit-image transforms3d
40+
pip install setuptools wheel pytest pytest-cov pytest-benchmark dask networkx igraph pandas scikit-image
4141
4242
- name: Test
4343
shell: bash -l {0}

pyclesperanto_prototype/_tier8/_AffineTransform3D.py

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from warnings import warn
22

33
import numpy as np
4-
import transforms3d
54
import math
65
from ._utilities import shear_angle_to_shear_factor
76

@@ -16,9 +15,55 @@ class AffineTransform3D:
1615
1716
"""
1817

18+
@staticmethod
19+
def _identity_matrix():
20+
return np.eye(4, dtype=float)
21+
22+
@staticmethod
23+
def _scale_matrix(sx=1.0, sy=1.0, sz=1.0):
24+
return np.asarray([
25+
[sx, 0, 0, 0],
26+
[0, sy, 0, 0],
27+
[0, 0, sz, 0],
28+
[0, 0, 0, 1],
29+
], dtype=float)
30+
31+
@staticmethod
32+
def _rotation_matrix_x(angle_in_rad):
33+
c = np.cos(angle_in_rad)
34+
s = np.sin(angle_in_rad)
35+
return np.asarray([
36+
[1, 0, 0, 0],
37+
[0, c, -s, 0],
38+
[0, s, c, 0],
39+
[0, 0, 0, 1],
40+
], dtype=float)
41+
42+
@staticmethod
43+
def _rotation_matrix_y(angle_in_rad):
44+
c = np.cos(angle_in_rad)
45+
s = np.sin(angle_in_rad)
46+
return np.asarray([
47+
[c, 0, s, 0],
48+
[0, 1, 0, 0],
49+
[-s, 0, c, 0],
50+
[0, 0, 0, 1],
51+
], dtype=float)
52+
53+
@staticmethod
54+
def _rotation_matrix_z(angle_in_rad):
55+
c = np.cos(angle_in_rad)
56+
s = np.sin(angle_in_rad)
57+
return np.asarray([
58+
[c, -s, 0, 0],
59+
[s, c, 0, 0],
60+
[0, 0, 1, 0],
61+
[0, 0, 0, 1],
62+
], dtype=float)
63+
1964
def __init__(self, transform = None, image=None):
2065
if transform is None:
21-
self._matrix = transforms3d.zooms.zfdir2aff(1)
66+
self._matrix = self._identity_matrix()
2267
if isinstance(transform, AffineTransform3D):
2368
self._matrix = np.copy(transform._matrix)
2469
if isinstance(transform, str):
@@ -56,11 +101,11 @@ def scale(self, scale_x: float = None, scale_y: float = None, scale_z: float = N
56101
warn('scale_z must not be 0')
57102
scale_z = 1
58103
if scale_x is not None:
59-
self._concatenate(transforms3d.zooms.zfdir2aff(scale_x, direction=(1, 0, 0), origin=(0, 0, 0)))
104+
self._concatenate(self._scale_matrix(sx=scale_x))
60105
if scale_y is not None:
61-
self._concatenate(transforms3d.zooms.zfdir2aff(scale_y, direction=(0, 1, 0), origin=(0, 0, 0)))
106+
self._concatenate(self._scale_matrix(sy=scale_y))
62107
if scale_z is not None:
63-
self._concatenate(transforms3d.zooms.zfdir2aff(scale_z, direction=(0, 0, 1), origin=(0, 0, 0)))
108+
self._concatenate(self._scale_matrix(sz=scale_z))
64109

65110
return self
66111

@@ -83,11 +128,11 @@ def rotate(self, axis : int = 2, angle_in_degrees : float = 0):
83128
angle_in_rad = angle_in_degrees * np.pi / 180.0
84129

85130
if axis == 0:
86-
self._concatenate(self._3x3_to_4x4(transforms3d.euler.euler2mat(angle_in_rad, 0, 0)))
131+
self._concatenate(self._rotation_matrix_x(angle_in_rad))
87132
if axis == 1:
88-
self._concatenate(self._3x3_to_4x4(transforms3d.euler.euler2mat(0, angle_in_rad, 0)))
133+
self._concatenate(self._rotation_matrix_y(angle_in_rad))
89134
if axis == 2:
90-
self._concatenate(self._3x3_to_4x4(transforms3d.euler.euler2mat(0, 0, angle_in_rad)))
135+
self._concatenate(self._rotation_matrix_z(angle_in_rad))
91136

92137
return self
93138

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ dependencies = [
3333
"pyopencl",
3434
"toolz",
3535
"scikit-image>0.20.0",
36-
"matplotlib",
37-
"transforms3d"
36+
"matplotlib"
3837
]
3938

4039
[project.urls]

0 commit comments

Comments
 (0)