Friday, July 20, 2012

Improvement of Nomacs Raw Loader

The RAW image data we get from digital cameras are the values taken from the cameras sensor. This image is mosaiced: every pixel has just one of the three colors: red, green, blue. The pixels form a pattern that is called color filter array. The most common of them is the Bayer filter which is composed of two green pixels on one diagonal and of one red and one blue pixel on the other diagonal. Bellow picture shows a small part of the Bayer filter.


 In order to create an image that represents what a human eye would see we need to process the RAW data. There are a few essential steps that we need to do:

1. Normalization of RAW data: the RAW image needs to be normalized depending on the black point of the used digital camera and its dynamic range.

2. Demosaicing: for each uni-colored pixel we need to find the other two colors of this pixels. This is done by using the interpolation that is based on the type of the color filter array.


3. White balance: The demosaiced image is very green. To remove this effect we multiply each image RGB channel with a constant. The three constants are based on the photographed scene illuminant and they differ for each digital camera.  


4. Color correction: The colors of the white balanced picture are still not right. We need to do another transformation that converts colors from the camera color space to a standardized color space such as sRGB or AdobeRGB. This is done by multiplying pixels RGB values with a so called color matrix.


5. Gamma correction: the human visual response to the light is nonlinear. On the other hand the digital camera response is linear. The process of changing the linear data to nonlinear data is called applying gamma correction.


The previous version of Nomacs RAW Loader had a little different sequence of this changes and it was missing one correction: the color correction. After changing this the improvements are clearly visible. Bottom image shows the difference between previous and modified RAW Loader.


So when we postprocess a RAW image we need to be careful that we make all needed corrections. Missing one completely changes  how the processed image looks.

Thursday, July 19, 2012

Hue, exposure, gamma

As promised, we will now take a look at the other three image manipulation tools that lie inside the Nomacs image manipulation dialog: hue, exposure compensation and gamma correction. The range of changes that we can make are:

Hue from -180 to 180. Step size for the bottom picture is 36.


Exposure compensation from -6 to 6. Step size for the bottom picture is 1.2.


Gamma correction from 0.01 to 9.99. The bottom picture shows changes for gamma 0.1, 0.2, 0.4, ..., 1.0, 2.0, 4.0, ..., 8.0, 9.99.


Gamma and exposure changes in the top and bottom slider range are very extreme. If we are changing 24 bit images then we also have a great loss of data. So the values in the extreme zones are not recommended unless if the images are very under or over exposed.

Thursday, July 5, 2012

New Image Mnaipulation Tools Dialog design

In the last two weeks the image manipulation tools was completely redesigned. Not only the GUI changed but also the source code changed a lot.

Let's start with the most visible thing. Sliders have a new look which makes the dialog look more professional and appealing. The difference between this and the previous look is noticeable.
To the list of manipulation tools was added the exposure control. I will present it in a separate post together with hue and gamma.


The work on the code in the past couple of weeks was mainly a research project. I was trying to find the best method to use for applying the sliders changes to the image in the main window. Because the changes made by different sliders stack on each other, the process to make them can be slow. Especially for big images.
At first the best way seemed to use 16 bit lookup tables (LUT). We create them very quickly and also we apply them very quickly on images. They are the quickest way of making changes on big images. In RGB space they can also be stacked together. We can then apply the LUT on the main image once. It sounds very promising but there is a problem. In our image manipulation dialog we can change the saturation and hue of an image. For this we need to convert the current picture from RGB to HSV space, change the Hue or Saturation value and convert back to the RGB space. Because the transformation is nonlinear the change can't be done using a lookup table in RGB space. With a simple 16 bit LUT in RGB we can't take into account all possible changes of saturation and hue in HSV space. For this we would need a 16^3 bit LUT which is too big.
The remaining solution was to use LUTs for changes on a local scale (within one slider) and to create a history of changes. When hitting the OK button we go through the history an apply all changes to the main image. This process can be slow because we need to go through image pixels for every change in history. But this is the only way to do it without losing the accuracy of the image data.



The positive side of having a history vector of the changes is that it enabled us to create the undo and redo buttons. We just need to go up or down through the history and recalculate the changes to that point.