This is a script (still being developed) I use to process "raw" files from my Canon DSLR. Note that it cannot be run with the pyctools-editor GUI. It is a command line script, with some optional parameters.
The processing pipeline is as follows:
- RawImageFileReader2 is used to read the image with no gamma correction.
- VignetteCorrector corrects any darkening of image corners if required.
- RGBtoYUV is used to convert from RGB to Y (luminance) and "UV" (actually CbCr) colour difference signals.
- The Y signal is sharpened with UnsharpMask and the UV signal is increased with Arithmetic - this increases the colour saturation a bit.
- The Y & UV signals are converted back to RGB with YUVtoRGB.
- GammaCorrect converts the "linear light" signal to "gamma corrected" form as stored in most image file formats.
- ErrorFeedbackQuantise truncates the result to integers without introducing banding effects. (All the processing so far uses floating point numbers.)
- ImageFileWriterPIL saves the result to a JPEG file.
Command line options can be used to add a ShowHistogram component to show the histogram of the final image, or a PlotData component to show the gamma curve used. Other command line options allow tweaking of the exposure or adding an extra UnsharpMask between stages 5 & 6.
Chromatic aberration correction
The RawImageFileReader2 component uses LibRaw - a powerful library with a lot of options. It can enlarge or reduce the red and blue signals to minimise the visibility of lateral chromatic aberration. By taking many pictures of a suitable test chart I've found the best settings for each of my lenses, at a variety of focal lengths in the case of the zoom lenses. This data is included in the script. If you copy my script you'll need to supply your own data!
I've also measured the vignetting (or "peripheral illumination error") of each of my lenses at a variety of focal lengths and apertures. I've been able to fit different power law functions to each of these measurements. The script contains all this data and interpolates corrections for other focal lengths and apertures.
Some of the above processing (such as vignette correction) has to be done on "linear light" signals. This is what raw files store - the camera's sensor output is proportional to the intensity of the light hitting it (except when completely saturated, of course). Before display images need to be "gamma corrected". This uses a non-linear transfer function so that the signal is roughly proportional to perceived brightness. There are many transfer functions available, from simple power laws to more complicated logarithmic functions. I've settled on using "Hybrid Log-Gamma", a proposal from my former colleagues at BBC Research.