Skip to main content

Classical and pixel-art image up/downscaling algorithms behind one consistent interface.

Project description

Scalerack

Many image up- and downscaling algorithms behind one unified interface: classical kernel resampling, edge-aware reconstruction for crisp low-resolution art, vectorizing and perceptual downscaling approaches. Whatever goes in comes back out in the same format:

  • NumPy arrays: (H, W), (H, W, 3), (H, W, 4) in uint8, float32, float64
  • Pillow images: L, RGB, RGBA

Install

pip install scalerack          # core resampler
pip install scalerack[cli]     # command line interface
pip install scalerack[all]     # everything

Usage

import scalerack

big = scalerack.mitchell(image, factor=2.5)
thumb = scalerack.box(photo, width=320)  # height inferred
crisp = scalerack.magic_kernel_sharp(image, width=100, height=100, version=2021)
sprite = scalerack.scale3x(pil_sprite)  # fixed 3x

# generic dispatch
out = scalerack.resize("catmull_rom", image, 2)

# all algorithm names
print(*scalerack.ALGORITHMS)

Invalid parameters (unsupported factor, wrong input type, missing extra) raise exceptions.

CLI (with the cli extra):

scalerack scale input.png output.png --method lanczos --factor 2
scalerack scale photo.png thumb.png --method box --width 320   # height inferred from aspect ratio
scalerack scale sprite.png big.png --method scale4x --factor 4
scalerack list

Algorithms

Check the code documentation for algorithm details.

Classical resamplers

Downscale previews are generated as 4x reductions (0.25x output size). Photo reconstruction previews first degrade the source with Lanczos at 0.25x, then upscale the degraded image back toward the original size. Sprite downscale previews reduce the pixel-art source directly, and sprite upscale previews enlarge the pixel-art source directly.

Algorithm Photo downscale Sprite downscale Photo reconstruction Sprite upscale
Original
nearest
box
bilinear
bicubic
Cubic convolution interpolation
mitchell
Mitchell-Netravali filter
catmull_rom
Catmull-Rom spline
lanczos
Lanczos resampling
magic_kernel_sharp
Magic Kernel Sharp

Downscalers

Downscaling algorithm usually focus on preserving detail.

Algorithm Photo downscale Sprite downscale
content_adaptive_downscale
Content-Adaptive Image Downscaling

Pixel-art scalers

Some algorithms may output different results depending on the fixed scale factor.

Algorithm Photo reconstruction Sprite upscale
Original
scale2x
Scale2x / EPX
scale3x
Scale3x / EPX
scale4x
Scale4x / EPX

Sources: Münster market, macaw, and Pixelart TV, via Wikimedia Commons.

Roadmap

Algorithm Family Status
nearest, box, bilinear, bicubic, mitchell, catmull_rom, lanczos, magic_kernel_sharp classical ✅ implemented
scale2x / scale3x / scale4x (EPX) pixel-art ✅ implemented
hq2x / hq3x / hq4x pixel-art ⬜ to be implemented
xBRZ (2x-6x) pixel-art ⬜ to be implemented
super-xBR pixel-art ⬜ to be implemented
EASU / RCAS (FSR 1 core, CPU) extended ⬜ to be implemented
EWA / Jinc (elliptical weighted average) extended ⬜ to be implemented
Gamma-correct (linear-light) resampling extended ⬜ to be implemented
Depixelizing Pixel Art (vectorizing) research ⬜ to be implemented
Content-adaptive downscaling research ✅ implemented
Perceptual / spectral downscaling research ⬜ to be implemented
Eagle, 2xSaI, SuperEagle, SABR (legacy retro) contrib ⬜ to be implemented

Machine-learning upscalers are out of scope.

Development

uv sync --group dev
uv run pre-commit install                   # ruff check + format on commit
uv run pytest                               # smoke suite
uv run mypy src                             # type check
uv run python scripts/generate_previews.py  # regenerate the gallery above

License

MIT. All bundled algorithms are implemented from scratch from their specifications or papers.

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

scalerack-0.1.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

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

scalerack-0.1.0-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scalerack-0.1.0.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for scalerack-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8d16c7f4d5538a611f9a4a32c047811ff4b13d347916b3e24cd30a9224c9917d
MD5 87687acecda21cff9f9c3141e6b97003
BLAKE2b-256 e77923eff3b555a503edba95995bcffe05d5a594261341d01fd14c76d1c33a46

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scalerack-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for scalerack-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b993186fe84123b05b261252d03adbf44e90ea90c5b4e64871a1d6884ea9a2e3
MD5 8db5afcaec14cb05a48b03e4ca36ca95
BLAKE2b-256 55a87d28dedfb730efade71b6cecd779215d465628108bfdffb329f3f6e75b12

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