what is gamma in digital images
perm url with updates: http://xahlee.org/img/what_is_gamma_correction.html
What Is Gamma In Digital Images
Xah Lee, 2010-02-24
Been quite familiar with the technology of bitmapped image, the mathematical gist of their formats, since about 1995. For example, the diff between gif, jpeg, png. There's RGB color model , but also HSL and HSV, and CMYK.
In one sentence, a image is made up by a rectangular grid of pixels, and a pixel has 3 sets of values, for Red, Green, Blue, together they specify a color for the pixel, and all the pixels form the image. In early 2000s, Alpha channel became important. It allows you to have semi-transparent images. Transparency is important for images on computers, because for example, you might want a image partially transparent so users can see what's behind.
One element of digital image i never understood is Gamma.
Going to Wikipedia's gamma article, but it is unreadable. But then i found this: Gamma FAQ - Frequently Asked Questions about Gamma (2002-12-16), by Charles Poynton Source. Skipping to the “What is gamma?” section, it began with this sentence:
The luminance generated by a physical device is generally not a linear function of the applied signal.
That explains it! How simple and potent explanation.
So, gamma, isn't a intrinsic quality of a image. Rather, it is a value to compensate the quirks of various display devices.
Reading other parts of the article by Charles, i find it excellent. Apparantly, it is written by a scientist, and explain things precisely, relpying on a physics background. In contrast, the hundreds of articles i read in the past 20 years about color, are mostly wishy-washy, or filled with technical arcana that indicates the writer doesn't really understand it. Going over to his home page http://www.poynton.com/index.html, he turns out to be a notable specialist in digital image formats.
Reading the whole gamma faq article, it is truely illuminating. It reminds me how complex is the science of color, and technologies related to color, in particular, digital image formats and image processing. In practice, this complexity is experienced in getting images right, from camera, video, computer displays, screenshots, scanners.
After reading Charle's article, Wikipedia article about gamma now becomes understable.
Another article on Gamma is this: PNG (Portable Network Graphics) Specification, Version 1.2, section “13. Appendix: Gamma Tutorial”, at http://www.libpng.org/pub/png/spec/1.2/PNG-Contents.html.
The whole thing about the gamma complexity, is of 2 main causes:
- (1) Human perception of the intensities of color or brightness, does not have a linear relationship, with respect to the values of intensity of light waves in physics.
- (2) The brightness of image display devices, such as CRT, does not have a linear relation of its voltage input.
These are the main reasons. The real complexity is a lot more than that, involving human understanding of nature (physics of color), psychology of perception, technology and engineering limitations (camera and display devices, image and video formats). Starting from the moment you create a digital image either by camera or camcorder, which needs to capture light intensities, thru lens, onto some light-sensitive media (CCD, Photographic film), which eventually needs to be converted to some file format when stored. And when you display it, the software needs to read the data, interpret it appropriately, and eventually convert the bits to voltage in your screen.
One fact surprising to me i learned is, that video formats such as mpeg, video broadcast signals such as NTSC, or image formats (jpeg, png), they actually store the adjusted light intensities (gamma corrected), and not the unprocessed light intensities.
The reason also seems reasonable. For example, for TV, it much economic to do the gamma correction processing once and send the gamma corrected signals, than having every TV receiver do the gamma correction.
Triangular-Grid Based Image Formats And Display
Another thing i wondered is that, whether there are triangular/hexagonal based grid for image format or display system. (i.e. like honeycomb) We know that a image is just a rectangular array of pixels. And monitors are more or less that too. CRT's display unit is basically lines Flat panel displays are all rectangular grids.
(The CRT tech basically scan a beam of electrons horizontally, but part of the CRT tech uses Shadow mask, which may have a triangular grids, but CRT's nature with respect to a grid is still array of lines.)
Note that packing dots by a rectangular array is not optimal, with respect to density. The optimal one is a triangular grid. (see: Circle packing ) So, with respect to better resolution and the display grid, for a display technology, a triangular grid is superior to rectangular. So, i wonder if there are display devices based on triangular grid, or image formats that is based on triangular grid. I'm sure they exist in some specialized niche.
Gamma Error In Picture Scaling
What made me look into gamma today is when reading this article: Gamma error in picture scaling (2007-08-30), by Eric Brasseur. Source. The article details a defect that almost all image processing software have. When you scale some images, the algorithm used in these software has a defect, so the result scaled image is not optimal. The site gives one particular example input image. When you scale the image, the result is very bad. I tested it with ImageMagick, and verified that it also have this defect.