Wednesday 20 February 2013

HSL/HSV/HSI Blog

Cylindrical Coordinate System:-Cylindrical co-ordinate system is a three dimensional co-ordinate system that specifies point positions by the distance from a chosen reference axis,the direction from the axis relative to a chosen reference direction & the distance from a chosen reference plane perpendicular to the axis.The latter distance is given as a positive or negative no depending on which side of reference plane faces the point.
        HSL & HSV are the two most common cylindrical co-ordinate system.HSL & HSV are developed  in 1970.They are widely used today in color pickers in image editing software,less commonly in image analysis
& computer vision.

HSV:-HSV stands for Hue,saturation & value.often also called HSB ,B for brightness. It is also called hex cone model.
HSL:- HSL stands for hue,saturation & light ,often also callled HLS.It is also called double hex cone model.

*We can calculate Chroma from RGB with the following formula :-

\begin{align}
  M &= \operatorname{max}(R, G, B) \\
  m &= \operatorname{min}(R, G, B) \\
  C &= M - m
\end{align}

*We can calculate Hue from RGB with the following formula :-

\begin{align}
  H^\prime &=
    \begin{cases}
      \mathrm{undefined},        &\mbox{if } C = 0 \\
      \frac{G - B}{C} \;\bmod 6, &\mbox{if } M = R \\
      \frac{B - R}{C} + 2,       &\mbox{if } M = G \\
      \frac{R - G}{C} + 4,       &\mbox{if } M = B
    \end{cases} \\
  H        &= 60^\circ \times H^\prime
\end{align}

*We can calculate Lightness from following formula :-

(i)In the HSI model intensity is defined as average of three components:

           I = 1/3(R+G+B)

(ii)In the HSV "hexcone" model value is defined as the largest component of color.

          V=M=max(R,G,B)
(iii)In the bi-hexcone model lightness is defined as the average of largest & smallest color component.

          L= 1/2(M+m)

(iv)Luma is the weighted average of gamma corrected R,G & B

        Y^\prime_{601} = 0.30R + 0.59G + 0.11B\,\!

* Following are the formula for the saturation for HSV,HSL & HSI:-

 \begin{align}
  S_{HSV} &=
    \begin{cases}
      0,           &\mbox{if } C = 0 \\
      \frac{C}{V}, &\mbox{otherwise}
    \end{cases} \\
  S_{HSL} &=
    \begin{cases}
      0,              &\mbox{if } C = 0 \\
      \frac{C}{1 - |2L - 1|},   &\mbox{otherwise}
    \end{cases}
\end{align}


S_{HSI} =
  \begin{cases}
    0,               &\mbox{if } C=0 \\
    1 - \frac{m}{I}, &\mbox{otherwise}
  \end{cases}


Uses of HSI,HSV & HSL:-HSI ,HSV & HSL are often used computer vision,Image analysis for feature detection & image segmentation.It is used in robot vision ,object recognition,content based image analysis & analysis of medical images.It is also used in color pickers of image editors.


HSL to RGB:-
 For converting HSL to RGB ,First of all ,we need to compute chroma:-

                                  
C =
 \begin{align}
  (1 - \left\vert 2 L - 1 \right\vert) \times S_{HSL}
 \end{align}

                                            where C is Chroma
                                            L for Lightness
                                            Shsl for saturation


Next,we find the point on one of the bottom three faces of the RGB cube which has the same hue & chroma as our color.

       \begin{align}
  H^\prime &= \frac{H}{60^\circ} \\
  X        &= C (1 - |H^\prime \;\bmod 2 - 1|)
\end{align}



  (R_1, G_1, B_1) =
    \begin{cases}
      (0, 0, 0) &\mbox{if } H \mbox{ is undefined} \\
      (C, X, 0) &\mbox{if } 0 \leq H^\prime < 1 \\
      (X, C, 0) &\mbox{if } 1 \leq H^\prime < 2 \\
      (0, C, X) &\mbox{if } 2 \leq H^\prime < 3 \\
      (0, X, C) &\mbox{if } 3 \leq H^\prime < 4 \\
      (X, 0, C) &\mbox{if } 4 \leq H^\prime < 5 \\
      (C, 0, X) &\mbox{if } 5 \leq H^\prime < 6
    \end{cases}

Finally ,we add the equal amounts of R,G & B to reach the proper value.

\begin{align}
  &m = L - \textstyle{\frac{1}{2}}C \\
  &(R, G, B) = (R_1 + m, G_1 + m, B_1 + m)
\end{align}




HSV to RGB:-

 For converting HSV to RGB ,First of all ,we need to compute chroma,by multiplying saturation by the maximum chroma for a given value.


                                             C = V \times S_{HSV}\,\!
                                            where C is Chroma
                                            V for value
                                            Shsv for saturation


Next,we find the point on one of the bottom three faces of the RGB cube which has the same hue & chroma as our color.

       \begin{align}
  H^\prime &= \frac{H}{60^\circ} \\
  X        &= C (1 - |H^\prime \;\bmod 2 - 1|)
\end{align}



  (R_1, G_1, B_1) =
    \begin{cases}
      (0, 0, 0) &\mbox{if } H \mbox{ is undefined} \\
      (C, X, 0) &\mbox{if } 0 \leq H^\prime < 1 \\
      (X, C, 0) &\mbox{if } 1 \leq H^\prime < 2 \\
      (0, C, X) &\mbox{if } 2 \leq H^\prime < 3 \\
      (0, X, C) &\mbox{if } 3 \leq H^\prime < 4 \\
      (X, 0, C) &\mbox{if } 4 \leq H^\prime < 5 \\
      (C, 0, X) &\mbox{if } 5 \leq H^\prime < 6
    \end{cases}

Finally ,we add the equal amounts of R,G & B to reach the proper value.

\begin{align}
  &m = V - C \\
  &(R, G, B) = (R_1 + m, G_1 + m, B_1 + m)
\end{align}

Luma/Chroma/Hue to RGB:-

Here we already have Hue & Chroma so we use same strategy:-

 \begin{align}
  H^\prime &= \frac{H}{60^\circ} \\
  X        &= C (1 - |H^\prime \;\bmod 2 - 1|)
\end{align}



  (R_1, G_1, B_1) =
    \begin{cases}
      (0, 0, 0) &\mbox{if } H \mbox{ is undefined} \\
      (C, X, 0) &\mbox{if } 0 \leq H^\prime < 1 \\
      (X, C, 0) &\mbox{if } 1 \leq H^\prime < 2 \\
      (0, C, X) &\mbox{if } 2 \leq H^\prime < 3 \\
      (0, X, C) &\mbox{if } 3 \leq H^\prime < 4 \\
      (X, 0, C) &\mbox{if } 4 \leq H^\prime < 5 \\
      (C, 0, X) &\mbox{if } 5 \leq H^\prime < 6
    \end{cases}

Finally ,we add the equal amounts of R,G & B to reach the proper value.

\begin{align}
  &m = Y^\prime_{601} - (.30R_1 + .59G_1 + .11B_1) \\
  &(R, G, B) = (R_1 + m, G_1 + m, B_1 + m)
\end{align}

No comments:

Post a Comment