Scalerack

Python image resizing, resampling, downscaling, and pixel-art upscaling for NumPy arrays and Pillow images.

Install

pip install scalerack
pip install scalerack[cli]
pip install scalerack[all]

Usage

import scalerack

big = scalerack.mitchell(image, factor=2.5)
thumb = scalerack.box(photo, width=320)
sprite = scalerack.scale3x(pil_sprite)
out = scalerack.resize("lanczos", image, factor=2)

Algorithms

bicubic

Scale with the classic Keys bicubic kernel.

Sharper than bilinear with mild overshoot; the general-purpose default when Lanczos rings too much.



bilinear

Scale with linear interpolation over the triangle kernel.

A fast, artifact-light baseline; visibly softer than the cubic and sinc families.



box

Scale by averaging each output pixel’s exact source footprint.

The best-behaved choice for downscaling (area interpolation); upscaling degenerates to nearest-neighbor blocks.



catmull_rom

Scale with the Catmull-Rom interpolating spline.

Sharper than Mitchell; a good pick when extra acutance is worth a little more ringing.



channel_median

Downscale with a coverage-weighted median computed per channel.

Each output channel is independently reduced to the median of its exact source footprint. This robustly rejects isolated channel outliers, but can construct a color vector that did not occur in the source image.



content_adaptive_downscale

Downscale with detail-preserving content-adaptive kernels (Kopf et al. 2013).

Each output pixel is a bilateral Gaussian kernel in joint space/color, fit by EM. Kernels start color-crisp; the locality and staircase constraints selectively smooth misbehaving kernels by raising their color variance. For the paper’s pixel-art mode pass staircase_constraint=False. Sharpness accumulates with iterations; the max_iter default is calibrated to reproduce the sharpness of the paper’s published results (running to full convergence over-sharpens). Pixel art converges early on its own.



depixelize

Vectorize pixel art into smooth outlines (Kopf-Lischinski 2011) at any target size.

Intended for hard-edged, limited-palette pixel art at enlarging factors; factors at or below 1 are accepted but produce odd-looking results. The paper’s optional harmonic-map cell relaxation is omitted.



eagle2x

Enlarge pixel art exactly 2x with the classic Eagle corner-rounding rules.



eagle3x

Enlarge pixel art exactly 3x with the community Eagle3x extension of the Eagle rules.



fsr

Upscale with AMD FSR 1: EASU edge-adaptive upsampling plus RCAS sharpening.

Designed for continuous-tone content; AMD’s published quality presets span factors of about 1.3x to 2x per axis (larger factors work but soften). Upscaling only; a factor of exactly 1 applies pure RCAS sharpening.



hq2x

Enlarge pixel art exactly 2x with Maxim Stepin’s hq2x pattern interpolation.



hq3x

Enlarge pixel art exactly 3x with Maxim Stepin’s hq3x pattern interpolation.



hq4x

Enlarge pixel art exactly 4x with Maxim Stepin’s hq4x pattern interpolation.



lanczos

Scale with a Lanczos windowed-sinc kernel.

The high-detail standard for photographic content; may ring at hard edges.



magic_kernel_sharp

Scale with Costella’s Magic Kernel Sharp.

A crisp modern alternative to plain cubic kernels.



mitchell

Scale with the Mitchell-Netravali BC-spline.

The safe offline default balancing blur, anisotropy, and ringing.



nearest

Scale by copying the nearest source pixel.

Preserves exact pixel values; the right choice for masks, label maps, and deliberately blocky display of low-resolution art.



sai2x

Enlarge pixel art exactly 2x with Kreed’s 2xSaI edge-aware interpolation.



scale2x

Enlarge pixel art exactly 2x with the Scale2x (EPX) neighborhood rules.



scale3x

Enlarge pixel art exactly 3x with the Scale3x neighborhood rules.



scale4x

Enlarge pixel art exactly 4x by applying Scale2x twice.



super2xsai

Enlarge pixel art exactly 2x with Kreed’s Super 2xSaI, the family’s strongest blur.



supereagle

Enlarge pixel art exactly 2x with Kreed’s SuperEagle edge detection and blending.



superxbr

Enlarge pixel art exactly 2x with Hyllian’s Super xBR hybrid interpolation.



vector_median

Downscale by selecting the vector median of each source footprint.

The vector median is the source pixel whose color vector has the smallest coverage-weighted sum of Euclidean distances to the other pixels in an output pixel’s exact source footprint. Unlike channel-wise medians, it always returns a color that occurred in the source image.



xbrz

Enlarge pixel art 2x-6x with Zenju’s xBRZ edge-slope detection and blending.



API

resize

Scale an image with the algorithm named by method.

Translates the request into whatever sizing the algorithm exposes: a factor becomes width/height (and vice versa) where needed.



Exceptions