I am using a machine vision camera that, according to the manufacturer, produces linear pixels. As a result, I need to apply a gamma correction to the image before I can view the result. However, after applying any gamma correction to the image, the colors appear washed out.

Before any gamma correction:

Example Of Raw Output

After applying a 2.2 gamma:

Example Port 2.2 Gamma Application

Overall, the brightness in the image looks substantially better. However, the colors in the color checker appear very desaturated. Is color desaturation a natural consequence of applying a gamma, and if so what can be done to compensate for that effect?

Update: I'm using an IMX 265 from TheImagingSource along with their provided capturing software

  • \$\begingroup\$ could you give the brand and exact type of camera because there are a lot of very different cv cameras (or often times just simple normal cameras) and what software you use. \$\endgroup\$
    – LuZel
    Commented Mar 20, 2019 at 12:39
  • \$\begingroup\$ I updated the post with that information \$\endgroup\$ Commented Mar 20, 2019 at 18:08

2 Answers 2


Just visually, this looks absolutely correct to me. In your non-adjusted image on my color-calibrated monitor, the steps between the gray patches appear irregularly spaced. In the adjusted image, they're more perceptually even.

You ask:

Is color desaturation a natural consequence of applying a gamma, and if so what can be done to compensate for that effect?

Short answer:

No. It's a consequence of not setting proper black levels and white point. You should do that before applying the gamma curve.

Long answer:

The gamma curve you applied is shaped something like this:

original with histogram from linear version with gamma curve to be applied

The light line applies to the values shown in the histogram. Once you've applied that curve, you get a histogram like this:

curve applied

This is basically a boring, "flat" curve — that is, while it's not linear in value, it's perceptually basically so. However, you can see that the values are all bunched up in the middle. This is very functional and may be what you want for machine vision purposes, but is not generally what we want for visual ones. We may want to increase the contrast simply by pulling in the black and white points, like this:

increase contrast

Which gives an image like this:

much less washed out

... much less washed out.

Your camera may have an adjustable black level, and you may want to raise that slightly. You'll also need to set an appropriate white level for your camera for use in conversion. You may want to look at the dcraw code for how this is typically done. (Well, spoiler: dcraw sets the white level to the 99th percentile of the histogram.)

That result has a histogram like this, by the way:

increased contrast

which you can see extends more to the extremes of the histogram. Because I am working with an 8-bit image in an 8 bit space, you can see that the colors are becoming sparse; for "real work" you'd want to work in a higher bit depth (and probably only apply one transform, rather than a series).

In any case, this is still a little boring. In the visual world, we may want to apply an s-curve, like this, to increase the punch:


resulting in


... or something like that.


That Camera's Gamma:

IMX265 is the Sony sensor - I'm going to guess the camera is the DFK 33UX265?

That camera does have a gamma feature you can use (simple gamma) it also allows the use of a LUT if you wanted a more exact transfer curve for Rec709 (HDTV) or sRGB (Computer monitor).

For computer monitor viewing, applying a gamma of 1/2.2 (i.e. 0.4545) to linear image data is (essentially) the inverse or the 2.4 gamma of the monitor with a small gain included). As Mattdm pointed out, you want to set your black and white point before applying the gamma.

Color Desaturation

Color desaturation is not the "inevitable result of gamma," perceived saturation is affected by a number of interdependent factors.

EXPOSURE: when shooting on film, if you overexpose and then print down, you'll get richer, deeper saturation. This is true in digital photography as well, so long as you don't clip at the high end, exposing high and then adjusting down will result in a perceptual increase of saturation. (Thus the reverse is if you underexpose and print UP, you reduce saturation.)

LIGHTING and SCENE/SURROUND: The lighting in the scene and the surrounding imagery will affect local color perception.

DYNAMIC RANGE/CONTRAST: This also affects apparent saturation — as mattdm pointed out, raising the black level and lowering the white level (which increases contrast) also increases saturation — in fact, you can "sort of" consider saturation as a function of colorcontrast.

DEBAYERING ALGORITHM: The nature of the algorithm used to debayer (demosaic) the RAW samples can have a marked effect on saturation. Among other things, the spectral weighting of R, G, and B is 0.21, 0.71, 0.07 — and if a different weighting is used, saturation can be substantially affected.

What is Gamma Anyway?

Gamma is a curve that is related to the human visual perception curve. Gamma is used in digital images to increase the data density in the dark areas of the image where the eye is most sensitive to changes, thus reducing artifacts like "banding" and noise.

In old analog systems such as broadcast television (NTSC/PAL), using gamma reduced apparent noise in the transmission, and the whole broadcast chain for that matter.

For computer viewing use, the standard is "sRGB", which uses a transfer curve with a gamma close to 0.4545 (1/2.2) designed to display on a monitor with ~2.4 gamma (of a 1.1 gamma system gain).

While applying a 2.2 exponent to each color channel (after debayering) is typically close enough, if you are doing image manipulation then the "official" transfer curve has a linearized section which prevents math problems such as an infinite slope at zero. For linear RGB (range 0.0 - 0.1):

Linear to sRGB


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.