Reduce image quality via JPEG or WebP compression. quality_range and compression_type control strength and format. Simulates real-world compression artifacts.
This transform simulates the effect of saving an image with lower quality settings, which can introduce compression artifacts. It's useful for data augmentation and for testing model robustness against varying image qualities.
quality_rangeRange for the compression quality. The values should be in [1, 100] range, where:
compression_typeType of compression to apply.
pProbability of applying the transform. Default: 0.5.
>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> transform = A.ImageCompression(quality_range=(50, 90), compression_type=0, p=1.0)
>>> result = transform(image=image)
>>> compressed_image = result["image"]