CN109246406B - A Realization Method of Automatic White Balance of Color Camera - Google Patents
A Realization Method of Automatic White Balance of Color Camera Download PDFInfo
- Publication number
- CN109246406B CN109246406B CN201811365142.2A CN201811365142A CN109246406B CN 109246406 B CN109246406 B CN 109246406B CN 201811365142 A CN201811365142 A CN 201811365142A CN 109246406 B CN109246406 B CN 109246406B
- Authority
- CN
- China
- Prior art keywords
- gain
- component
- frame image
- white balance
- current frame
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N23/00—Cameras or camera modules comprising electronic image sensors; Control thereof
- H04N23/80—Camera processing pipelines; Components thereof
- H04N23/84—Camera processing pipelines; Components thereof for processing colour signals
- H04N23/88—Camera processing pipelines; Components thereof for processing colour signals for colour balance, e.g. white-balance circuits or colour temperature control
Landscapes
- Engineering & Computer Science (AREA)
- Multimedia (AREA)
- Signal Processing (AREA)
- Processing Of Color Television Signals (AREA)
- Color Television Image Signal Generators (AREA)
Abstract
本发明涉及一种彩色相机自动白平衡的实现方法。该方法提高了彩色相机自动白平衡算法收敛的速度。该方法的主要步骤是:1、根据RGB与YCbCr空间转换关系,获取当前增益和目标增益关系式;2、当前帧图像进行检测白点检测;3、对当前帧图像N进行色温估计,判断是否出现偏色;4、根据步骤1中的当前增益和目标增益关系式计算目标增益;5、对N+2帧图像每个像元的R、B分量的进行增益调整。
The invention relates to a method for realizing automatic white balance of a color camera. This method improves the convergence speed of the automatic white balance algorithm of the color camera. The main steps of the method are: 1. According to the RGB and YCbCr space conversion relationship, obtain the current gain and the target gain relational expression; 2. The current frame image detects the white point detection; 3. Estimates the color temperature of the current frame image N, and judges whether Color cast occurs; 4. Calculate the target gain according to the relationship between the current gain and the target gain in step 1; 5. Adjust the gain of the R and B components of each pixel of the N+2 frame image.
Description
技术领域technical field
本发明涉及一种图像处理技术,具体涉及一种色相机自动白平衡的实现方法。The invention relates to an image processing technology, in particular to a method for realizing automatic white balance of a color camera.
背景技术Background technique
白平衡的基本概念是不管在任何光源下,都能将白色物体还原为白色。在不同的光源或者天气条件下光谱特性是互不相同的,这被称之为色温。从物理意义上讲,人们看到的物体之所以呈现出特定的颜色,是因为光线照向物体时,物体所反射的光在人眼视觉系统中呈现出这种特定颜色。也就是说,能看到的物体颜色不仅取决于其反射特性,而且还和照向物体的光线有关系,比如一张白纸在钨丝灯下会偏橘黄色调,在荧光灯下会偏绿,而在日光下会有点偏蓝。自动白平衡的目的就是自动调整不同色温光照下图像的三基色分量的比例,使其看上去和标准光源下拍摄的颜色一致。The basic concept of white balance is to restore white objects to white regardless of the light source. The spectral characteristics are different under different light sources or weather conditions, which is called color temperature. In a physical sense, the reason why people see objects in a specific color is because when the light hits the object, the light reflected by the object presents this specific color in the human visual system. In other words, the color of an object that can be seen depends not only on its reflective properties, but also on the light that shines on the object. For example, a piece of white paper will be orange-yellow under tungsten light, and greenish under fluorescent light. And in daylight it's a bit bluish. The purpose of automatic white balance is to automatically adjust the ratio of the three primary color components of the image under different color temperature lighting, so that it looks consistent with the color taken under the standard light source.
很多带有自动白平衡功能彩色相机是对YCbCr空间的图像进行色温评估,然后调整Cb和Cr的增益值,使Cb和Cr满足白色像素点的条件,从而完成自动白平衡的功能,因此Cb、Cr的增益的调整方法是自动白平衡的一个重点。Many color cameras with automatic white balance function evaluate the color temperature of images in the YCbCr space, and then adjust the gain values of Cb and Cr to make Cb and Cr meet the conditions of white pixels, thereby completing the automatic white balance function. Therefore, Cb, The adjustment method of Cr gain is an important point of automatic white balance.
现有的方法是通过设置步长,来对增益进行逐级调整,但是采用该方法进行调整时,收敛速度较慢,无法满足高频相机的使用要求。The existing method is to adjust the gain step by step by setting the step size, but when this method is used for adjustment, the convergence speed is slow and cannot meet the requirements of high-frequency cameras.
发明内容Contents of the invention
为了解决背景技术中现有技术的缺陷,本发明提供了一种彩色相机自动白平衡的实现方法,提高了彩色相机自动白平衡的快速收敛的速度。In order to solve the defects of the prior art in the background technology, the present invention provides a method for realizing the automatic white balance of the color camera, which improves the fast convergence speed of the automatic white balance of the color camera.
本发明的具体技术方案是:Concrete technical scheme of the present invention is:
一种彩色相机自动白平衡的实现方法,运行于彩色相机的处理器,所述处理器类型为FPGA或CPU或DSP;通过以下步骤实现:A kind of realization method of color camera automatic white balance, runs on the processor of color camera, and described processor type is FPGA or CPU or DSP; Realize by following steps:
【1】根据RGB与YCbCr空间转换关系,获取当前增益R分量增益γ和目标增益R分量增益γ′的关系式,以及当前增益B分量增益α和目标增益B分量增益α′的关系式;[1] According to the spatial conversion relationship between RGB and YCbCr, obtain the relational expression of the current gain R component gain γ and the target gain R component gain γ′, and the relational expression of the current gain B component gain α and the target gain B component gain α′;
具体公式为:The specific formula is:
【2】设定白点的个数阈值w,对当前帧图像N的每个像素进行检测,判断其是否是白点,统计检测出当前帧图像N的白点个数w′,利用检测出当前帧图像N的白点个数w′和白点的个数阈值w进行比较,若w′≥w,则进行步骤【3】,若w′<w,则进入步骤【6】;[2] Set the number threshold w of white dots, detect each pixel of the current frame image N, judge whether it is a white dot, and count the number w' of white dots in the current frame image N, and use the detected Compare the number w' of white dots in the current frame image N with the threshold w of white dots, if w'≥w, proceed to step [3], if w'<w, proceed to step [6];
【3】对当前帧图像N进行色温估计,判断是否出现偏色;[3] Estimate the color temperature of the current frame image N to determine whether there is a color cast;
求出当前帧图像N所有白点的平均值和 Find the average of all white points in the current frame image N and
如果M设置为9,则判断图像出现了偏色,B或者R的分量需要进行增益调节,进入步骤【4】;if If M is set to 9, it is judged that there is a color cast in the image, and the B or R component needs to be adjusted for gain, and then go to step [4];
如果则判断图像没有出现偏色,进入步骤【6】;if Then judge that there is no color cast in the image, and go to step [6];
【4】当时,根据公式(1)计算出目标增益R分量增益γ′;当时,根据公式(2)计算出目标增益B分量增益α′;【4】when When , the target gain R component gain γ' is calculated according to the formula (1); when , calculate the target gain B component gain α' according to the formula (2);
【5】通过步骤【4】获取的目标增益R分量增益γ′或目标增益B分量增益α′对当前帧图像进行白平衡调整。[5] Use the target gain R component gain γ' or the target gain B component gain α' obtained in step [4] to adjust the white balance of the current frame image.
【6】等待1帧图像传输之后,从第N+2帧图像开始重复步骤【2】-【5】。[6] After waiting for the transmission of 1 frame image, repeat steps [2]-[5] from the N+2 frame image.
进一步地,步骤【3】中当前帧图像N中任意一个像素是白点的判断条件为:Y≥A,|Cb|≤B,|Cr|≤C;其中,A=2048,B=10,C=20。由于实现该方法的相机的量化位数是12bit,灰度值的范围是0~4095,A的值在该方法中设置为灰度值范围的一半,因此将A设置为2048。Further, the judgment condition that any pixel in the current frame image N in step [3] is a white point is: Y≥A, |Cb|≤B, |Cr|≤C; wherein, A=2048, B=10, C=20. Since the quantization bit of the camera implementing this method is 12bit, and the gray value range is 0-4095, the value of A is set to half of the gray value range in this method, so A is set to 2048.
进一步地,白点的个数阈值必须足够多才能保证白平衡的效果和正确性,这里将w设置为像元总数的1/500;Further, the threshold of the number of white points must be large enough to ensure the effect and correctness of the white balance, here w is set to 1/500 of the total number of pixels;
本发明的有益效果是:The beneficial effects of the present invention are:
本发明采用直接计算出增益的方法可以使自动白平衡快速收敛,经过2个或者几个帧周期就可以实现收敛,对于帧频几十帧/秒或者上百帧/秒的相机来说,能够快速的实现白平衡,大大提高了工作效率。The present invention adopts the method of directly calculating the gain to quickly converge the automatic white balance, and the convergence can be realized after two or several frame periods. For cameras with a frame rate of tens of frames per second or hundreds of frames per second, the Quickly achieve white balance, greatly improving work efficiency.
一般的白平衡方法在调整增益时,为了保证收敛速度会设置较大的步长,这样会出现无法收敛的情况。本发明采用的直接计算出增益的方法可以实现相邻两次增益调整的步长非常小,保证了白平衡方法的正确率。In general white balance methods, when adjusting the gain, a larger step size is set in order to ensure the convergence speed, which may lead to failure to converge. The method of directly calculating the gain adopted by the present invention can realize that the step size of two adjacent gain adjustments is very small, thereby ensuring the accuracy of the white balance method.
附图说明Description of drawings
图1为本发明的工作流程示意图;Fig. 1 is a schematic diagram of the workflow of the present invention;
图2为Cb与增益α的线性关系图;Fig. 2 is the linear relationship diagram of Cb and gain α;
图3为Cr与增益γ的线性关系图。Fig. 3 is a linear relation diagram of Cr and gain γ.
具体实施方式Detailed ways
本发明提供了一种通过直接计算出增益的方法,快速、高效的实现了彩色相机的自动白平衡,其具体实施步骤如下:The present invention provides a method of directly calculating the gain, which quickly and efficiently realizes the automatic white balance of the color camera, and its specific implementation steps are as follows:
【1】获取当前增益R分量增益γ和目标增益R分量增益γ′的关系式,以及当前增益B分量增益α和目标增益B分量增益α′的关系式;该步骤的具体实现步骤如下:[1] Obtain the relational expression of the current gain R component gain γ and the target gain R component gain γ′, and the relational expression of the current gain B component gain α and the target gain B component gain α′; the specific implementation steps of this step are as follows:
【1.1】确定RGB空间向YCbCr空间转换的公式;[1.1] Determine the formula for converting RGB space to YCbCr space;
Y=a*γ*R+b*G+c*α*B (1)Y=a*γ*R+b*G+c*α*B (1)
Cb=α*B-Y=-a*γ*R-b*G+(1-c)*α*B (2)Cb=α*B-Y=-a*γ*R-b*G+(1-c)*α*B (2)
Cr=γ*R-Y=(1-a)*γ*R-b*G-c*α*B (3)Cr=γ*R-Y=(1-a)*γ*R-b*G-c*α*B (3)
其中,Y为像素点在YCbCr空间的亮度分量;Cb为像素点在YCbCr空间的蓝色偏移分量;Cr为像素点在YCbCr空间的红色偏移分量;R为像素点在RGB空间的红色分量,G为像素点在RGB空间的绿色分量,B为像素点在RGB空间的蓝色分量,a为空间转换公式中R分量的系数,b为空间转换公式中G分量的系数,c为空间转换公式中B分量的系数,γ为自动白平衡中R分量的增益,α为自动白平衡中B分量的增益。Among them, Y is the brightness component of the pixel in the YCbCr space; Cb is the blue offset component of the pixel in the YCbCr space; Cr is the red offset component of the pixel in the YCbCr space; R is the red component of the pixel in the RGB space , G is the green component of the pixel in the RGB space, B is the blue component of the pixel in the RGB space, a is the coefficient of the R component in the space conversion formula, b is the coefficient of the G component in the space conversion formula, and c is the space conversion The coefficient of the B component in the formula, γ is the gain of the R component in the automatic white balance, and α is the gain of the B component in the automatic white balance.
根据公式(1)、(2)和(3)可以看出,在对γ进行增益调整时,α作为常量;在对α进行增益调整时,γ作为常量。这样γ与Cr呈线性关系,α与Cb呈线性关系,具体的线性关系如图2和图3所示。According to formulas (1), (2) and (3), it can be seen that when adjusting the gain of γ, α is used as a constant; when adjusting the gain of α, γ is used as a constant. In this way, γ has a linear relationship with Cr, and α has a linear relationship with Cb. The specific linear relationship is shown in Figure 2 and Figure 3 .
【1.2】根据公式(1)、(2)和(3)可得:【1.2】According to the formulas (1), (2) and (3), we can get:
Y′=a*γ′*R+b*G+c*α′*B (4)Y'=a*γ'*R+b*G+c*α'*B (4)
Cb′=α′*B-Y′=-a*γ′*R-b*G+(1-c)*α′*B (5)Cb'=α'*B-Y'=-a*γ'*R-b*G+(1-c)*α'*B (5)
Cr′=γ′*R-Y′=(1-a)*γ′*R-b*G-c*α′*B (6)Cr'=γ'*R-Y'=(1-a)*γ'*R-b*G-c*α'*B (6)
其中,Cr′为自动白平衡方法收敛时的红色偏移分量,即目标值,是个常量;Cb′为自动白平衡方法收敛时的蓝色偏移分量,即目标值,是个常量;γ′为自动白平衡方法收敛时R分量的增益,α′为自动白平衡方法收敛时B分量的增益。Among them, Cr' is the red offset component when the automatic white balance method converges, that is, the target value, which is a constant; Cb' is the blue offset component when the automatic white balance method converges, that is, the target value, which is a constant; γ' is The gain of the R component when the automatic white balance method converges, and α' is the gain of the B component when the automatic white balance method converges.
由公式(5)和公式(6)可以整理得到From formula (5) and formula (6), we can get
由此可以看出,通过当前增益γ和α,可以计算出目标的增益γ′和α′。It can be seen from this that, through the current gains γ and α, the target gains γ′ and α′ can be calculated.
【2】设定白点的个数阈值w,对当前帧图像N的每个像素进行检测,判断其是否是白点,统计检测出当前帧图像N的白点个数w′,利用检测出当前帧图像N的白点个数w′和白点的个数阈值w进行比较,若w′≥w,则进行步骤【3】,若w′<w,则进入步骤【6】;;本实施例中w探测器像元总数的1/500。;[2] Set the number threshold w of white dots, detect each pixel of the current frame image N, judge whether it is a white dot, and count the number w' of white dots in the current frame image N, and use the detected Compare the number w' of white dots in the current frame image N with the threshold w of white dots, if w'≥w, go to step [3], if w'<w, go to step [6]; this In the embodiment, w is 1/500 of the total number of detector pixels. ;
当前帧图像N中任意一个像素是白点的判断条件为:Y≥A,|Cb|≤B,|Cr|≤C;其中,A=2048,B=10,C=20。由于实现该方法的相机的量化位数是12bit,灰度值的范围是0~4095,A的值在该方法中设置为灰度值范围的一半,因此将A设置为2048。The judgment condition that any pixel in the current frame image N is a white point is: Y≥A, |Cb|≤B, |Cr|≤C; wherein, A=2048, B=10, C=20. Since the quantization bit of the camera implementing this method is 12bit, and the gray value range is 0-4095, the value of A is set to half of the gray value range in this method, so A is set to 2048.
【3】对当前帧图像N进行色温估计,判断是否出现偏色;[3] Estimate the color temperature of the current frame image N to determine whether there is a color cast;
求出当前帧图像N所有白点的平均值和 Find the average of all white points in the current frame image N and
如果M设置为9,则判断图像出现了偏色,B或者R的分量需要进行增益调节,进入步骤4;if If M is set to 9, it is judged that there is a color cast in the image, and the B or R component needs to be adjusted for gain, and then go to step 4;
如果则判断图像没有出现偏色,进入步骤6;if Then it is judged that there is no color cast in the image, and go to step 6;
【4】当时,根据公式(1)计算出目标增益R分量增益γ′;当时,根据公式(2)计算出目标增益B分量增益α′;【4】when When , the target gain R component gain γ' is calculated according to the formula (1); when , calculate the target gain B component gain α' according to the formula (2);
【5】通过步骤【4】获取的目标增益R分量增益γ′或目标增益B分量增益α′对当前帧图像进行白平衡调整。[5] Use the target gain R component gain γ' or the target gain B component gain α' obtained in step [4] to adjust the white balance of the current frame image.
【6】等待1帧图像传输之后,从第N+2帧图像开始重复步骤【2】-【5】。这样做的原因是当根据第N帧图像计算出新的增益γ′和α′之后,如果帧频足够快,第N+1帧图像已经输出,新的增益并没有起作用。新的增益会作用于第N+2帧图像。所以为了保证自动白平衡的正确性,采用了这种方法。[6] After waiting for the transmission of 1 frame image, repeat steps [2]-[5] from the N+2 frame image. The reason for this is that after calculating the new gains γ' and α' based on the Nth frame image, if the frame rate is fast enough, the N+1th frame image has already been output, and the new gain has no effect. The new gain will be applied to the N+2th frame image. So in order to ensure the correctness of the automatic white balance, this method is adopted.
由于该发明中很多w、A、B、C等参数都是自行设定的,如果出现设定的参数不合适的情况,自动白平衡也会出现无法收敛的情况,这时可以设置自动白平衡的调节次数T。超过这个阈值,自动白平衡会暂时停下来,一段时间后增益恢复默认值,重新开始计算。Since many parameters such as w, A, B, and C in this invention are self-set, if the set parameters are inappropriate, the automatic white balance will also fail to converge. At this time, the automatic white balance can be set The number of adjustments T. If this threshold is exceeded, the automatic white balance will temporarily stop, and after a period of time, the gain will return to the default value, and the calculation will start again.
Claims (2)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201811365142.2A CN109246406B (en) | 2018-11-16 | 2018-11-16 | A Realization Method of Automatic White Balance of Color Camera |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201811365142.2A CN109246406B (en) | 2018-11-16 | 2018-11-16 | A Realization Method of Automatic White Balance of Color Camera |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN109246406A CN109246406A (en) | 2019-01-18 |
| CN109246406B true CN109246406B (en) | 2019-12-31 |
Family
ID=65075567
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201811365142.2A Active CN109246406B (en) | 2018-11-16 | 2018-11-16 | A Realization Method of Automatic White Balance of Color Camera |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN109246406B (en) |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113674258B (en) * | 2021-08-26 | 2022-09-23 | 展讯通信(上海)有限公司 | Image processing method and related equipment |
Family Cites Families (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101227623B (en) * | 2008-01-31 | 2012-07-04 | 炬力集成电路设计有限公司 | White balance adjustment method, system and camera |
| US8493482B2 (en) * | 2010-08-18 | 2013-07-23 | Apple Inc. | Dual image sensor image processing system and method |
| CN104618703B (en) * | 2015-02-09 | 2016-08-24 | 傅邓文 | A kind of white balance adjustment method |
| CN107027017A (en) * | 2017-04-25 | 2017-08-08 | 建荣半导体(深圳)有限公司 | A kind of method of adjustment, device, picture processing chip and the storage device of image white balance |
-
2018
- 2018-11-16 CN CN201811365142.2A patent/CN109246406B/en active Active
Also Published As
| Publication number | Publication date |
|---|---|
| CN109246406A (en) | 2019-01-18 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN109361910B (en) | Adaptive white balance correction method and device | |
| CN103065334B (en) | A kind of color cast detection based on hsv color space, bearing calibration and device | |
| TWI389559B (en) | Foreground image separation method | |
| CN101227623B (en) | White balance adjustment method, system and camera | |
| JP4266461B2 (en) | Color illumination color temperature detection method and apparatus | |
| CN102858072B (en) | Lighting control method and system | |
| CN103327345B (en) | White balance processing method and processing device thereof | |
| WO2015109746A1 (en) | Image color enhancement method and device | |
| CN101957988B (en) | Method and device for obtaining probability distribution of image grey spots and white balance method and device | |
| CN103108469B (en) | Method and device for controlling output light of illuminating device and illuminating system | |
| CN109785240B (en) | A low-illuminance image enhancement method, device and image processing device | |
| CN103227928B (en) | White balance adjusting method and device | |
| CN111899182A (en) | Color enhancement method and device | |
| CN103391412B (en) | The method for displaying image of a kind of light-source brightness Automatic adjusument and device | |
| CN104935900B (en) | Image sensing device, color correction matrix correction method and lookup table establishment method | |
| CN109493291A (en) | A kind of method for enhancing color image contrast ratio of adaptive gamma correction | |
| TW201340727A (en) | White balance method and apparatus thereof | |
| JP2006203393A (en) | Automatic white balance apparatus and automatic white balance adjusting method | |
| KR20100009035A (en) | Apparatus and method for controlling gain of color signal | |
| CN107135384A (en) | White balance adjusting method, device, image processing terminal and storage medium | |
| CN108234971A (en) | White balance parameter determines method, white balance adjustment method and device, storage medium, terminal | |
| CN111669560A (en) | Real-time automatic white balance correction method and system based on FPGA and storage medium | |
| CN103500457A (en) | Method of color cast detection of video image | |
| CN109246406B (en) | A Realization Method of Automatic White Balance of Color Camera | |
| CN105163102A (en) | Real-time image automatic white balance system and method based on FPGA |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant | ||
| OL01 | Intention to license declared | ||
| OL01 | Intention to license declared |