Fourier slice extraction/insertion in PyTorch.
Project description
torch-fourier-slice
Fourier slice extraction/insertion from 2D images and 3D volumes in PyTorch.
Overview
This package provides a simple API for back projection (reconstruction) and forward projection of 3D volumes using Fourier slice insertion and extraction. This can be done for
- single volumes with
project_3d_to_2d()andbackproject_2d_to_3d() - and multichannel volumes with
project_3d_to_2d_multichannel()andbackproject_2d_to_3d_multichannel()
There are also some lower order layers in the package that run directly on Fourier transforms of volumes/images which can be relevant if the fourier transform can be precalculated:
extract_central_slices_rfft_3d(),extract_central_slices_rfft_3d_multichannel()insert_central_slices_rfft_3d(),insert_central_slices_rfft_3d_multichannel()
The package also provides a use case for extracting common lines from 2D images with project_2d_to_1d which can be useful for tilt-axis angle optimization in cryo-ET.
Installation
pip install torch-fourier-slice
Usage
Single volume
import torch
from scipy.stats import special_ortho_group
from torch_fourier_slice import project_3d_to_2d, backproject_2d_to_3d
# start with a volume
volume = torch.rand((30, 30, 30))
# and some random rotations
rotation_matrices = torch.tensor(special_ortho_group.rvs(dim=3, size=10))
# shape is (10, 3, 3)
# forward project the volume, provides 10 projection images
projections = project_3d_to_2d(volume, rotation_matrices)
# shape is (10, 30, 30)
# we can backproject the 10 images to get the original volume back
reconstruction = backproject_2d_to_3d(projections, rotation_matrices)
# shape is (30, 30, 30)
# we can have an arbitrary number of leading dimensions for the rotations
rotation_matrices = torch.rand(3, 10, 3, 3)
projections = project_3d_to_2d(volume, rotation_matrices)
# shape is (3, 10, 30, 30)
# but for reconstruction it needs to match up with the projections
reconstruction = backproject_2d_to_3d(
projections, # (3, 10, 30, 30)
rotation_matrices # (3, 10, 3, 3)
)
# shape is (30, 30, 30
Multichannel volumes
import torch
from scipy.stats import special_ortho_group
from torch_fourier_slice import project_3d_to_2d_multichannel, backproject_2d_to_3d_multichannel
# now we start with a multichannel 3d volume
volume = torch.rand((5, 30, 30, 30))
# and some random rotations
rotation_matrices = torch.tensor(special_ortho_group.rvs(dim=3, size=10))
# shape is (10, 3, 3)
# forward project the volume, provides 10 projection images with 5 channels each
projections = project_3d_to_2d_multichannel(volume, rotation_matrices)
# shape is (10, 5, 30, 30)
# we can backproject the 10 multichannel images to get the original multichannel volume back
reconstruction = backproject_2d_to_3d_multichannel(projections, rotation_matrices)
# shape is (5, 30, 30, 30)
# we can have an arbitrary number of trailing dimensions as well for multichannel data
rotation_matrices = torch.rand(3, 10, 3, 3)
projections = project_3d_to_2d_multichannel(volume, rotation_matrices)
# shape is (3, 10, 5, 30, 30)
# but for reconstruction it needs to match up with the projections
reconstruction = backproject_2d_to_3d_multichannel(
projections, # (3, 10, 5, 30, 30)
rotation_matrices # (3, 10, 3, 3)
)
# shape is (5, 30, 30, 30)
License
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.
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
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 torch_fourier_slice-0.4.0.tar.gz.
File metadata
- Download URL: torch_fourier_slice-0.4.0.tar.gz
- Upload date:
- Size: 28.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a91e96b63141249b8bf8ad00009f787e409f0cfa2d609fb23a4bfe479eec93a
|
|
| MD5 |
41d943d7b3d5959c92cdd2e375fd6100
|
|
| BLAKE2b-256 |
8ad2a6f16d9495e56b2229932d0b56026e3e41b3a58be1e8e93c57c722c7d549
|
Provenance
The following attestation bundles were made for torch_fourier_slice-0.4.0.tar.gz:
Publisher:
ci.yml on teamtomo/torch-fourier-slice
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torch_fourier_slice-0.4.0.tar.gz -
Subject digest:
5a91e96b63141249b8bf8ad00009f787e409f0cfa2d609fb23a4bfe479eec93a - Sigstore transparency entry: 802816814
- Sigstore integration time:
-
Permalink:
teamtomo/torch-fourier-slice@8040ad56e1e65bc798b79dbb4c9eafb444c9671a -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/teamtomo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@8040ad56e1e65bc798b79dbb4c9eafb444c9671a -
Trigger Event:
push
-
Statement type:
File details
Details for the file torch_fourier_slice-0.4.0-py3-none-any.whl.
File metadata
- Download URL: torch_fourier_slice-0.4.0-py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d9a3db58b6de40597dcc11eba80e14eb722a2a8f081e2bbb5580567aca74b36
|
|
| MD5 |
44683d1f7fa813a7abfd9e212acec776
|
|
| BLAKE2b-256 |
684dae5c74f153ce1ff2bee8831b112cd6a6419c5ceaa3cde93fb6e93138b008
|
Provenance
The following attestation bundles were made for torch_fourier_slice-0.4.0-py3-none-any.whl:
Publisher:
ci.yml on teamtomo/torch-fourier-slice
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torch_fourier_slice-0.4.0-py3-none-any.whl -
Subject digest:
0d9a3db58b6de40597dcc11eba80e14eb722a2a8f081e2bbb5580567aca74b36 - Sigstore transparency entry: 802816885
- Sigstore integration time:
-
Permalink:
teamtomo/torch-fourier-slice@8040ad56e1e65bc798b79dbb4c9eafb444c9671a -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/teamtomo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@8040ad56e1e65bc798b79dbb4c9eafb444c9671a -
Trigger Event:
push
-
Statement type: