Skip to main content

Shift 2D/3D images by phase shifting Fourier transforms in PyTorch

Project description

torch-phase-shift

License PyPI Python Version CI codecov

torch-fourier-shift is a package for shifting 1D, 2D and 3D images with subpixel precision by applying phase shifts to Fourier transforms in PyTorch.

A 2D image and the shifted result

import torch
from torch_fourier_shift import fourier_shift_image_2d

# create a dummy image
my_image = torch.tensor(
    [[0, 0, 0, 0, 0, 0],
     [0, 1, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0],
     [0, 0, 0, 0, 0, 0]]
)

# shift the image by 1 pixel in dim 0, 2 pixels in dim 1
shifted_image = fourier_shift_image_2d(image=my_image, shifts=torch.tensor([1, 2]))

API's are equivalent for 1D and 3D images.

Installation

torch-fourier-shift is available on PyPI.

pip install torch-fourier-shift

Usage

Please check the the docs at teamtomo.org/torch-fourier-shift

Caching

Some functions are equipped with an argument called cache_intermediates. If you set cache_intermediates=True, an LRU cache will be used to avoid recomputing intermediate results. Note that this might affect gradient calculations.

By default, the size of the cache is 3, and can be changed with an environmental variable called TORCH_FOURIER_SHIFT_CACHE_SIZE. Just do

export TORCH_FOURIER_SHIFT_CACHE_SIZE=5

or

os.environ["TORCH_FOURIER_SHIFT_CACHE_SIZE"]=5

before importing the torch_fourier_shift module.

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

torch_fourier_shift-0.1.0.tar.gz (49.9 kB view details)

Uploaded Source

Built Distribution

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

torch_fourier_shift-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file torch_fourier_shift-0.1.0.tar.gz.

File metadata

  • Download URL: torch_fourier_shift-0.1.0.tar.gz
  • Upload date:
  • Size: 49.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for torch_fourier_shift-0.1.0.tar.gz
Algorithm Hash digest
SHA256 322ae23ce7cfcee3aea163fc583df13ccbe37edc722ceddc6e3df9cb7b62bb03
MD5 484a27163096a7bf1be865743ec93627
BLAKE2b-256 ccbc0b0a2e64ce84533284b0fdf4b1405d2822631833dff5469534d8c1b6017f

See more details on using hashes here.

Provenance

The following attestation bundles were made for torch_fourier_shift-0.1.0.tar.gz:

Publisher: ci.yml on teamtomo/torch-fourier-shift

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file torch_fourier_shift-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for torch_fourier_shift-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82929a1d35c82589bcd443b0cba22a6d610769ecfd50aa001f585d4963dc799c
MD5 e64eb4975df9b12e5ed61844ba40e224
BLAKE2b-256 d6635b0a1f6ec6682eafc95bfbade0927f7ab455bd07927ee70be1f4f6778521

See more details on using hashes here.

Provenance

The following attestation bundles were made for torch_fourier_shift-0.1.0-py3-none-any.whl:

Publisher: ci.yml on teamtomo/torch-fourier-shift

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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