Skip to main content

Scalerack

PyPI version

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

PyPI package

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
(Does not fully reproduce paper results)

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

Vectorizing scalers

Vectorizing scalers reconstruct smooth resolution-independent region outlines before rasterizing at the target size, so they support arbitrary (non-integer) factors.

Algorithm Photo reconstruction Sprite upscale
Original
depixelize
Depixelizing Pixel Art

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 ✅ 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.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: scalerack-0.1.2.tar.gz
  • Upload date:
  • Size: 32.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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.2.tar.gz
Algorithm Hash digest
SHA256 ddd8dffef9bb90be4254c4d166f90272915f98a6f77b0915a2e3b82c34e2d2ad
MD5 ef16c66770328e5da403a777a36b6247
BLAKE2b-256 80fd94201433b9010275986cd5e91bd53211e06651a505e57995e3c049fcf2ee

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scalerack-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 43.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b7fbd6c8040b003c986a7554d65a5cb74f49fa439f3a2ead1a19c3b560d9d65b
MD5 211b76fa06cb3165f20df5d703f8f087
BLAKE2b-256 cff534c9376533890d0e1ad2aff7f9d7913490ed5832f30705461ba98a843bf5

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

This release

0.1.2 This release

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page