User Tools

This is an old revision of the document!


Contrast

Increasing the contrast increases the separation between dark and bright, making shadows darker and highlights brighter. Increasing it too much may clip both limits' values. Decreasing the contrast brings the shadows up and highlights down to make them closer to one another.

Essentially when the contrast is increased, the pixel's \(L\) value gets “pushed away” from the center of the values' scale, and when the contrast is decreased the \(L\) is being “pushed towards” the center.

For our purposes we are going to adjust the pixel's \(L\) component in the HSL color space, leaving the other two components intact as the Saturation shouldn't be affected by the Contrast and the Hue (at least for now) is also maintaining its invariance during this operation.

Assuming the \(L\) component to be in range \([0..100]%%\) the contrast adjustment looks like this: \[ luma = (luma - 50) * contrast^2 + 50 \\ luma \in [0..100] \\ contrast \in ]0..2.0]%% \]

// pseudo-code
void contrast(/*array of pixels*/image, double _cst){
  for(const & pixel: image){
    pixel.luma = std::clamp((pixel.luma - 50) * _sct * _sct + 50, 0, 100);
  }
}

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also, you acknowledge that you have read and understand our Privacy Policy. If you do not agree, please leave the website.

More information