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_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)
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)
```

## Project details

This version 0.0.2 0.0.1
{"ft_lang_label":"__label__en","ft_lang_prob":0.58565885,"math_prob":0.9570782,"size":3419,"snap":"2020-10-2020-16","text_gpt3_token_len":1041,"char_repetition_ratio":0.13440703,"word_repetition_ratio":0.12832929,"special_character_ratio":0.30915472,"punctuation_ratio":0.18505338,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99766093,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,2,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-04-04T00:34:57Z\",\"WARC-Record-ID\":\"<urn:uuid:5b0f072f-b4ae-4d3c-bbbf-71ba45c08b35>\",\"Content-Length\":\"58557\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:fc6eb18d-4211-4ac9-b883-cb28d59f6cdb>\",\"WARC-Concurrent-To\":\"<urn:uuid:893e5ffc-f0f2-452c-b244-ee9562c030d7>\",\"WARC-IP-Address\":\"151.101.192.223\",\"WARC-Target-URI\":\"https://pypi.org/project/pyellipsoid/\",\"WARC-Payload-Digest\":\"sha1:ZJ56LLV5GTDMOPIH27XXHFQOBCZ4ZMK4\",\"WARC-Block-Digest\":\"sha1:QVK4EXZBBVXXEE2KIBCKGJFTPXXPWMHP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-16/CC-MAIN-2020-16_segments_1585370518767.60_warc_CC-MAIN-20200403220847-20200404010847-00082.warc.gz\"}"}