ISSN: 1693-6 930                                                     45     Im age Enhan cem ent Usi n g  Contra st Stretchin g …… (Kartika Fi rda u sy)  IMAGE ENHANCEMENT USING CONTRAST  STRETCHING ON RGB AND IHS DIGI TAL IMAGE      Kar t ika Firda u s y , Tole Su tikno, Eko Prasety o   Cente r  for Electri c al Engi n eerin g Re se a r ch a nd Soluti on (CEE RS)  Electri c al Eng i neeri ng Dep a rtment, Ahm ad Da hlan  Un iversity  3 rd  Campus, Prof.. Soepomo Stree t, Janturan, Yogy akarta 55164  Tel. (027 4) 3 8152 3, 3794 1 8  ext 220, Fax. (0274) 3 8 1 523   email:  k a rtik af@ i ndos a t.net.id tholes20 00@ya hoo. com        A b st r a ct  Low contra st  im age ha relativel y   bad  quality si nce   its inform atio n can  not be  dire ctly  interp reted b y  hum an eye s . It s  quality ca n be im pr ove d  using  cont rast stret c hin g  operatio n. The  obje c tive of t h is pa per i s  to desi gn software fo r en h ancem ent usi ng co ntra st st retchi ng o n  RGB  and I H S digit a l im age m o d e ls. Th e o p e r ation i s  a  poi nt ope ration,  that ea ch  pixel on  the im a ge  is processe d  individ uall y , by da rkeni ng da rk   pixels an d b r ig htening b r ig ht pixel s . T he  developm ent  of the softwa r e was d one  usin g TBitm ap cla ss i n  Bo rland  Delp hi  6.0. Tests  ha ve   been  perfo rm ed on BMP a nd PEG grayscale a s  well  as   colo r im ages. The te st result  sho w s that   the de velo pe d software i s  ca pable  to  enha nce the  contrast  of th e sam p le im age s, which   are  sho w n b y  the  expa nsi on of  the histogra m s of the im ages.     Key w ords :  i m age enhan cem ent, contra st stret c hin g , point ope ratio n , RGB, IHS        1.  INTRODUCTION  Some  colo model s a r u s ed  in di gital  image  proce ssi ng to  re prese n t an i m a ge, e.g.  RGB, IHS, YIQ, CIE, and CMY model s.  RGB model  i s  frequ ently used  sin c e it is good to provi de  colo r inform ation, although  this model is  not prop er for some imag e pro c e ssi ng o peratio n. Some  image  pro c e s sing  ope ratio n s fo rce the  use  of a m o d e l othe r tha n   RGB m odel, i . e. IHS mode l.  Some of im age p r o c e ssi ng op eratio n s  for thi s  m odel a r e p a ttern recogniti on an d ima ge  comp re ssion.    An image ca n be analyze d by examining its  histog ram. Image histogram is a  graph   sho w in g the  freq uen cy o f  every  colo r co ntaine i n  it. The  ho rizo ntal axi s  of a  histo g ram  rep r e s ent s th e value of th e colo r (0-25 5 ), whil e t he  vertical axi s   sho w s the nu mber  of pixels of  each col o r [4] .  Not all imag e can  be ea si ly analyz ed, f o r exampl e, image  with lo w co ntra st. This  kind of ima g e  is pro d u c ed  unde r low o r   uneven lig hting. Low  cont rast ima ge can be en han ced   by contra st st retchi ng. Thi s  operatio n is  a point  ope ra tion, where gray level of a  pixel is mapp ed   to anoth e gray level de p end s o n  cert ain fun c tion.  Point ope rati on i s  an  ima ge o peration  in  whi c h ea ch  pixel of the image i s  processed in de p e ndently to other pixel s  [1] .  By performi ng  contrast en ha ncem ent, the image can be  clearly ob eserved an d an alyzed.   Re cently, ma ny imag e file  format exist, e. g. BMP, J PEG, GIF, I C O, and WMF. The  way a n  ima g e  is saved  de pend on th need. F o r im age tran sfer  via intern et, d a ta comp re ssion   and compatib ility are need ed. This pa pe r use d  2 imag e formats, i.e. BMP and JPEG.      2. MATERI A L  AN D MET H O D   This  pape r p r ocesse d 2 - d i mensi on  still image  whi c h is  rep r e s e n ted in M x  N matrix   form, wh ere  M and  N a r e  the width  an d heig h t of  th e imag e. The  matrix can b e  treate d  a s   2- dimen s ion a r ray, repre s e n ting x and y co ordin a tes.    Contrast stret c hin g   can  b e  done by  empl oyi ng GST  (Gray Scale T r an sform )  fun c tion a s   sho w n in Equ a tion 1[1].    K = G(K i  – P) +  P                           (1)    Evaluation Warning : The document was created with Spire.PDF for Python.
                                   ISSN: 16 93-6 930     TELKOM NIKA   Vol. 5, No. 1,  April 2007 :  45 - 50   46 K 0  is the  pix e l value  of o u tput imag e,    K i  is the  pixel value  of in put imag e, G  is th cont rast  stren g th co efficient, and P is the graysca l e va lue that is used a s  ce nter of co ntra st.  The de sign p hase wa s divided into 2 st eps, i.e. algo rithm de sign i n  flowchart fo rm and  algorith m  imp l ementation.  Figure 1  sho w s the flo w ch art of th e d e velope syste m . The i nput  ca n   be eithe r  g r a y scal e  o r  tru e  colo r im age.  If the i nput i s   a grayscale i m age, the  progra m  contin ues  to the next p r ocess, i.e. cont ra st enha ncem ent. But, if it is a  true colo r imag e, the progra m   pro c ee ds to  choo se wheth e r the u s er  wants  to do im age conversi on. If so, the RGB color im age  input will  be  conve r ted to  IHS model. T h is  conve r si o n  process i s   to pro d u c e g r ayscale ima g e Else, the RG B image will be dire ctly applied to c ontrast enha nce m ent. The ne xt step is to save  the resulted i m age to eithe r  BMP or JPE G  file.         Figure 1. Flowchart of the  system       Followi ng i s  the al gorith m   to implem ent  impr oveme n t  of imag q uality usi ng  contra st  enha ncement   2.1.  Algorithm to  calculate intensit y  frequenc y   This algo rith m is u s ed  to  cal c ul ate th e nu mb e r  of  pixels that  contai ns cert ain  colo intensity to determin e  the intensity frequ enci e s. The a l gorithm for g r ayscale i s  as follow  a). Take the informatio n of bit per pixel o f  the image   FPro se s.Image1.Pictu r e.Bitmap.  PixelFormat =  pf8bit;    b). Perform in itialization on  cou n t variabl c[ i] = 0;   c). Repeat for each pixel   for i:= 0 to 25 5;  d). Cou n t up the frequ en cy of value for the examined p i xel  inc ( c [ PC[i]]);   Evaluation Warning : The document was created with Spire.PDF for Python.
TELKOMNI KA   ISSN:  1693-6930      Im age Quality Im provem e n t Usin g Co ntrast Stret c hin g ……(K a rtika  Firdau sy)  47 e). Rep eat for all pixels in the image   For i:= 0 to F P roses.Imag e1.Picture.He ight-1;   For j:= 0 to F P roses.Imag e1.Picture.Wi dth-1;     After all pixels are an alyze d , the maximum co u n t of all grayscale is calcul ated u s ing the  following algorithm.    f). Set maxim u m c o unt  Max <> 0 the n  cMax =max;  Max = 0 then  cMax=0;   g). Rep eat for all pixels in the image   For i:= 0 then  255;   For 24 bit tru e  colo r imag e ,  the algorith m  is simila r to the above. Howeve r, sin c e  each pixel h a three colo r el ements, the a nalysi s  wa s d one for the th ree ele m ent s.    2.2.  Algorithm fo r contr ast e n hanceme n This al gorith m  is u s ed to  control the  co ntra st of the i m age, which need s a tra n formatio n   usin certai con s tant s. Th e op eratio n i s  don sep a ra tely for e a ch i m age  form at. Before  save d   into an  array  variable, th maximum a n d  minim u m v a lue fo r the  resulte d  ima g e  are d e termi ned.  Folowi ng is th e algoruthm for co ntra st eh nacement for  grayscal e im age:   a). Take the informatio n of bit per pixel o f  the image  FPro se s.Image1.Pictu r e.Bitmap.PixelFormat = pf8bit;     b). Rep eat for all pixels in the image   For i:= 0 to F P roses.Imag e1.Picture.He ight-1;   For j:= 0 to F P roses.Imag e1.Picture.Wi dth-1;   c). Ta ke the value of the pi xel being pro c e s sed   PC:= FPro se s.Image1.Pi cture.Bitmap. Scanli ne[i];  PH:= FPro se s.Image2.Pi cture.Bitmap. Scanli ne[i];  d). Cal c ulate  the value of the re sult   temp:=  Round(K*(P C[j]-P)+ P);   e). Apply value limiter, i.e. if the value of  a pixel  is gre a ter than 25 5 ,  then the pixel value is set to  255; and if the value of taht pixel is less  than 0, then the pixel value  is set to 0.  If (temp > 25 5) then temp: =  255;   If (temp < 0 then) tem p :=  0;  f).  Put the pixel value in the image bitm ap memo ry  PH[i]:=  temp;  The alg o rith m for true  col o r imag e is  si milar to  the a bove, however the al gorit hm is a pplied  for  the three  colo r eleme n ts (R, G and B).       3. RESULT A ND  DISCUS SION   The im plem entation  of the p r og ram  into a  p r o g ram  was d one  usi ng  Delphi  6.0   Integrated  Developme n t Environme n t. The progra m   wa s tested  using  seve ral test image s that  have lo w con t rast, with va rious te nde ncy of brightne ss, i.e. dark  co lor ima ge, bri ght col o r im a ge,  as well as g r a y scal e  image.     3.1.  Dark  Color Image   Test im age  h a s lo co ntra st and  da rk a ppea ran c e. T he qu ality of image s p o ssessing   this kind of  cha r a c teri stic can be improved increa si ng by  it s co nt rast  st ren g t h  (G).  Figu re  2  sho w s an  example  of the  result of ap pl ying the  p r og ram o n  lo contra st Bird.b mp. The  re su lt  image was th en rep r e s e n ted in RGB  co lor mod e l ca n  saved in a JPEG file.  Figure 2.a  sh ows that th origin al im ag e ap pea rs   da rk, with co ntr a st  stre ngth coefficient  (G)  = 1 and  cente r  of co n t rast (P)  = 0.  Its orig inal h i stogram for  each col o r el ement (R,G,B) is  narro w and lo cated o n  the left part of its absi c a (Fig u r e 2.b). This t e lls u s  that the image ha s l o contrast. Fig u re 2.c i s  the result imag e of t he contrast en han ce ment prog ra m using  cont rast   stren g th coef ficient (G 3 and  cente r  of cont rast  (P) = 0. Th e resu lt ima ge  appe ars sharper  comp are to the ori g inal i m age. Th e h i stogram s of all colo r ele m ents a r wi dene d apa rt and   cover all g r ay  scal e  ran ge, i.e. 0-255 (Figure 2.d ) .   Evaluation Warning : The document was created with Spire.PDF for Python.
                                   ISSN: 16 93-6 930     TELKOM NIKA   Vol. 5, No. 1,  April 2007 :  45 - 50   48   Figure 2 .  Co ntrast Stret c h i ng on Bird.b mp,  (a) o r iginal image   (b) histogram  of  original image (R , G, B),  (c ) result  image (d) histogr am of result imag     2. Bright  Image  Image that h a s lo w contra st and it s hist ogra m  is  m o stly locate d to the rig h t of the gray  scale  ran ge i s  difficult to  a nalyze,  sin c the im ag e ap pears to o b r i ght. To imp r o v e its qu ality can   be d one  by  adju s ting th e  co ntra st  stre ngth  coeffici e n t (G ) a s   wel l   as the  co ntrast  ce nter (P).  Figure 3 is an  example of light image. Th e result imag e wa s save d in to a BMP file.  Figure 3.a  sh ows the  o r igi nal 8  bit  colo r ima ge. T h e  imag e i s  too  bri ght, be ca use  its  histog ram s  fo r ea ch  ele m e n ts a r mo stly at right  sid e  (hig colo r v a lue) a s   sho w by Figu re   3.b.  Figure 3. c is the e nhan ce image  usi ng  contrast  stre n g th coefficie n t (G) = 6 a nd  contrast  ce nter  (P) = 2 55. Th e re sult imag e is obviou s l y  easie r to analyze. Th e histog ram s  a r e wide ned to  the  left after the enhan cem ent (Figure 3.d).   Evaluation Warning : The document was created with Spire.PDF for Python.
TELKOMNI KA   ISSN:  1693-6930      Im age Quality Im provem e n t Usin g Co ntrast Stret c hin g ……(K a rtika  Firdau sy)  49     Figure 3 .  Co ntrast Stret c h i ng on Eleph a n t.bmp,  (a) o r iginal image  (b) histogram  of  original image (R , G, B),  (c ) result  image (d) histogr am of result imag     3.  Gra y  scale image   Gray scale i m age ha s the same valu es for all col o r eleme n ts  (R,G,B). The  original   image  wa s converted  into  IHS  colo r m odel, afte r th en b e  a pplie d  by contrast  stre cthing.  Fi gure   4.a sho w s an  example of 8 bit color im age befo r conversion, wi th original hi stogram s for e a ch   colo r elem ent s are sh own in Fi gure 4.b. The imag e was then  conv erted fro m  RGB colo r mo del  to IHS. The intensity element of this col o r mo d e l wa s then  processe d usin g co ntra st  enha ncement  algorith m . F i gure  4.c  sh ows the inte nsity eleme n t of the IHS  image, with i t histog ram  sh own  in Fi gure 4.d. After a pplying  c ont rast e nhan ce ment alg o rith m for  gray  scale   image, the result image and its histogram  c an be shown in  Figure 4.e and Figure 4.f,  respe c tifully. It can be seen  that the histogram of  the result imag e is stretched for  the whol e gra y   scale value s  (0-25 5 ).   Evaluation Warning : The document was created with Spire.PDF for Python.
                                   ISSN: 16 93-6 930     TELKOM NIKA   Vol. 5, No. 1,  April 2007 :  45 - 50   50     Figure 4 .  Co ntrast Stret c h i ng on Anoa. bmp   (a)  Original image, (b)  Original histogram ( R ,G,B ), ( c ) IHS image, (d )  IHS image histogram,    (e) Result of cont rast stretching, (f ) Histogram of  re sult image      4. CONCL U S I ON  Based  on the  test result on  the image sa mples, the d e v eloped  software can be  use d  to   enha nce the  contrast  of th e imag es.  Th e imp r oveme n t of imag quality can b e  seen  by th expan sion of  its histog ra m by adj u s ting the contrast strength  c oeffici ent a nd the cente r  of   contrast.       REFERE NC ES  [1]  Achma d B. dan Fird au sy,  K.,  “Digital Image Pro c essing   With Delphi“ ,  Ardi  Publi s hing,   Yogyaka r ta, 2005.   [2]  Andreswari,   D.,   “Imag e  Enhence m ent With  Borland  Del phi“ , Tes i s  of Informatic   Dep a rtem ent Ahmad Dahla n   University, Yogyaka r ta, 2002.   [3] Munir,  R.,  “Digital Image Processin g   With   Alg o rithm Approa c h , Informati k a Publishi ng,  Bandun g, 20 04.  [4]  Nalwan, A.,   “Digital Image Processi ng” , PT. Elex Media Komp utindo Publi s hing, Ja ka rta,    1997.   Evaluation Warning : The document was created with Spire.PDF for Python.