Skip to main content

Angular projections of 2/3D image objects and subsequent spherical harmonics analysis

Project description

Spherical Texture Extraction

This toolkit extracts Spherical Textures: Angular projections of 2D or 3D image objects with subsequent spherical harmonics analysis.

Installing

Installing can best be done through conda with

conda install -c conda-forge sphericaltexture

or to create a dedicated environment:

conda create -n sphericaltexture_env -c conda-forge sphericaltexture

Note, this is a lot faster with an updated version of conda! If it takes over a minute, consider updating conda.

alternatively, one can also install through pip with

pip install SphericalTexture

Usage

Construct a SphericalTextureGenerator object, with the dimensionality of the data and the desired spherical projections and output types. This stg.process_image() takes an image and binary mask, and returns a dictionary with numpy arrays for each projection and output type.

    from sphericaltexture import SphericalTextureGenerator
    # all outputs:
    stg = SphericalTextureGenerator(
            ndim=3, 
            projections=['Shape','Intensity'], 
            output_types=["Spectrum", "Condensed Spectrum", "Polarization Direction", "Full Projection", "Complex Decomposition"]
        )
    results = stg.process_image(imgdata, mask)

    # only 20-value Intensity spectrum:
    stg = SphericalTextureGenerator()
    results = stg.process_image(imgdata, mask)

Rays are projected from the center of a rescaled object to capture all angles to make a spherical or circular projection. The values are saved according to the selected projections.

Implemented projections:

  • Intensity
    • Takes the average intensity along each ray
  • Shape
    • Takes the distance from the center to the edge of the mask

Subsequently, these are analyzed and saved according to the selected output type.

Implemented output types:

  • Spectrum
    • 1D power spectrum of the Fourier/Spherical Harmonics decomposition of the spherical/circular projection.
  • Condensed Spectrum
    • a 20-value version of the Spectrum binned along a log2 axis by integration.
  • Polarization Direction
    • location in rad of the highest value in the projection
  • Full Projection
    • The entire circular or spherical projection
  • Complex Decomposition
    • The Fourier/Spherical Harmonics decomposition of the spherical/circular projection.

Rescaling

Objects are rescaled to the size of the scale parameter in the creation of the SphericalTextureGenerator. This is by default 80: every object processed will be scaled to 80x80x80 pixels before projection to a sphere/circle. Lower values give more speed, higher gives more resolution. However, for many applications in biology, going much higher than 80 seems anecdotally to give diminishing returns.

Speed

The first time you run this with a new shape or ndim parameter a new projection map needs to be constructed. This is afterwards cached in a local folder, and should then subsequently be fast. Spherical Texture generation is optimized for parallel processing, such as this example:

from concurrent import futures
import numpy as np
from sphericaltexture import SphericalTextureGenerator

# 100 test images of 34x35x36 pixels
your_images = [np.random.randint(1,1e6, size=(34,35,36)) for i in range(100)]
your_masks = [np.ones((34,35,36)) for i in range(100)]

stg = SphericalTextureGenerator(
            projections=['Intensity'], 
            output_types=["Spectrum"]
        )

with futures.ThreadPoolExecutor(max_workers=10) as executor:
    jobs = [executor.submit(stg.process_image, imgdata, mask) for imgdata, mask in zip(your_images, your_masks)]
    all_results = [fut.result() for fut in futures.as_completed(jobs)]

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

sphericaltexture-0.0.3.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphericaltexture-0.0.3-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file sphericaltexture-0.0.3.tar.gz.

File metadata

  • Download URL: sphericaltexture-0.0.3.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for sphericaltexture-0.0.3.tar.gz
Algorithm Hash digest
SHA256 f2b7225fcdf9b96068574fb4c78754bfeae4e0e1d98e6f4c621e33d475d616fa
MD5 273bc1ff015480b7aabbc162e39801a1
BLAKE2b-256 58880e0763038cd0e59bf0e373ce384a95956a991518f9ed7def34b2e9b9475b

See more details on using hashes here.

File details

Details for the file sphericaltexture-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for sphericaltexture-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5dfe3db58c032316535733162072a1c8594867957e75262562a3268d1bbdcdee
MD5 d5c7e811aa380854a3931f30dab7c1ac
BLAKE2b-256 31c9f9d38513ee2c1dae4f2e46ec76efd10985f4369e042cd604d16ae5fc6370

See more details on using hashes here.

Supported by

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