Beruflich Dokumente
Kultur Dokumente
Pi19404
December 17, 2012
Contents
Contents
Automatic White Balance
0.1 0.2 0.3 0.4 0.5 Color Constancy . . . . . . . . . Gray world assumption . . . . normalized minkowski p-norm References . . . . . . . . . . . . Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
4 4 6 7 7
3 | 10
4 | 10
(a) gray world normalization (b) gray world normalization method 1 method 2
Figure 1: Example 1
5 | 10
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
pi
i
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 2
Figure 2: Example 2
6 | 10
0.4 References
1. 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 Code
The code in included in the document however le can opened/saved by clicking on the icon
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 <pi19404@gmail . com> / # 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 <iostream > # 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
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 <cv : : Vec3b >( 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
67
69
71
73
i f ( a r g c <5 ) { c e r r << " Usage : c o l o r _ b a l a n c e 1 { i n p u t _ f i l e n a m e } o u t p u t f i l e norm ( > 0 ) norm_method ( 0 or 1 ) " << endl ; return 1; } namedWindow ( "AAA" , CV_WINDOW_AUTOSIZE ) ; s t r i n g f i l e =argv [ 1 ] ; Mat s r c ; s r c =cv : : imread ( f i l e . c _ s t r ( ) , 1 ) ; Mat d s t ; i f ( s r c . empty ( ) ) { c e r r << " Cannot load image " << " " << f i l e . c _ s t r ( ) << endl ; return 1; } else
75
77
79
81
83
85
87
8 | 10
91
s r c . copyTo ( d s t ) ;
93
95
Mat s r c 1 ; s r c . copyTo ( s r c 1 ) ;
97
99
101
v e c t o r <Mat> b g r _ p l a n e s ;
103
105
107
109
111
113
115
117
119
121
123
125
127
129
131
cv : : Mat_<cv : : Vec3b > : : c o n s t _ i t e r a t o r i t = s r c 1 . begin <cv : : Vec3b > ( ) ; cv : : Mat_<cv : : Vec3b > : : c o n s t _ i t e r a t o r i t e n d = s r c 1 . end<cv : : Vec3b > ( ) ; cv : : Mat_<cv : : Vec3b > : : i t e r a t o r i t o u t = d s t . begin <cv : : Vec3b > ( ) ;
133
135
137
f o r ( ; i t ! = i t e n d ; ++ i t , ++ i t o u t ) {
139
cv : : Vec3b v1= i t ;
141
9 | 10
143
145
147
149
151
153
155
157
159
161
163
165
167
169
171
173
175
177
179
181
10 | 10