Skip to main content

Periodic raster rotation approximation for toroidally tiling NumPy images

Project description

toroidal-rotate

toroidal-rotate is a small NumPy utility for periodic raster rotation of toroidally tiling images.

It keeps the same array shape, uses wraparound boundaries, and rotates by inverse-mapped sampling on the periodic image domain.

What it is

The transform is:

  • deterministic
  • same output shape as input
  • periodic under square tiling
  • works on grayscale (H, W) and channels-last (H, W, C) arrays

What it is not

This is not an exact Euclidean rotation. It is a periodic raster approximation using wrapped inverse sampling, so inverse rotation is approximate rather than exact and repeated small angles are not numerically exact cumulative rotation.

Installation

pip install toroidal-rotate

Showcase

Toroidal rotate showcase

Direct file: docs/showcase.gif

Usage

Example 1: grayscale periodic rotation

import numpy as np

from toroidal_rotate import toroidal_rotate

image = np.arange(8 * 8).reshape(8, 8)

rotated = toroidal_rotate(image, 24)

Example 2: RGB image

import numpy as np

from toroidal_rotate import toroidal_rotate

image = np.zeros((64, 64, 3), dtype=np.uint8)
image[..., 0] = 255

rotated = toroidal_rotate(
    image,
    angle_degrees=24,
    rounding="nearest",
    center="pixel_center",
)

API

from toroidal_rotate import (
    ToroidalRotationError,
    ToroidalRotationSpec,
    toroidal_rotate,
    toroidal_rotate_inverse,
    toroidal_rotate_many,
)

toroidal_rotate_inverse applies the matching wrapped inverse angle, but due to raster quantization it is approximate rather than exact round-trip restoration.

Build and publish

python -m pip install --upgrade build twine
python -m build
twine upload --repository testpypi dist/*
# after checking it works
twine upload dist/*

To regenerate the demo GIF:

PYTHONPATH=src python scripts/make_showcase_gif.py

License

MIT

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

toroidal_rotate-0.2.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

toroidal_rotate-0.2.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file toroidal_rotate-0.2.0.tar.gz.

File metadata

  • Download URL: toroidal_rotate-0.2.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for toroidal_rotate-0.2.0.tar.gz
Algorithm Hash digest
SHA256 949f4f1c8702919c766b474156ceb751cc46676146fac4aef768f491cad0fcb8
MD5 4f4570f0d16c34bd5224dd51318492b6
BLAKE2b-256 9234fca3f72dc8e176f0b88d8758e96ab74d87ecd6755a8335a96b11acff6b84

See more details on using hashes here.

File details

Details for the file toroidal_rotate-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for toroidal_rotate-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b149ffef5e2621d73ee86e9e26d4dfc50a1e3e5a43c4c67551c8237a3a07fd9
MD5 bf4009307b6eae67a4c6ee5c9dc33448
BLAKE2b-256 97f0d9a049c46bc2706b9e096525fcb16de4efac444e1675ac99e8bfbb8fddfb

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