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. As described in the preprint.
Spherical Textures can be used in ilastik, or as a conda installable Python API.
(caption under tooltip)
Usage in ilastik
Spherical textures are available in ilastik, where it is available as a feature in the Object Classification pipeline. Further documentation for using Spherical Textures in ilastik is available at ilastik, and issues can be logged at the image.sc forum.
In brief:
- Open any Object Classification pipeline
- Add a label-mask/segmentation mask/pixel prediction map (depending on the pipeline)
- In the Feature Selection, select Spherical Texture
Spherical Textures in ilastik is supported via the ilastik-sphericaltexture bridge.
Python API
Installing
We recommend installing with conda from conda-forge
conda create -n sphericaltexture_env -c conda-forge sphericaltexture
Note: Consider updating conda if this takes over a minute.
alternatively, one can also install through pip with
pip install SphericalTexture
Usage as API
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. Note that this function expects a single object at a time without padding, and any mask management should be handled upstream from Spherical Texture generation.
The center of projection can (optionally) be set, with a numpy array with the coordinate of the center of projection in image space.
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, center_of_projection=np.array([10,10,10]))
# 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:
- Shape
- Takes the distance from the center to the edge of the mask
- Intensity
- Takes the average intensity along each ray
Subsequently, these values 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
Spectrumbinned along a log2 axis by integration.
- a 20-value version of the
- Polarization Direction
- location of the highest value in the projection in radians
- Full Projection
- The entire circular or spherical projection
- Complex Decomposition
- The Fourier/Spherical Harmonics decomposition of the circular/spherical projection.
Plotting
Some convenience functions for plotting are bundled, notably for gathering data into long-form, with appended spherical harmonics degree, and for plotting condensed spectra. These require the added library seaborn. Here is an example workflow that also utilizes scipy:
from scipy.ndimage import find_objects
import numpy as np
import sphericaltexture
for separate objects in one image:
# Generate example data
img = np.random.randint(0,1000, (10,10,25))
mask = np.concatenate([np.ones((10, 10, 5)) * ix for ix in range(5)], axis=-1).astype('uint32')
# loop through objects and record all in a dictionary
stg = sphericaltexture.SphericalTextureGenerator()
results = []
for obj_id, objslice in enumerate(find_objects(mask)):
result = stg.process_image(img[objslice], mask[objslice])
result['obj_id'] = obj_id
results.append(result)
# Plotting
df = sphericaltexture.list_of_dicts_to_dataframe(results, "Intensity Condensed Spectrum") # select which output
sphericaltexture.plot_condensed_spectra(df, groupkey=None, unitkey='obj_id', palette=None)
for separate objects in multiple images
# Generate example data with 5 objects per image, 3 images at different scales (5-pixel thick objects for convenience of generation)
imgs = []
masks = []
for scale in [10, 20, 30]:
imgs.append(np.random.randint(0,1000, (scale,scale,25)))
masks.append(np.concatenate([np.ones((scale, scale, 5)) * ix for ix in range(5)], axis=-1).astype('uint32'))
# loop through images and objects and record all in a list of dictionaries
stg = sphericaltexture.SphericalTextureGenerator()
results = []
for img_id, (img, mask) in enumerate(zip(imgs, masks)):
for obj_id, objslice in enumerate(find_objects(mask)):
result = stg.process_image(img[objslice], mask[objslice])
result['obj_id'] = obj_id
result['img_id'] = img_id
results.append(result)
# Plotting
df = sphericaltexture.list_of_dicts_to_dataframe(results, "Intensity Condensed Spectrum") # select which output
sphericaltexture.plot_condensed_spectra(df, groupkey='img_id', unitkey='obj_id', palette=None)
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. Higher values give more resolution but will take longer to calculate. However, for many applications in biology, going beyond 80 apppears to yield diminishing returns, according to our anecdotal evidence.
Speed
The first time you run this with a new shape or ndim parameter a new projection map needs to be constructed. This projection map is cached in a local folder to increase the speed subsequently.
Spherical Texture generation is optimized for parallel processing, such as in 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sphericaltexture-0.1.1.tar.gz.
File metadata
- Download URL: sphericaltexture-0.1.1.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
842f8f93d7d06ae8f079db1f92bd603b41e53c47da7ba5d7d6381d17e0843066
|
|
| MD5 |
e455cf7c5b02c835fed193d50262378e
|
|
| BLAKE2b-256 |
6e1a17a99d8a5cc3c8368fe593f6341083167e243269f5aa5f031051ac7f3749
|
Provenance
The following attestation bundles were made for sphericaltexture-0.1.1.tar.gz:
Publisher:
build-upload.yml on KoehlerLab/SphericalTexture
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphericaltexture-0.1.1.tar.gz -
Subject digest:
842f8f93d7d06ae8f079db1f92bd603b41e53c47da7ba5d7d6381d17e0843066 - Sigstore transparency entry: 154177079
- Sigstore integration time:
-
Permalink:
KoehlerLab/SphericalTexture@9fe812a0ff7ca5b2b0c1338124fa841de0c0cad8 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/KoehlerLab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-upload.yml@9fe812a0ff7ca5b2b0c1338124fa841de0c0cad8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file sphericaltexture-0.1.1-py3-none-any.whl.
File metadata
- Download URL: sphericaltexture-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfef29a3333bd3207a0dd70dfac0d407c39ec8a3b3ca4e35a50e3fe666d94ef9
|
|
| MD5 |
b0c0b9b424fe32dfeb6961780abba60e
|
|
| BLAKE2b-256 |
e66eb83eea22beb0bb677b5725b71b90b15c54eff101c6f4ec23db2d527ba559
|
Provenance
The following attestation bundles were made for sphericaltexture-0.1.1-py3-none-any.whl:
Publisher:
build-upload.yml on KoehlerLab/SphericalTexture
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sphericaltexture-0.1.1-py3-none-any.whl -
Subject digest:
cfef29a3333bd3207a0dd70dfac0d407c39ec8a3b3ca4e35a50e3fe666d94ef9 - Sigstore transparency entry: 154177081
- Sigstore integration time:
-
Permalink:
KoehlerLab/SphericalTexture@9fe812a0ff7ca5b2b0c1338124fa841de0c0cad8 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/KoehlerLab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-upload.yml@9fe812a0ff7ca5b2b0c1338124fa841de0c0cad8 -
Trigger Event:
push
-
Statement type: