Friday, 22 February 2013

RGB channel Equalixzation for 8-bit & 24-bit


Today,I perform various type of histogram equalization or contrast equalization .These are performed on following type of images:-     

a) 8-bit color
b) 8-bit gs
c) 24-bit color
d) 24-bit gs

Each type of image uses following five methods:
a) b
b) g
c) r
d) rgb ( All together but channel by channel)
e) r+g+b (each separately)

So ,I get total 20 output images for 4 input images which are respectively 8-bit gray scale,8-bit color,24-bit gray scale & 24-bit color image.Output images are in above sequence. Here is the input images & output images:

Input Images


Output Images for first image which is 8-bit grayscale






Output Images for second image which is 8-bit color image

Output Images for third image which is 24-bit grayscale image


Output Images for fourth image which is 24-bit color image


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}

Tuesday, 19 February 2013

More about Image file format

Raster Image:-Raster images are actually a grid of pixel,each of which has a no of bits to designate its color equal to the color depth of device displaying it.It is also called bitmap images .In raster images image size is positively correlated to the no of pixel in an image the color depth & bits per pixel of the image. These are widely used in digital cameras ,scanners & laser printers.They are very popular in these days .Example of some Raster image file formats are JPEG,PNG,GIF ,TIFF,RAW & EXIF.

Vector Images:-Vector images can be any dimension dependent of file size.File size increases only with the addition of more vectors.Vector image format contain geometrical description which can be rendered smoothly at any desired display size.Vector images can be displayed with analog CRT technology such as that used in some electronic test equipment,medical monitor,radar displays ,laser shows & early video games.Plotters are also used vector data for draw graphics.Example of some Vector image file format are CGM,Gerber format & SVG.Some 2 D vector formats are AI,CDR,DrawingML etc.Vector images are not always appropriate in graphics work.

Generation Of Vector image:- Vector graphics is based on vectors (also called paths or strokes) which lead through locations called control points .Each of these points has a definite position on the x & y axes of the work plan.Each point ,as well is variety of database,including the location of the point in the work space & the direction of the vector.Each track can be assigned a color,a shape,a thickness & also a fill.This does not affect the size of the files in a substantial way because all information resides in the in the structure .

Difference between RGB & sRGB:-RGB color space is additive color space based on RGB color model.A particular RGB color space is defined by three chromatics of Red,Green & Blue additive color primaries.In this color space all colors produced are combination of these three primary colors.The complete specification of RGB color space also requires a white point chromacity & a Gamma correction curve.
                                 sRGB color space is standard RGB color space created cooperatively by HP & Microsoft in 1996 for use monitors ,printers & the internet.sRGB uses the ITU-R BT.709 primaries & transfer function Gamma curve .Unlike other RGB color spaces ,sRGB gamma cannot be represented as a single numerical value.sRGB color space has been endorsed by W3cC,Exif & Intel etc.The sRGB color space is well specified & designed to match typical home & office viewing condition. sRGB  color space is widely used in HDTV &  CRTs.




   

Monday, 18 February 2013

8-bit color Image

8-bit color image uses 1 byte for each pixel storage it means every pixel occupy 8-bit so it is called 8-bit image.The maximum no of color displayed at one time is 256 which is calculated through formula 2^n where n is bits per pixel.
                          Basically,there is two form of 8-bit color graphics .The most common uses a separate palette of 256 colors,where each of the 256 entries in the palette map to given red,green & blue values.In most color maps each color is chosen from a palette of 2^24 colors but in some cases, thecolor is chosen from palette of 2^12 or 2^18 colors.
                        The second form in which 8 bits directly describes the red ,green & blue component of pixel.The first 2 bytes is used for Blue ,next three bytes is used for green & last three byte of pixel is used for red.This form is sometime called 8-bit true color Because it does not uses palette at all.  

Terminology of Color Theory

There are some special terms which are widely used in color theory or in color processing.Some of them are explained here:-
1)Colorfulness:- Colorfulness is the degree of difference between a color & gray.
                         In other words "The attribute of a visual sensation according to which the perceived color of an area appears to be more or less chromatic ".

2)Chroma:-Chroma is the colorfulness relative to the brightness of another color that appears white under similar viewing conditions.
     In other words "the colorfulness relative to the brightness of a similarly illuminated white".
                   C= M-m

     where
                 M=Max(R,G,B)
                 m=min(R,G,B)


3)Saturation:-Saturation is the colorfulness of a color relative to its own brightness.Saturation for the HSV,HSL and HSI can be calculate by following formulas:-

\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}
4)Lightness:-Lightness is a property of a color or a dimension of a color space that is defined in a way to reflect the subjective brightness perception of a color for humans along a lightness-darkness axis.
                            In other words "the brightness relative to the brightness of a similarly illuminated white."
In the HSL model lightness is defined by the average of largest and smallest color components.
                      L=1/2(M+m)
     where
                 M=Max(R,G,B)
                 m=min(R,G,B)

5)Brightness:-Brightness is an attribute of visual perception in which a source appears to be radiating or reflecting light.In the RGB color space ,brightness can be thought of as arithmetic mean of RGB value.
Brightness is also a color co-ordinates in HSB or HSV color space.It is denoted by B.It is also called value.
In other words "the attributes of a visual sensation according to which an area appears to omit more or less light".In the HSV color model value is defined as largest component of  color.
                               
                                    V = M

     where
                 M=Max(R,G,B)


6)Luma:-Luma represents the brightness in an image.This term is used in color video.Basically luma is the weighted sum of gamma compressed R'G'B' color components of color video.Luma is denoted by Y'.The prime symbol (') denotes gamma compression.For the Rec 709 primaries used in sRGB
                                 Y'709=0.21R+0.72G+0.07B
For the Rec. 601 NTSC primaries
                                 Y'601=0.30R+0.59G+0.11B
                         

7)Luminance:-Luminance is the photometric measure of the luminous intensity per unit area of light travelling in a given direction.It describes the amount of light that passes through or is omitted thruogh a particular area
& falls within a given solid angle.It is denoted by Y.The SI unit for luminance is candela/Square metre.Here is the formula for luminance:-

L_\mathrm{v} = \frac{\mathrm{d}^2 \Phi_\mathrm{v}}{\mathrm{d}A\,\mathrm{d}{\Omega} \cos \theta}



L_\mathrm{v} is the luminance (cd/m2),
\Phi_\mathrm{v} is the luminous flux or luminous power (lm),
\theta\, is the angle between the surface normal and the specified direction,
A is the area of the surface (m2), and
\Omega\, is the solid angle (sr).

8)Luminosity:-Luminosity is generally understood by measurement of brightness.It has SI unit joules per second which is called watt.Here is the formula for luminosity of a star:-


L = 4\pi R^2\sigma T^4 \,
where
σ is the Stefan–Boltzmann constant 5.67×10−8 W·m-2·K-4.

9)Hue:- Hue is one of the main properties of a color.It is also a color co-ordinates in HSV or HSB .The angle around the central vertical axis corresponds hue.A hue is the color element of color wheel.
                                          In other words "the attributes of visual sensation according to which an area appears to be similar to one of the perceived colors : red,yellow.green & blue or to a combination of two of them".
             The hue is the proportion of  the distance around the edge of the edge of the hexagon which passes through the projected point.Typically, it is measured in degrees and denoted by H.
\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}


10)Contrast:-Contrast is the difference between the luminance and/or color that makes an object distinguishable.In visual perception of the real world ,contrast is determined by the difference in the color & brightness of the object & other objects within the same field of view.
                                      Contrast is also the difference between the color or shading of the printed material on a document & the background on which it is printed.Contrast is the ratio of luminance & average luminance. 
11)Intensity:-The total amount of light passing through a area is called intensity.It is denoted by I.It is also called radiance.In the HSI model intensity is the average of three color component:-
                                   
                                         I=1/3(R+G+B) 
       












Types Of Bitmap Header

There are six important type of file header which are given below:-

1)BITMAPFILEHEADER:-It has the first 14 bytes of any bitmap header.It has the following structure:-


struct bitmapHeader
   {
   char identity[2];//2bytes
            unsigned int sizeOfBmp,//4 bytes

            short int reserved,//2 bytes
 reserved1;//2 bytes
    unsigned int Startingadd;//4 bytes
}
This is the structure for the BITMAPFILEHEADER.In this structure identity is the char array which stores header field which is used to identify the bmp.Possible values are BM,BA,CI etc.Unsigned int sizeOfBmp shows the size of bmp file.Short int reserved & reserved1 are reserved value which actually depends upon  application that creates image.The last 4 bytes shows starting address of image data.

2)BITMAPCOREHEADER:-Its structure has five members


struct bitmapCoreHeader
   {
    unsigned int sizeOfDib,//4 bytes
                               widthinPixels,//4 bytes
                               heightinPixels;//4bytes
  short int noOfColorPlanes,//2 bytes
       BitsPerPixel;//2 bytes
}

It has some important information like width & height of BMP in pixels & bitdepth of bmp.

3) BITMAPINFOHEADER:-Its structure has 11 members.It is standard DIB header which we normally use in BMP file.It has total size of 40 bytes.


struct bitmapInfoHeader
   {
    unsigned int sizeOfDib,//4 bytes
                               widthinPixels,//4 bytes
                               heightinPixels;//4bytes
  short int noOfColorPlanes,//2 bytes
       BitsPerPixel;//2 bytes
           unsigned int compressionMethod,//4 bytes
                              imageSize,//4 bytes
                             horRes,//4 bytes
                             verRes,//4 bytes
                             noOfColorsInColorPalatte,//4 bytes
                            noOfImportantColorUsed;//4 bytes
}
It have some specific information like compression method used,horizontal & vertical resolution etc.

4)BITMAPV4HEADER:It has following structure:-

typedef struct {
  unsigned int bV4Size,//4 bytes
               bV4Width,//4 bytes
               bV4Height;// 4 bytes
  short int bV4Planes,//2 bytes
            bV4BitCount;//2 bytes
  unsigned int bV4V4Compression,//4 bytes
               bV4SizeImage,//4 bytes
               bV4XPelsPerMeter,//4 bytes
               bV4YPelsPerMeter,//4 bytes
               bV4ClrUsed,//4 bytes
               bV4ClrImportant,//4 bytes
               bV4RedMask,//4 bytes
               bV4GreenMask,//4 bytes
               bV4BlueMask,//4 bytes
               bV4AlphaMask,//4 bytes
               bV4CSType;//4 bytes
  CIEXYZTRIPLE bV4Endpoints;//36 bytes
  unsigned int bV4GammaRed,//4 bytes
               bV4GammaGreen,//4 bytes
               bV4GammaBlue;// 4 bytes
} BITMAPV4HEADER, *PBITMAPV4HEADER;
It has  Red,Green ,Blue & Alpha mask.4bytes for color space type.It also Gamma for all three RGB values

5))BITMAPV4HEADER:-It is the extended version of BITMAPINFOHEADER.It has following structure:-

typedef struct {
  unsigned int bV5Size,//4 bytes
               bV5Width,//4 bytes
               bV5Height;// 4 bytes
  short int bV5Planes,//2 bytes
            bV5BitCount;//2 bytes
  unsigned int bV5V4Compression,//4 bytes
               bV5SizeImage,//4 bytes
               bV5XPelsPerMeter,//4 bytes
               bV5YPelsPerMeter,//4 bytes
               bV5ClrUsed,//4 bytes
               bV5ClrImportant,//4 bytes
               bV5RedMask,//4 bytes
               bV5GreenMask,//4 bytes
               bV5BlueMask,//4 bytes
               bV5AlphaMask,//4 bytes
               bV5CSType;//4 bytes
  CIEXYZTRIPLE bV5Endpoints;//36 bytes
  unsigned int bV5GammaRed,//4 bytes
               bV5GammaGreen,//4 bytes
               bV5GammaBlue,// 4 bytes
               bV5Intent,// 4 bytes
               bV5ProfileData,// 4 bytes
              bV5ProfileSize,// 4 bytes
              bV5Reserved;// 4 bytes
} BITMAPV5HEADER, *PBITMAPV5HEADER;



Sunday, 17 February 2013

Color Co-ordinates

Color Co-ordinates ranges are a matter of designer choice & there is no universal standard range for many color space.There are different type of color co-ordinates which are explained below:-

1)Hex Triplet
2)sRGB
3)CMYK
4)HSV

1)Hex Triplet:- Hex triplet is a six digit three byte hexadecimal number used in HTML,CSS & SVG and other computing applications to represent colors.The bytes represent red ,green & blue color component.The one byte represent number from 00 to FF (in hexadecimal) & 0 to 255 (in decimal).The hex triplet is formed by concatenating  three bytes in following order:-
Byte 1:red value (color type red)
Byte 2:green value(color type green)
Byte 3:blue value(color type blue)

If the values of red ,green & blue component is respectively 36,104 & 160.Then these are represented by 24,68 & A0 in hexadecimal notation.So hex triplet is obtained by concatenating 6 hexadecimal digit & in this case it will be 2468A0.If any one of these three color values are less than 10 in hex.Then it must be represented with a leading 0 because hex triplet exactly have a six digit number.

2)sRGB:-sRGB is a standard color space created by HP & Microsoft co-operatively.It is used in monitors ,printers & internet.The sRGB color space is well specified & is designed to match home & office view conditions.LCDs ,Digital Cameras & Scanners & printers all follow the RGB  color space.
sRGB also defines a non-linear transformation between the intensity of these primaries.
ChromaticityRedGreenBlueWhite point
x0.64000.30000.15000.3127
y0.33000.60000.06000.3290
Y0.21260.71530.07211.0000







3)CMYK:-It is also called substractive color model .It is used in color printing.If we mix green & blue color in equal proportion then we get Cyan color .If we mix red & blue color in equal proportion then we get magenta & if we combine Red & Green in equal proportion then we get yellow color . K in CMYK used as key color .It is also said that it is used for last letter in black.Because b is already used for blue.

4)HSV:- HSV is used for hue,saturation & value.It is also known as HSB where B is used for brightness.HSV is basically used in computer vision & image analysis for feature detection or image analysis.
The main disadvantage of HSV is it choose a single color & ignore much off complexity of color appearance.
                       


*For calculating no of entries in color table we can use formula 2 ^n where n is the bit depth.So ,it is directly depend on bit-depth.

* General formula for calculating starting address of image data is here:-

           Sa=(Size of header + Size of Color Table)
           
For More than 8-bit depth

Sa=Size of header

Because there is no color table in image of more than 8-bit depth.

For =<8 bit depth,

Sa=(Size of header+(4*no of possible colors)
    =(Size of header +(4*2^n))

where n is bit depth of image.