Ellipsoids drawing and analysis in 3D volumetric images.
Project description
PyEllipsoid is the package for drawing and analysis of ellipsoids in 3D volumetric images (3D arrays).
Installation
The easiest way to install the latest version is by using pip:
$ pip install pyellipsoid
You may also use Git to clone the repository and install it manually:
$ git clone https://github.com/ashkarin/pyellipsoid.git $ cd pyellipsoid $ python setup.py install
How to use
To draw an ellipsoid:
import numpy as np
from pyellipsoid import drawing
# Define an image shape, axis order is: Z, Y, X
image_shape = (128, 128, 128)
# Define an ellipsoid, axis order is: X, Y, Z
ell_center = (64, 64, 64)
ell_radii = (5, 50, 30)
ell_angles = np.deg2rad([80, 30, 20]) # Order of rotations is X, Y, Z
# Draw a 3D binary image containing the ellipsoid
image = drawing.make_ellipsoid_image(image_shape, ell_center, ell_radii, ell_angles)
To compute inertia ellipsoid for given ellipsoid image:
import numpy as np
from pyellipsoid import drawing, analysis
# Draw a 3D binary image containing an ellipsoid
image_shape = (128, 128, 128)
ell_center = (64, 64, 64)
ell_radii = (5, 50, 30)
ell_angles = np.deg2rad([80, 30, 20])
image = drawing.make_ellipsoid_image(image_shape, ell_center, ell_radii, ell_angles)
# Compute inertia ellipsoid
points = analysis.sample_random_points(image)
inertia_ellipsoid = analysis.compute_inertia_ellipsoid(points)
To rotate axes and find relative rotation between the original and rotated axes:
import numpy as np
from pyellipsoid import geometry
original_axes = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
rot_angles = np.deg2rad([0, 0, 45]) # Rotate around Z-axis by 45 deg
# Build rotation matrix and rotate the axes
rotm = geometry.build_rotation_matrix(*rot_angles)
rotated_axes = np.dot(rotm, np.transpose(original_axes)).T
# Find relative rotation
rel_rotm = geometry.find_relative_axes_rotation(original_axes, rotated_axes)
# Validate relative rotation matrix
rel_rotated_axes = np.dot(rel_rotm, np.transpose(original_axes)).T
assert(np.all(rotated_axes == rel_rotated_axes))
# Compute rotation angles
# Please note, that these angles might differ from rot_angles!
rel_rot_angles = geometry.rotation_matrix_to_angles(rel_rotm)
print(np.rad2deg(rel_rot_angles))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyellipsoid-0.0.2.tar.gz
(5.5 kB
view hashes)
Built Distributions
Close
Hashes for pyellipsoid-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2e100d6a060a7ef1952a156a281b002fab01b86a60f5dfcea9e87732d7fc3e1 |
|
MD5 | 52a97d6fb879af317f0d0667ba2f075d |
|
BLAKE2b-256 | ad085937df81cfe3117765cf430dba8167d1bb577a952be9dd0f2466a43c5987 |
Close
Hashes for pyellipsoid-0.0.2-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c01165a302879b427275b5cc8fe6c4b7d2636f610c37b46b14ff551b5b8ca68 |
|
MD5 | 2fb05db6fef56a02d477a83b7204f2c2 |
|
BLAKE2b-256 | d7a04e4b4a12a5fa428dfaaff479aeab4a69970c7e560c9ee1eab6af077ca86a |