automatic white balance algorithm 1

10
Automatic White Balance Algorithm Pi19404 December 17, 2012

description

gray world,shades of gray algorithm automatic white balance alorithm

Transcript of automatic white balance algorithm 1

Automatic White Balance AlgorithmPi19404December 17, 2012

Contents

ContentsAutomatic White Balance0.1 0.2 0.3 0.4 0.5 Color Constancy . . . . . . . . . Gray world assumption . . . . normalized minkowski p-norm References . . . . . . . . . . . . Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

44 4 6 7 7

3 | 10

Automatic White Balance

Automatic White Balance0.1 Color ConstancyColor constancy is a mechanism of detection of color indepdent of light source. The light source many introduce color casts in captured digital images To solve the colour constancy problem a standard method is to estimate the colour of the prevailing light and then, at the second stage, remove it. Once the color of light in indiviudal channels is obtained the each color pixel is normalized by a scaling factor . Two of the most commonly used simple techniques for estimating the colour of the light are the Grey-World and Max-RGB algorithms. These two methods will work well in practice if the average scene colour is grey or the maximum is white

0.2 Gray world assumptionThe Gray World Assumption is a white balance method that assumes that your scene, on average, is a neutral gray. Grayworld assumption hold if we have a good distribution of colors in the scene. Assuming that we have a good distribution of colors in our scene,the average reected color is assumed to be the color of the light. Therefore, we can estimate the illuminant color cast by looking at the average color and comparing it to gray. Gray world algorithm produces an estimate of illuminant by computing the mean of each channel of the image. One of the methods of normalization is that The mean of the three compoments is used as illumination estimate of the image. To normalize the image of channel i avg ,the pixel value is scaled by s1 = avgi where avgi is the channel mean and avg is the illumination estimate . Another method of normalization is normalizing to the maximum channel by scaling by si max ( avgR , avgG , avgB ) ri = avgi

4 | 10

Attached are output of standard contrast stretching and present algorithm

(a) gray world normalization (b) gray world normalization method 1 method 2Figure 1: Example 1

5 | 10

Automatic White Balance0.3 normalized minkowski p-norm

Another variant to estimate illumination vector is to calculate the normalized minkowski p-norm for each color channel color constancy algorithm which is based on Minkowski norm - for each color channel, the Minkowski p-norm is calculated and the normalized result forms the estimated illumination vector.

ei =

1 N

1/p

pii

where summation if over all the pixels. Gray world algorithm is obtained by setting p=1 The shades of gray, is given by Finlayson and Trezzi concluded that using Minkowski norm with p = 6 gave the best estimation results on their data set.

(a) minkowski norm 6 normal- (b) minkowski norm 6 normalization method 1 ization method 2Figure 2: Example 2

6 | 10

0.4 References1. A New Color Balancing Method http://www.stanford.edu/class/ee368/Project_ 11/Reports/Cohen_A_New_Color_Balancing_Method.pdfauthor 2. http://research.edm.uhasselt.be/~oancuti/Underwater_CVPR_2012/CVPR_underwater_ final.pdf 3. http://www.imaging.org/IST/store/epub.cfm?abstrid=32117 4. https://ueaeprints.uea.ac.uk/23682/

0.5 CodeThe code in included in the document however le can opened/saved by clicking on the icon

1

3

5

7

9

11

13

15

17

/ This i s a sample program t o demonstrate gray world a l g o r i t h m s using opencv Copyright (C) 2012 by p i 1 9 4 0 4 This program i s f r e e s o f t w a r e : you can r e d i s t r i b u t e i t and/or modify i t under t h e terms o f t h e GNU General P u b l i c L i c e n s e as published by t h e Free Software Foundation , e i t h e r v e r s i o n 3 o f t h e License , or ( a t your o p t i o n ) any l a t e r v e r s i o n . This program i s d i s t r i b u t e d i n t h e hope t h a t i t w i l l be u s e f u l , but WITHOUT ANY WARRANTY; without even t h e implied warranty o f MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See t h e GNU General P u b l i c L i c e n s e f o r more d e t a i l s . You should have r e c e i v e d a copy o f t h e GNU General P u b l i c L i c e n s e along with t h i s program . I f not , s e e < h t t p ://www. gnu . org/ l i c e n s e s / >. / / @ f i l e c o l o r _ b a l a n c e _ 2 . cpp @ b r i e f This i s a sample program t o demonstrate gray world a l g o r i t h m s @author p i 1 9 4 0 4 / # i n c l u d e " opencv2/highgui/highgui . hpp " # i n c l u d e " opencv2/imgproc/imgproc . hpp " # i n c l u d e # i n c l u d e < s t d i o . h> using namespace s t d ; using namespace cv ;

19

21

23

25

27

29

31

33

7 | 10

Automatic White Balance35

void gray_world ( Mat s r c 1 , f l o a t ml , f l o a t ma, f l o a t mb, i n t p ) { ma= 0 ; mb= 0 ; ml = 0 ; f o r ( i n t i = 0 ; i < s r c 1 . rows ; i ++) { f o r ( i n t j = 0 ; j < s r c 1 . c o l s ; j ++) { Vec3b v1= s r c 1 . at ( i , j ) ; f l o a t l c =pow( v1 . v a l [ 0 ] , p ) ; f l o a t ac=pow( v1 . v a l [ 1 ] , p ) ; f l o a t bc=pow( v1 . v a l [ 2 ] , p ) ; ma=ma+ac ; mb=mb+bc ; ml=ml+ l c ; } }

37

39

41

43

45

47

49

51

53

55

57

59

61

ma=pow ( ( f l o a t ) ma/( s r c 1 . c o l s s r c 1 . rows ) , ( f l o a t ) 1/p ) ; mb=pow ( ( f l o a t ) mb/( s r c 1 . c o l s s r c 1 . rows ) , ( f l o a t ) 1/p ) ; ml=pow ( ( f l o a t ) ml/( s r c 1 . c o l s s r c 1 . rows ) , ( f l o a t ) 1/p ) ; }

63

65

i n t main ( i n t argc , char argv [ ] ) {

67

69

71

73

i f ( a r g c