# How to add chromatic aberration to an AI image

Source: https://passreal.com/how-to/chromatic-aberration

Lateral chromatic aberration is a radial colour shift: the red and blue channels are magnified slightly differently from green, so edges toward the corners show thin coloured fringes while the centre stays clean. To add it, scale the red and blue channels by tiny opposite amounts about the image centre. A constant offset across the frame is wrong and looks like a mistake.

## What it is

A simple lens focuses different wavelengths at slightly different positions,
because glass bends blue light more than red. Lens designers fight this with
multiple elements, but a residual always remains. The visible form is a thin
coloured edge along high-contrast boundaries, and it is strongest far from the
optical axis.

That last point is the whole trick. The effect is radial. On the axis, red,
green and blue line up. Toward the corners, red is displaced one way and blue the
other. Orientation follows the radius, so on the left edge the fringe shifts
horizontally, in the top corner it shifts diagonally, and in the middle of the
frame there is nothing.

## Why the common shortcut fails

Many editing recipes suggest offsetting the red layer by one pixel and the blue
by one pixel the other way. The result is a constant shift across the whole
frame. Even the centre, where the lens has none, picks up colour edges. It looks
like a misaligned print, and anyone who inspects centre detail sees the error.

The correct operation is a scale, not a shift. Scaling a channel about the
centre moves each point by an amount proportional to its distance. That gives
zero at the centre and the largest displacement at the corners, which is the
real behaviour.

## In Photoshop

Split the image into channels, or open Filter, Lens Correction and use the
Chromatic Aberration sliders for red-cyan and blue-yellow fringe, which apply
a radial correction. Pushing them in the opposite direction from a correction
adds the effect rather than removing it. Alternatively, copy each channel to its
own layer, transform the red layer a fraction of a percent larger, the blue
layer the same amount smaller, anchor at the centre, and set the blend modes to
combine them again.

## In GIMP

Use Colors, Components, Decompose to RGB layers, then Layer, Scale Layer with
the centre anchor, followed by Compose. This takes a few more clicks than
Photoshop but gives the same maths.

## In Python

Load the image as an array, split the channels, and resample red and blue with
an affine transform that scales about the image centre. A scale factor just
above and just below one is enough. Use a good interpolation, since a poor one
softens those channels and leaves visible colour smearing. Then stack the
channels and save.

## How to judge it

- Look at the corners of the frame at full size on a high-contrast edge such as
  a branch against sky. A faint fringe should be visible only at that zoom.
- Look at the centre. It must be clean.
- Look at a neutral grey edge. It should gain a coloured border that flips
  colour on opposite sides of the frame.

## Placement in a workflow

Colour fringing happens in the lens, so it belongs before the sensor stages.
Add grain after, so the noise sits on top of the fringing as it would in a real
exposure. Then compress once.

PassReal applies this in sequence: it removes C2PA, IPTC digital source type,
XMP and PNG text chunks, adds grain, adds radial lateral chromatic aberration
reaching 1.25 px at the corners and none at the centre, smooths the
frequency spectrum, and encodes a JPEG with real-camera EXIF.

It does not remove SynthID or any pixel-level watermark, and it does not promise
any detector outcome.

## Common mistakes

Three errors recur. The first is applying the effect to the whole image equally, which we covered. The second is using a large scale difference so that fringes appear in mid-frame, where real lenses show almost none. The third is blurring the shifted channels, which smears colour into a haze instead of a thin edge line. Keep the interpolation sharp, keep the difference small, and judge only at the corners. A good test is to desaturate the result: if the picture looks identical in black and white and only the corners carry a coloured edge in colour, you got it right.

## Try it

Process three images free at PassReal and zoom into a corner of the result to
see the fringe grow from nothing at the centre.

## Questions

### What is the difference between lateral and longitudinal aberration?

Lateral aberration shifts colours sideways and increases toward the edges. Longitudinal aberration focuses colours at different depths, giving fringes in front of and behind the focal plane. Lateral is what you imitate with a radial channel scale.

### Why is a constant shift wrong?

A fixed offset moves colours the same amount everywhere, including at the centre, where a real lens shows none. It looks like a misregistered print, not an optical effect.

### How large should the shift be?

A pixel or so at the corners of a large image is already visible on close inspection. PassReal uses 1.25 px at the corners and zero at the centre.

### Does this hide an image from detectors?

No claim is made. It reproduces one physical trait of lenses, among several that a camera file has.

### Do I need to do this before or after resizing?

Before the final resize if the amount is defined in pixels at full resolution, and always before compression, so the fringes are part of the encoded picture.

Try it: https://passreal.com/app (three images free)
