• AlbumentationsAlbumentations
All TransformsGet LicenseDocumentationNews & Insights
Report IssueJoin Discord...

Posterize

Targets:
image
Image Types:uint8, float32

Reduce bits per color channel (e.g. 8→4). num_bits_range controls strength; lower gives stronger posterization. Simulates low-bit-depth or compression.

This transform applies color posterization, a technique that reduces the number of distinct colors used in an image. It works by lowering the number of bits used to represent each color channel, effectively creating a "poster-like" effect with fewer color gradations.

Arguments
num_bits
tuple[int, int] | list[tuple[int, int]]
[4,4]

Defines the number of bits to keep for each color channel. Can be specified as:

  • tuple of two ints: (min_bits, max_bits) to randomly choose from. Range for each: [1, 7].
  • list of per-channel tuples: Ranges per channel [(r_min, r_max), (g_min, g_max), ...]. Default: (4, 4)
p
float
0.5

Probability of applying the transform. Default: 0.5.

Examples
>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, [100, 100, 3], dtype=np.uint8)

# Posterize all channels to 3 bits
>>> transform = A.Posterize(num_bits=(3, 3), p=1.0)
>>> posterized_image = transform(image=image)["image"]

# Randomly posterize between 2 and 5 bits
>>> transform = A.Posterize(num_bits=(2, 5), p=1.0)
>>> posterized_image = transform(image=image)["image"]

# Range of bits for each channel
>>> transform = A.Posterize(num_bits=[(1, 3), (3, 5), (2, 4)], p=1.0)
>>> posterized_image = transform(image=image)["image"]
Notes
  • The effect becomes more pronounced as the number of bits is reduced.
  • This transform can create interesting artistic effects or be used for image compression simulation.
  • Posterization is particularly useful for:
    • Creating stylized or retro-looking images
    • Reducing the color palette for specific artistic effects
    • Simulating the look of older or lower-quality digital images
    • Data augmentation in scenarios where color depth might vary
References
  • Color Quantizationhttps://en.wikipedia.org/wiki/Color_quantization
  • Posterizationhttps://en.wikipedia.org/wiki/Posterization