User Tools

This is an old revision of the document!


Hue rotation

“Hue rotation” is a global (every pixel) shift of the image's color spectrum by a given radial offset (considering the color wheel).

To rotate the color vector by an angle \(\Theta\) the following matrix multiplication is done:

\[ \begin{bmatrix} R \\ G \\ B \end{bmatrix} \times \begin{bmatrix} cox(\Theta) & sin(\Theta) & 0 \\ -sin(\Theta) & cos(\Theta) & 0 \\ 0 & 0 & 1 \end{bmatrix} \]

In our codebase the Hue adjustment is a 14-bit signed integer in range \([-16383..16384]\) that corresponds to \((-180°..+180°]\).

In RGB color space

In HSL color space

Really, no magic here, once you process the image in HSL color space. The operation is as trivial as adding or subtracting a specified value from the pixel's \(H\) component:

// pseudo-code
void hue_rotation(/*array of pixels*/image, double _hue){
  for(const & pixel: image){
    pixel.hue = std::clamp(pixel.hue + _hue, 0., 360.); // hue is in range [0..360]°
  }
}

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