Skip to main content

Compute cross sectional area of 3d shapes.

Project description

PyPI version

xs3d: Compute cross sectional area for 3D image objects

import xs3d

# let binary image be a boolean numpy array 
# in fortran order that is 500 x 500 x 500 voxels
# containing a shape, which may have multiple 
# connected components, representing e.g. a neuron
binary_image = np.load(...)

# a point inside the shape (must be integer)
vertex = np.array([200,121,78])
# normal vector defining sectioning plane
# it doesn't have to be a unit vector
# vector can be of arbitrary orientation
# This vector is given in voxel space, 
# not physical space (i.e. divide by anisotropy)!
normal = np.array([0.01, 0.033, 0.9])

# voxel dimensions in e.g. nanometers
resolution = np.array([32,32,40]) 

# cross sectional area returned as a float
area = xs3d.cross_sectional_area(binary_image, vertex, normal, resolution)

# optionally return a bitfield that tells you if the section
# plane touched the image border, indicating a possible
# underestimate of the area if the image is a cutout of
# a larger scene.
# if the bitfield is > 0, then some edge contact is made
# the bitfield order is -x+x-y+y-z+z00
# where - means left edge (0), and + means right edge (size-1)
# and 0 means unused
area, contact_warning = xs3d.cross_sectional_area(
	binary_image, vertex, normal, resolution, 
	return_contact=True
)

# Returns the cross section as a float32 3d image
# where each voxel represents its contribution
# to the cross sectional area
image = xs3d.cross_section(
	binary_image, vertex, 
	normal, resolution, 
)

# Get a slice of a 3d image in any orientation.
# Note: result may be reflected or transposed
# compared with what you might expect.
image2d = xs3d.slice(labels, vertex, normal, anisotropy)

Installation

pip install xs3d

Cross Section Calculation

When using skeletons (one dimensional stick figure representations) to create electrophysiological compartment simulations of neurons, some additional information is required for accuracy. The caliber of the neurite changes over the length of the cell.

Previously, the radius from the current skeleton vertex to the nearest background voxel was used, but this was often an underestimate as it is sensitive to noise and divots in a shape.

A superior measure would be the cross sectional area using a section plane that is orthogonal to the direction of travel along the neurite. This library provides that missing capability.

How Does it Work?

The algorithm roughly works as follows.

  1. Label voxels that are intercepted by the sectioning plane.
  2. Label the connected components of those voxels.
  3. Filter out all components except the region of interest.
  4. Compute the polygon formed by the intersection of the plane with the 8 corners and 12 edges of each voxel.
  5. Add up the area contributed by each polygon so formed in the component of interest.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xs3d-1.7.0.tar.gz (31.1 kB view hashes)

Uploaded Source

Built Distributions

xs3d-1.7.0-cp312-cp312-win_amd64.whl (92.9 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

xs3d-1.7.0-cp312-cp312-win32.whl (86.4 kB view hashes)

Uploaded CPython 3.12 Windows x86

xs3d-1.7.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (137.7 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

xs3d-1.7.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (130.2 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

xs3d-1.7.0-cp312-cp312-macosx_11_0_arm64.whl (95.1 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

xs3d-1.7.0-cp312-cp312-macosx_10_9_x86_64.whl (102.2 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

xs3d-1.7.0-cp311-cp311-win_amd64.whl (93.8 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

xs3d-1.7.0-cp311-cp311-win32.whl (86.9 kB view hashes)

Uploaded CPython 3.11 Windows x86

xs3d-1.7.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (137.9 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

xs3d-1.7.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (144.9 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686

xs3d-1.7.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (130.9 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

xs3d-1.7.0-cp311-cp311-macosx_11_0_arm64.whl (97.5 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

xs3d-1.7.0-cp311-cp311-macosx_10_9_x86_64.whl (104.9 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

xs3d-1.7.0-cp310-cp310-win_amd64.whl (93.3 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

xs3d-1.7.0-cp310-cp310-win32.whl (86.2 kB view hashes)

Uploaded CPython 3.10 Windows x86

xs3d-1.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (136.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

xs3d-1.7.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (143.6 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

xs3d-1.7.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (129.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

xs3d-1.7.0-cp310-cp310-macosx_11_0_arm64.whl (96.0 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

xs3d-1.7.0-cp310-cp310-macosx_10_9_x86_64.whl (103.3 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

xs3d-1.7.0-cp39-cp39-win_amd64.whl (93.1 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

xs3d-1.7.0-cp39-cp39-win32.whl (86.3 kB view hashes)

Uploaded CPython 3.9 Windows x86

xs3d-1.7.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (136.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

xs3d-1.7.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (143.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

xs3d-1.7.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (129.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

xs3d-1.7.0-cp39-cp39-macosx_11_0_arm64.whl (96.1 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

xs3d-1.7.0-cp39-cp39-macosx_10_9_x86_64.whl (103.4 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

xs3d-1.7.0-cp38-cp38-win_amd64.whl (93.3 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

xs3d-1.7.0-cp38-cp38-win32.whl (86.3 kB view hashes)

Uploaded CPython 3.8 Windows x86

xs3d-1.7.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (136.7 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

xs3d-1.7.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (143.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686

xs3d-1.7.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (129.7 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

xs3d-1.7.0-cp38-cp38-macosx_11_0_arm64.whl (95.9 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

xs3d-1.7.0-cp38-cp38-macosx_10_9_x86_64.whl (103.2 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

xs3d-1.7.0-cp37-cp37m-win_amd64.whl (93.9 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

xs3d-1.7.0-cp37-cp37m-win32.whl (86.9 kB view hashes)

Uploaded CPython 3.7m Windows x86

xs3d-1.7.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (138.8 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

xs3d-1.7.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl (145.8 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ i686

xs3d-1.7.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (132.4 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

xs3d-1.7.0-cp37-cp37m-macosx_10_9_x86_64.whl (102.9 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

xs3d-1.7.0-cp36-cp36m-win_amd64.whl (93.9 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

xs3d-1.7.0-cp36-cp36m-win32.whl (86.9 kB view hashes)

Uploaded CPython 3.6m Windows x86

xs3d-1.7.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (138.6 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

xs3d-1.7.0-cp36-cp36m-manylinux_2_17_i686.manylinux2014_i686.whl (145.8 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ i686

xs3d-1.7.0-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (132.3 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ ARM64

xs3d-1.7.0-cp36-cp36m-macosx_10_9_x86_64.whl (102.7 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page