Embodiment
In order to make purpose of the present invention, technical scheme and advantage clearer,, the present invention is further elaborated below in conjunction with drawings and Examples.Should be appreciated that specific embodiment described herein only in order to explanation the present invention, and be not used in qualification the present invention.
When the embodiment of the invention is adjusted in white balance, the validity of reference white point color temperature information is assessed, carried out the white balance adjustment, can improve efficient and accuracy that white balance is adjusted at effective color temperature information.
Fig. 1 shows the realization flow of the white balance adjustment method that the embodiment of the invention provides, and details are as follows:
In step S101,, be the YCbCr form with the image transitions of rgb format by color space conversion;
In embodiments of the present invention, the image of YCbCr form can obtain by color space conversion, the transformational relation between rgb color space and the YCbCr color space as shown in Equation (1):
Utilize formula (1), the picture frame of rgb color space can be converted to the picture frame of YCbCr color space, obtain the RGB data and the YCbCr data of pixel.
In step S102, the reference white point in the detected image, and go out color temperature information according to the data statistics of reference white point;
As one embodiment of the present of invention, during reference white point in detected image, can judge according to following formula:
(Y_pixel-|Cb_pixel-128|-|Cr_pixel-128|)>thr_dyn (2)
Wherein, Y_pixel, Cb_pixel and Cr_pixel are respectively luminance component, chroma blue component and the red color component of pixel, and thr_dyn is with reference to the white point judgment threshold, influence the reference white point number in the picture frame.Owing to may according to circumstances adjust in the subsequent operation to thr_dyn, so when first frame handled, the value of thr_dyn was very unimportant, in general, when first frame was handled, the value of thr_dyn can be set to~0.
In one embodiment of the invention, in utilizing the process of above-mentioned formula (2) detection, can also take following formula that each tested pixel is detected simultaneously with reference to white point:
R_pixel<R passage threshold value (3)
G_pixel<G passage threshold value (4)
B_pixel<B passage threshold value (5)
Y_pixel<luminance threshold (6)
Wherein, R_pixel, G_pixel, B_pixel, Y_pixel are respectively R component, G component, B component and the luminance component of pixel, and R passage threshold value, G passage threshold value, B passage threshold value and luminance threshold are predefined constant.In general, the span of R passage threshold value, G passage threshold value, B passage threshold value is generally 210 to 255, and the span of luminance threshold often can be set to 200 to 240.
During specific implementation, can choose formula (3), (4), (5) or (6) one of them as the noise filter criteria, also can get these formula arbitrarily " with " or " or " combination as the noise filter criteria.
By formula (3)-(6), can realize the noise in the filtering image, avoiding the over-exposed harmful effect that causes, and take precautions against the color spillover, thereby improve the accuracy that white balance is adjusted, optimize the output effect of image.
In an embodiment of the present invention, then specifically comprise accumulated value Sum (R), Sum (G), Sum (B) with reference to white point R, G, three passages of B with reference to the color temperature information of white point, and with reference to the quantity counter of white point.In a preferred embodiment of the invention, in when the quantity counter of reference white point of accumulative total reaches first threshold N_max, then can finishing to image with reference to the detection and the statistics of white point.
As one embodiment of the present of invention, the reference white dot information can be realized by statistics with histogram.
In step S103, judge in this picture frame whether the color temperature information with reference to white point is effectively, be execution in step S104 then, otherwise execution in step S106;
In embodiments of the present invention, will compare, when N_min<counter<N_max, then can judge effective with reference to the color temperature information of white point with reference to the quantity counter of white point and first threshold N_max and the second threshold value N_min; Otherwise when counter 〉=N_max or counter≤N_min, it is invalid then to judge with reference to the color temperature information of white point.In above preferred embodiment, described then is counter=N_max or counter≤N_min with reference to the invalid judgement standard of the color temperature information of white point.Wherein, the first threshold N_max and the second threshold value N_min are predefined value.The first threshold N_max and the second threshold value N_min can be set to image in the proportional number of sum of all pixels, in general, first threshold N_max can be provided with 0.01 times of sum of all pixels in the image, the second threshold value N_min can be provided with 0.001 times of sum of all pixels in the image
In step S104, calculate the gain of R, G, B passage according to the color temperature information of reference white point;
In embodiments of the present invention, calculate all R, mean value R_avg, the G_avg of G, B, B_avg earlier with reference to white point, respectively shown in formula (7), (8), (9):
R_avg=Sum(R)/counter (7)
G_avg=Sum(G)/counter (8)
B_avg=Sum(B)/counter (9)
Calculate all mean values again with reference to the Y of white point, as shown in Equation (10):
Y_avg=0.257×R_avg+0.504×G_avg+0.098×B_avg (10)
Then the calculating of gain R_gain, the G_gain of R, G, B passage, B_gain is respectively shown in formula (11), (12), (13):
R_gain=R_avg/R_avg (11)
G_gain=R_avg/G_avg (12)
B_gain=Y_avg/B_avg (13)
In step S105, according to the gain of R, G, B passage original R, G, the B value of each pixel in the image are adjusted, obtain new R, G, B value;
In embodiments of the present invention, the calculating of new R, G, B value R_new, G_new and B_new is respectively shown in formula (14), (15), (16):
R_new=R×R_gain (14)
G_new=G×G_gain (15)
B_new=B×B_gain (16)
In step S106, adjustment dynamic threshold thr_dyn adds up the reference white point in next picture frame.
In embodiments of the present invention, directly influence in the two field picture number with reference to white point judgment threshold thr_dyn with reference to white point, therefore when invalid color temperature information occurring, need adjust reference white point judgment threshold thr_dyn value, to guarantee in the next frame image validity with reference to the white point color temperature information.
In embodiments of the present invention, can dynamically adjust in predefined fixedly span with reference to white point judgment threshold thr_dyn, its adjusting can be adopted the mode of the joint step-length that modifies tone, for example regulate step value: 5 for be provided with 4 with reference to white point judgment threshold thr_dyn, 10,20,40.During adjustment, record and comparison are with reference to the adjusting direction of the last picture frame of white point judgment threshold thr_dyn and current adjusting direction, a picture frame is regulated situation and current situation on the analysis-by-synthesis, adjusts in real time and regulates step-length, to find suitable reference white point detected value as early as possible.When the white balance adjustment moves for the first time, can put judgment threshold thr_dyn for reference white an initial value is set, and in above-mentioned 4 step values, select one as the initial adjustment step-length, later on be value after the up-to-date adjusting with reference to the value of white point judgment threshold thr_dyn, its concrete control method as shown in Figure 2:
In step S201, whether the quantity counter of reference white point that judges present frame more than or equal to first threshold N_max, is execution in step S202 then, otherwise execution in step S209.
In step S202, determine that current direction with reference to white point judgment threshold thr_dyn is big for transferring, judging according to the record of regulating direction indicator whether a last picture frame also is to transfer greatly with reference to the adjusting direction of white point judgment threshold thr_dyn again, is execution in step S203 then, otherwise execution in step S206.
But described adjusting direction indicator can be the unit of the adjusting direction of stored reference white point judgment threshold thr_dyn such as variable.
At step S203, whether the adjusting step-length of judging a last picture frame equals maximum step value (40) or big step value (20), is execution in step S204 then, otherwise execution in step S205.
In step S204, transfer big current, promptly current with reference to the adjusted adjusting step-length of the last picture frame of white point judgment threshold thr_dyn=with reference to the last picture frame of white point judgment threshold thr_dyn+ with reference to white point judgment threshold thr_dyn by the adjusting step-length of a last picture frame.
In step S205, transfer big currently by rising adjusting step-length after the one-level with reference to white point judgment threshold thr_dyn, if the adjusting step-length of a promptly last picture frame is 5, then current adjusting step-length is 10; If the adjusting step-length of a last picture frame is 10, then current adjusting step-length is 20, and is current adjusted with reference to the adjusting step-length after the white point judgment threshold thr_dyn+ upgrading with reference to white point judgment threshold thr_dyn value=last picture frame.
In step S206, judge whether the adjusting step-length of a last picture frame equals minimum step value (5), be execution in step S207 then, otherwise execution in step S208.
In step S207, transfer big current, then current adjusted with reference to white point judgment threshold thr_dyn+5 by minimum step with reference to the last picture frame of white point judgment threshold thr_dyn=with reference to white point judgment threshold thr_dyn.
In step S208, transfer big current by the adjusting step-length of falling after the one-level with reference to white point judgment threshold th_dyn, if the adjusting step-length of a promptly last picture frame is 10, then current adjusting step-length is 5, by that analogy, then current adjusted with reference to the adjusting step-length behind the white point judgment threshold thr_dyn+ degradation with reference to the last picture frame of white point judgment threshold thr_dyn=.
In step S209, determine that current direction with reference to white point judgment threshold thr_dyn for turning down, judges with reference to the adjusting direction of the last picture frame of white point judgment threshold thr_dyn again and whether also turn down, be execution in step S210 then; Otherwise execution in step S213.
At step S210, whether the adjusting step-length of judging a last picture frame equals maximum step value or big step value, is execution in step S211 then, otherwise execution in step S212.
In step S211, turn down current with reference to white point judgment threshold thr_dyn, promptly current with reference to the adjusted adjusting step-length of the last picture frame of white point judgment threshold thr_dyn=with reference to the last picture frame of white point judgment threshold thr_dyn-by the adjusting step-length of a last picture frame.
In step S212, turn down current with reference to white point judgment threshold thr_dyn, promptly current adjusted with reference to the adjusting step-length after the white point judgment threshold thr_dyn-upgrading with reference to white point judgment threshold thr_dyn value=last picture frame by the adjusting step-length that rises after the one-level.
In step S213, judge whether the adjusting step-length of a last picture frame equals the minimum step value, be execution in step S214 then, otherwise execution in step S215.
In step S214, turn down current with reference to white point judgment threshold thr_dyn, then current adjusted with reference to white point judgment threshold thr_dyn-5 by minimum step with reference to the last picture frame of white point judgment threshold thr_dyn=.
In step S215, turn down current with reference to white point judgment threshold thr_dyn, then current adjusted with reference to the adjusting step-length behind the white point judgment threshold thr_dyn-degradation with reference to the last picture frame of white point judgment threshold thr_dyn=by the adjusting step-length of falling after the one-level.
In the embodiment of the invention, can be (0,240) with reference to the span of white point judgment threshold thr_dyn.
Fig. 3 shows the structure chart of the white balance adjustment system that the embodiment of the invention provides, and color space converting unit 31 is converted to the view data of rgb format the view data of YCbCr form by the color space conversion.Reference white point in colour temperature assessment unit 32 detected image is added up color temperature information according to the reference white point, and judges the validity of this color temperature information, exports effective color temperature information.Gain adjusting unit 33 is according to the gain that the effective color temperature information of colour temperature assessment unit 32 output calculates R, G, B passage, utilizes the gain of R, G, B passage to adjust R, G, the B value of pixel in the image, and image is regulated.
Fig. 4 shows the structure of the camera head that the embodiment of the invention provides, and for convenience of explanation, only shows the part relevant with the embodiment of the invention.
Camera 41 images acquired signals are the image data of rgb format through white balance loop 42 output signals.Color space converting unit 43 transfers the view data of rgb format to the view data of YCbCr form by the color space conversion.Reference white point in colour temperature assessment unit 44 detected image is added up color temperature information according to the reference white point, and judges the validity of this color temperature information, exports effective color temperature information.The gain that gain adjusting unit 45 is calculated R, G, B passage according to the effective color temperature information of colour temperature assessment unit 44 output, and configuration camera 41 utilize the gain of R, G, B passage to adjust R, G, the B value of pixel in the image, and image is regulated.
In embodiments of the present invention, color temperature information comprises with reference to the accumulated value Sum (R) of white point R, G, three passages of B, Sum (G), Sum (B), and with reference to the quantity counter of white point.
Fig. 5 shows the structure of the colour temperature assessment unit that the embodiment of the invention offers, and for convenience of explanation, only shows the part relevant with the embodiment of the invention.
Reference white point detects the reference white point in module 441 detected image, and adds up color temperature information according to detected with reference to white point, and as one embodiment of the present of invention, the reference white point in the image detects according to following formula:
(Y_pixel-|Cb_pixel-128|-|Cr_pixel-128|)>thr_dyn;
Wherein, Y_pixel, Cb_pixel and Cr_pixel are respectively luminance component, chroma blue component and the red color component of pixel, and thr_dyn is with reference to the white point judgment threshold.
As a preferred embodiment of the present invention, for fear of the over-exposed harmful effect that causes, whether improve the accuracy that white balance is adjusted, optimize the output effect of image, be also to filter by the noise in 4411 pairs of images of noise filtering module in reference to white point detecting each pixel.
During noise in filtering image, as one embodiment of the present of invention, need satisfy with reference to white point following one of various, perhaps following various arbitrarily " with " or " or " combination:
R_pixel<R passage threshold value;
G_pixel<G passage threshold value;
B_pixel<B passage threshold value;
Y_pixel<luminance threshold;
Wherein, R_pixel, G_pixel, B_pixel, Y_pixel are respectively R component, G component, B component and the luminance component of pixel.
In a preferred embodiment of the invention, in when the quantity counter of reference white point of accumulative total reaches first threshold N_max, then can finishing to image with reference to the detection and the statistics of white point.
The validity that color temperature information judge module 442 is judged with reference to the color temperature information of white point, as one embodiment of the present of invention, when judging the validity of color temperature information, when the second threshold value N_min<with reference to the quantity counter of white point<first threshold N_max, color temperature information with reference to white point is effective, during as the quantity counter 〉=first threshold N_max of reference white point or with reference to the quantity counter of the white point≤second threshold value N_min, color temperature information with reference to white point is invalid, when adopt when the quantity counter of reference white point totally reaches first threshold N_max, finish described in the above preferred embodiment to image in reference to the detection and the statistics of white point, then the condition that color temperature information is invalid is with reference to the quantity counter=first threshold N_max of white point or with reference to the quantity counter≤second threshold value N_min of white point.
In embodiments of the present invention, when color temperature information judge module 442 judged that color temperature information with reference to white point is invalid, 444 pairs of passing threshold adjusting modules were adjusted with reference to the white point judgment threshold, specifically adjust mode as mentioned above, repeat no more.
The effective color temperature information of color temperature information output module 443 outputs.
Fig. 6 shows the structure of the gain adjusting unit that the embodiment of the invention provides, and for convenience of explanation, only shows the part relevant with the embodiment of the invention.
RGB mean value calculation module 551 is calculated all R with reference to white point, mean value R_avg, the G_avg of G, B, B_avg according to following formula:
R_avg=Sum(R)/counter
G_avg=Sum(G)/counter
B_avg=Sum(B)/counter
Average brightness computing module 552 calculates all mean value Y_avg with reference to the brightness of white point according to following formula:
Y_avg=0.257×R_avg+0.504×G_avg+0.098×B_avg
Channel gain computing module 53 calculates R, G, gain R_gain, the G_gain of B passage, B_gain according to following formula:
R_gain=Y_avg/R_avg
G_gain=Y_avg/G_avg
B_gain=Y_avg/B_avg
RGB adjusting module 554 is adjusted R, G, B value R_new, G_new and the B_new of pixel in the image according to following formula:
R_new=R×R_gain
G_new=G×G_gain
B_new=B×B_gain。
When the embodiment of the invention is adjusted in white balance, the validity of reference white point color temperature information is assessed, carried out the white balance adjustment, can improve efficient and accuracy that white balance is adjusted at effective color temperature information.Simultaneously, the noise in the filtering image has improved the accuracy of colour temperature assessment, and then the effect of having optimized output can prevent the color spillover in the white balance adjustment process effectively, avoids the over-exposed harmful effect that causes.
The above only is preferred embodiment of the present invention, not in order to restriction the present invention, all any modifications of being done within the spirit and principles in the present invention, is equal to and replaces and improvement etc., all should be included within protection scope of the present invention.