Skip to main content

Deterministic reversible toroidal pseudo-rotation for NumPy images

Project description

toroidal-rotate

toroidal-rotate is a small NumPy utility for deterministic, reversible toroidal pseudo-rotation of raster images.

It keeps the same array shape, preserves pixel values exactly, and uses wraparound boundaries. It does not interpolate, blur, or average values.

What it is

The transform is built from three integer shears on a toroidal grid:

  • deterministic
  • reversible
  • same output shape as input
  • exact value preservation
  • works on grayscale (H, W) and channels-last (H, W, C) arrays

What it is not

This is not a true Euclidean raster rotation. It is a reversible permutation-like transform that looks rotation-like. Repeatedly applying many small angles is not equivalent to exact cumulative rotation.

Installation

pip install toroidal-rotate

Usage

Example 1: grayscale round-trip

import numpy as np

from toroidal_rotate import toroidal_rotate, toroidal_rotate_inverse

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

rotated = toroidal_rotate(image, 24)
restored = toroidal_rotate_inverse(rotated, 24)

print(np.array_equal(image, restored))  # True

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,
)

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/*

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.1.0.tar.gz (5.3 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.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: toroidal_rotate-0.1.0.tar.gz
  • Upload date:
  • Size: 5.3 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.1.0.tar.gz
Algorithm Hash digest
SHA256 383ee9468fa706f7e21188cc9d3b121986dae7c447e4b6857a1097a04616a714
MD5 b7b97ec231d5dfa474b656c99a29a92d
BLAKE2b-256 fceda139f6c7b0997aad1cfa528c006e58e7d7e8dda533d79086650154537e19

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for toroidal_rotate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5eb86603b202d086c511bad731e43c350abdac243e020b1c1b47df85d68fa74a
MD5 95d6ab609b4fe7c23814aabad6c674a8
BLAKE2b-256 9b6a57227dfd39d34fbce86880088ec964afb1ff62c12dde650c28b29cc8f890

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