Gamma Correction
Using Gamma Correction in anti-aliasing
Address: http://www.antigrain.com/research
/Gamma_correction/index.html # page_gamma_correction
Translation: Tang Feng
My intercept: continue to translate documents from the author's official website. Two reasons are as follows: first, what the author wrote has something to do with the implementation of the author, learning the document he wrote is one of the best ways to understand the code. Second, I like the style of doing things by the author, and I can feel the pursuit of perfection. It is a pity that pipeline stops development. Fortunately, the code and documents left behind are enough for me to learn for a while.
It is complex and difficult to de-sample. The difficulty lies not only in algorithms, but also in that the visual effects of images are related to display devices. The effect of de-sawtooth images on the CRT and LCD display is different. Generally, this is a science called Color Management (or perhaps art ). Anti-grain geometry uses a de-sawtooth method that tries to achieve the best effect. During the rendering process, the overwrite value of each boundary pixel is calculated. This value is reflected to the anti-aliasing levels level ). Anti-aliasing geometry uses 256 levels, which is sufficient for any practical use (this detailed classification produces results) and is better than most 5-level de-sawtooth software, for example, most Adobe products and the true-type font Renderer. I am very sure that the rendering method I use can provide the best results. However, when I tried to use anti-grain geometry and Adobe SVG Viewer to render the same image, I found that although Adobe SVG Viewer only uses a 5-level de-sawtooth level, but sometimes it looks better than anti-grain geometry.
The left graph is rendered using anti-grain geometry, and the right graph is rendered using Adobe SVG viewer.
When rendering with a 5-level de-sawtooth Adobe SVG Viewer, the Lion's beard looks smooth. At least it looks like this on a CRT display. However, rendering of large images still tells us that it is not enough to de-sample the layers of Adobe viewer.
Obviously, anti-grain geometry can be rendered better, but it is not the best to use a simple linear relationship for the correspondence between the pixel overwrite value and the brightness. Correction is required. In color management, this is called Gamma Correction. To perform Gamma Correction, I used an array of 256 values to provide the brightness of the pixel corresponding to the covered value. If the values in the array are equal to their index values, for example, 0, 1, 2, 3, 4 ...... So there is no Gamma Correction. This array can be calculated using any method, but the simplest method is to use the B-spline curve through two correlation points and four quadrants (kx1, ky1, kx2, ky2) to determine its shape. I created a program that uses special Gamma Correction controls to calculate values in the Gamma value array. This program draws 6 very flat ovans, 6 small circles, and some other images used to test the de-sawtooth effect.
No Gamma Correction
The control points can be moved within the quadrant where they are located. The following figure looks much better on the CRT display.
Gamma Correction for CRT
For some width and brightness, we can achieve the best display effect, but this situation is not universal. In the above example, although it is not the best for some parameters, it works well on average (Gamma Correction Method), as it does on a CRT display, this is also true for LCD. Below are some typical examples of gamma in other shapes.
In addition, the effect of Gamma Correction is closely related to the image content. In the above example, the gamma values that have good elliptical effects do not have a very good time effect for plotting. The text requires a clear boundary shape, but the large geometric image looks better with a smooth boundary.
The following is the lion drawn after Gamma Correction on the CRT, And now it looks better than Adobe SVG viewer.
You can download this program: gamma control.
The source code of this program can be found in the example directory of the distributed package.