ChromaticAberration

Targets:
image
volume
Image Types:uint8, float32

Add lateral chromatic aberration by distorting the red and blue channels of the input image.

Chromatic aberration is an optical effect that occurs when a lens fails to focus all colors to the same point. This transform simulates this effect by applying different radial distortions to the red and blue channels of the image, while leaving the green channel unchanged.

Arguments
primary_distortion_limit
tuple[float, float] | float
[-0.02,0.02]

Range of the primary radial distortion coefficient. If a single float value is provided, the range will be (-primary_distortion_limit, primary_distortion_limit). This parameter controls the distortion in the center of the image:

  • Positive values result in pincushion distortion (edges bend inward)
  • Negative values result in barrel distortion (edges bend outward) Default: (-0.02, 0.02).
secondary_distortion_limit
tuple[float, float] | float
[-0.05,0.05]

Range of the secondary radial distortion coefficient. If a single float value is provided, the range will be (-secondary_distortion_limit, secondary_distortion_limit). This parameter controls the distortion in the corners of the image:

  • Positive values enhance pincushion distortion
  • Negative values enhance barrel distortion Default: (-0.05, 0.05).
mode
green_purple | red_blue | random
green_purple

Type of color fringing to apply. Options are:

  • 'green_purple': Distorts red and blue channels in opposite directions, creating green-purple fringing.
  • 'red_blue': Distorts red and blue channels in the same direction, creating red-blue fringing.
  • 'random': Randomly chooses between 'green_purple' and 'red_blue' modes for each application. Default: 'green_purple'.
interpolation
0 | 6 | 1 | 2 | 3 | 4 | 5
1

Flag specifying the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR.

p
float
0.5

Probability of applying the transform. Should be in the range [0, 1]. Default: 0.5.

Examples
>>> import albumentations as A
>>> import cv2
>>> transform = A.ChromaticAberration(
...     primary_distortion_limit=0.05,
...     secondary_distortion_limit=0.1,
...     mode='green_purple',
...     interpolation=cv2.INTER_LINEAR,
...     p=1.0
... )
>>> transformed = transform(image=image)
>>> aberrated_image = transformed['image']
Notes
  • This transform only affects RGB images. Grayscale images will raise an error.
  • The strength of the effect depends on both primary and secondary distortion limits.
  • Higher absolute values for distortion limits will result in more pronounced chromatic aberration.
  • The 'green_purple' mode tends to produce more noticeable effects than 'red_blue'.