re gamma correction in article t meinnrc gap caltech edu madler cco caltech edu mark adler writes can someone who knows what they re talking about add a faq entry on gamma correction thanks i get regular questions about gamma correction since i go to great pains to deal with it properly in xli the image loader program i maintain here is an explanation i often use to answer these questions this might be suitable for inclusion in the faq graeme gill a note on gamma correction and images author graeme w gill graeme labtam oz au date what is all this gamma stuff anyway although it would be nice to think that an image is an image there are a lot of complications not only are there a whole bunch of different image formats gif jpeg tiff etc etc there is a whole lot of other technical stuff that makes dealing with images a bit complicated gamma is one of those things if you ve ever downloaded images from bbs or the net you ve probably noticed with most image viewing programs that some images look ok some look too dark and some look too light why is this you may ask this is gamma correction or the lack of it why do we need gamma correction at all gamma correction is needed because of the nature of crts cathode ray tubes the monitors usually used for viewing images if you have some sort of real live scene and turn it into a computer image by measuring the amount of light coming from each point of the scene then you have created a linear or un gamma corrected image this is a good thing in many ways because you can manipulate the image as if the values in the image file were light ie adding and multiplying will work just like real light in the real world now if you take the image file and turn each pixel value into a voltage and feed it into a crt you find that the crt doesn t give you an amount of light proportional to the voltage the amount of light coming from the phosphor in the screen depends on the the voltage something like this light out voltage crt gamma so if you just dump your nice linear image out to a crt the image will look much too dark to fix this up you have to gamma correct the image first you need to do the opposite of what the crt will do to the image so that things cancel out and you get what you want so you have to do this to your image gamma corrected image image crt gamma for most crts the crt gamma is somewhere between and if that is all it is why does it seem so complicated the problem is that not all display programs do gamma correction also not all sources of images give you linear images video cameras or video signals in general because of this a lot of images already have some gamma correction done to them and you are rarely sure how much if you try and display one of those images with a program that does gamma correction for you the image gets corrected twice and looks way to light if you display one of those images with a program that doesn t do gamma correction then it will look vaguely right but not perfect because the gamma correction is not exactly right for you particular crt whose fault is all this it is really three things one is all those display programs out there that don t do gamma correction properly another is that most image formats don t specify a standard gamma or don t have some way or recording what their gamma correction is the third thing is that not many people understand what gamma correction is all about and create a lot of images with varying gamma s at least two file formats do the right thing the utah graphics toolkit rle format has a semi standard way of recording the gamma of an image the jfif file standard that uses jpeg compression specifies that the image to be encoded must have a gamma of ie a linear image but not everyone obeys the rules some image loaders for instance xli an x image utility allow you to specify not only the gamma of the monitor you are using but the individual gamma values of image you are trying to view other image viewers eg xv another x image program and utilities eg the pbm toolkit provide ways of changing the gamma of an image but you have to figure out the overall gamma correction yourself allowing for undoing any gamma correction the image has and then the gamma correction you need to suite your crt monitor note that xv doesn t provide an easy way of modifying the gamma of an image you need to adjust the r g and b curves to the appropriate gamma in the coledit controls altering the intensity in the hsv controls doesn t do the right thing as it fails to take account of the effect gamma has on h and s this tends to give a tint to the image how can i figure out what my viewer does or what gamma my screen has the simplest way to do that is to try loading the file chkgamma jpg provided with xli distribution which is a jfif jpeg format file containing two grayscale ramps the ramps are chosen to look linear to the human eye one using continuous tones and the other using dithering if your viewer does the right thing and gamma corrects images then the two ramps should look symmetrical and the point at which they look equally bright should be almost exactly half way from the top to the bottom to find this point it helps if you move away a little from the screen and de focus your eyes a bit if your viewer doesn t do gamma correction then left hand ramp will have a long dark part and a short white part and the point of equal brightness will be above the center if your viewer does have a way of setting the right amount of gamma correction for a display then if the equal brightness point is above center increase the gamma and decrease it if it is below the center the value will usually be around with xli for instance you can adjust the display gamma with the dispgamma flag and once you ve got it right you can set the display gamma environment variable in your profile how do i figure out what the gamma of an image is this is the most tricky bit as a general rule it seems that a lot of true color ie bit ppm jpg images have a gamma of linear although there are many about that have some gamma correction it seems that the majority of pseudo color images ie bit images with color maps gif etc are gamma corrected to some degree or other if your viewer does gamma correction then linear images will look good and gamma corrected images will look too light if your viewer doesn t do gamma correction then linear images will look too dark and gamma corrected images will ok why linear images are sometimes not such a good thing one of the reason that many high quality formats such as video use gamma correction is that it actually makes better use of the storage medium this is because the human eye has a logarithmic response to light and gamma correction has a similar compression characteristic this means images could make better use of bits per color for instance if they used gamma correction the implication though is that every time you want to do any image processing you should convert the bit image to or so linear bits to retain the same accuracy since little popular software does this and none of the popular image formats can agree on a standard gamma correction factor it is difficult to justify gamma corrected images at the popular level if some image formats can standardize on a particular gamma and if image manipulation software takes care to use extra precision when dealing with linearized internal data then gamma corrected distribution of images would be a good thing i am told that the kodak photocd format for instance has a standard gamma correction factor that enables it to get the highest quality out of the bits used to hold the image
