A single-element lens bends light (“refraction”), so rays from a distant object that hit different parts of the lens are focused on a single point on the sensor. The amount of bending depends on the colour of the light, and on the glass used (its “index of refraction”, IOR, which varies according to wavelength). Blue light bends more than red light. So if white light passes through a single-element lens the red, green and blue components will bend by different amounts, and hence will focus at different places. This is chromatic aberration (CA).
A different colour may focus at a different distance from the lens (axial CA, aka longitudinal CA) or a different distance from the centre of the sensor (transverse CA, aka lateral CA), or both. The distances depend on the lens aperture but also on the distance of the light source from the plane that is in focus.
In film photography, CA is difficult to correct in post. In digital photography, transverse CA can be reduced by a geometrical distortion of the red, green and blue components of the image.
Camera lenses reduce CA by using multiple elements with different IORs. But the problem can’t be entirely removed.
I took a photo that included a dense tree, with glimpses of the sky visible through the green leaves as small white dots. Here is a crop from the bottom-left, magnified.
set SRCNEF=%PICTLIB%20120918\DSC_0314.NEF
set sPROC=-strip -crop 9x9+54+4881 +repage -scale 5000%%
%DCRAW% -6 -T -w -O ca_1.tiff %SRCNEF%
%IM%convert ca_1.tiff %sPROC% ca_1.png
Observe blue fringing top-right and red fringing bottom-left. Imagine this white blob is really made of blue, green and red blobs. To get this result, the coloured blobs must be offset, so the blue blob is towards the top-right (towards the centre of the original image), and the red blob is towards the bottom-left (away from the centre of the original image). This is “lateral chromatic aberration”.
We can correct the image by enlarging the blue component of the image, which will move the blue blob outwards. We do the opposite with red.
%DCRAW% -6 -T -w -C 0.99980 1.00005 -O ca_2.tiff %SRCNEF%
%IM%convert ca_2.tiff %sPROC% ca_2.png
This has reduced the red and blue fringing. There is still some blue fringing, but if we remove that, we cause purple fringing on the opposite side.
I found these numbers by trial and error. They can be found automatically from a photo of a grayscale object (eg a newspaper): separate the channels into three grayscale images, then find the scale factors that make the images most closely match.
The above assumes that lateral CA causes a simple resizing in the red and blue channels, so the opposite resizing fixes it. This is a good first approximation. The “most closely match” test can be repeated at different parts of the image, to get the parameters for a more precise barrel/pincushion distortion.