pierogis.ingredients.quantize module

class pierogis.ingredients.quantize.Quantize(opacity: int = 100, mask: Optional[numpy.ndarray] = None, **kwargs)[source]

Bases: pierogis.ingredients.ingredient.Ingredient

quantize reduces the color palette of the input pixels to a smaller set.

cook(pixels: numpy.ndarray)[source]

get the closest rgb color in the palette to each pixel rgb “snap” to the colors in the palette

prep(colors=None, **kwargs)[source]

parameters for spatial color quantization

Parameters

colors – colors to use. can be a list of str or pixel array likes

class pierogis.ingredients.quantize.SpatialQuantize(opacity: int = 100, mask: Optional[numpy.ndarray] = None, **kwargs)[source]

Bases: pierogis.ingredients.quantize.Quantize

use the Spatial Color Quantization algorithm implemented in rust with rscolorq

also performs dithering to make the palette appear richer.

DITHERING_LEVEL = 0.8
FILTER_SIZE = 3
FINAL_TEMP = 0.001
INITIAL_TEMP = 1
ITERATIONS = 3
PALETTE_SIZE = 8
REPEATS = 1
cook(pixels: numpy.ndarray)[source]

use the binding to the rscolorq package in rust to perform an optimization in quantizing and dithering

dithering_level: float

relative amount of dithering (.5-1.5)

filter_size: int

filter size for dithering

final_temp: float

final annealing temp (decimal near but above 0)

initial_temp: float

starting annealing temp (around 1)

iterations: int

number of iterations to do at each coarseness level

palette_size: int

number of colors

prep(palette_size=8, iterations=3, repeats=1, initial_temp=1, final_temp=0.001, dithering_level=0.8, seed=0, **kwargs)[source]
repeats: int

number of repeats to do of each annealing temp

seed: int

seed for rng