User Tools

Site Tools


isp:contrast

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(auto & pixel: image){
    pixel.luma = std::clamp((pixel.luma - 50) * _sct * _sct + 50, 0, 100);
  }
}
/home/adminsub2r/public_html/dokuwiki/data/pages/isp/contrast.txt · Last modified: 2019/07/17 23:45 by Igor Yefmov