Scale each image toward a sampled global mean while preserving pixel ratios. Use it to model exposure changes whose strength depends on the input brightness.
The transform samples one normalized target mean per call and computes the multiplicative gain
from each image's global mean. Image batches and the volume target share the sampled target while deriving
one gain per image or depth slice. Values that exceed the dtype range are clipped, so saturation
can keep the resulting mean below the sampled target. A zero image remains zero.
target_mean_rangeLower and upper bounds for the normalized target mean. Both values must be in [0, 1]. Default: (0.3, 0.5).
gain_rangeOptional lower and upper bounds for the derived gain.
Both values must be non-negative. Use None to leave the gain unbounded. Default: None.
pProbability of applying the transform. Default: 0.5.
>>> import numpy as np
>>> import albumentations as A
>>> # Prepare sample data
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> mask = np.random.randint(0, 2, (100, 100), dtype=np.uint8)
>>> bboxes = np.array([[10, 10, 50, 50]], dtype=np.float32)
>>> bbox_labels = [1]
>>> keypoints = np.array([[20, 30]], dtype=np.float32)
>>> keypoint_labels = [0]
>>> # Define the exposure-matching pipeline
>>> transform = A.Compose(
... [
... A.ExposureMatching(
... target_mean_range=(0.3, 0.5),
... gain_range=(1.0, 3.0),
... p=1.0,
... ),
... ],
... bbox_params=A.BboxParams(coord_format="pascal_voc", label_fields=["bbox_labels"]),
... keypoint_params=A.KeypointParams(coord_format="xy", label_fields=["keypoint_labels"]),
... )
>>> # Apply the transform to the image while preserving annotation targets
>>> transformed = transform(
... image=image,
... mask=mask,
... bboxes=bboxes,
... bbox_labels=bbox_labels,
... keypoints=keypoints,
... keypoint_labels=keypoint_labels,
... )
>>> matched_image = transformed["image"]
>>> transformed_mask = transformed["mask"]
>>> transformed_bboxes = transformed["bboxes"]
>>> transformed_bbox_labels = transformed["bbox_labels"]
>>> transformed_keypoints = transformed["keypoints"]
>>> transformed_keypoint_labels = transformed["keypoint_labels"]images and volume, each image or slice gets its own gain.