Content of the invention
Disadvantages described above or Improvement requirement for prior art, the invention provides a kind of coloured image side of focusing automatically
Method, its object is to both make full use of image color information, can realize fast automatic focusing again.Technical side proposed by the present invention
Case is as follows:
A kind of coloured image auto focusing method, it is characterised in that methods described includes following step:
(1) original image of rgb format is input into, red-green antagonism figure I is calculated respectivelyrgWith blue-yellow antagonism figure Iby;
(2) obtain and focus on sampled point;
Original image is divided into three class focus windows first:Center window, four side window mouths and corner window;
To the red-green antagonism figure I in different focus windowsrgWith blue-yellow antagonism figure IbySet different sampling policies:
In the window of center, pixel carries out fully sampled, and in four side window mouths, pixel carries out horizontal dot interlace sampling, in the window of corner pixel laterally and
Longitudinal direction carries out dot interlace sampling respectively;Respectively obtain after sampling and red-green antagonism figure IrgCorresponding sampled point chained list first Lrg, and blue-
Yellow antagonism figure IbyCorresponding sampled point chained list second Lby, described sampled point chained list first Lrg, sampled point chained list second LbyIn have recorded poly-
The picture element position information of burnt sampled point;
(3) red-green antagonism figure I is calculated respectively using improved Brenner functionsrgFocus on the functional value of sampled point with blue-
Yellow antagonism figure IbyFocus on the functional value F of sampled pointMBrenner, all functional value sums of the statistics more than given threshold value T, by this
Statistical value evaluates the definition of coloured image.
The concrete calculating process of described step (1) is as follows:
Irg=R-G
Iby=B-Y
Wherein,
Y=(R+G)/2
R, G, B are respectively three Color Channels of red, green, blue of input color image.
In step (2):4 adjacent subgraphs of original image central point constitute center window Wa;Original image corner
4 subgraphs constitute corner window Wc;In original image, corner window Wc, center window WaPart in addition constitutes four side window mouths
Wb.
Improvement Brenner function computing formula in step (3) are as follows:
Wherein, Lc.length it is sampled point chained list LcLength,
MBc(i)=| Ic(Lc[i] .x+2, Lc[i].y)-Ic(Lc[i] .x, Lc[i].y)|×
|Ic(Lc[i] .x, Lc[i].y+2)-Ic(Lc[i] .x, Lc[i] .y) | c=rg, by
Wherein, (Lc[i] .x, Lc[i] .y) it is sampled point chained list LcIn i-th element location of pixels.
What the present invention can reach has the beneficial effect that:
Very high due to focusing on automatically the requirement to real-time, in the design of substantial amounts of sharpness evaluation function, in order to subtract
Few amount of calculation and lose colouring information so that under some specific occasions cannot exact evaluation coloured image definition.And this
The method of bright proposition allows the color characteristic of image to maximize the use on the premise of amount of calculation is not increased, to coloured image
The evaluation result of definition is more accurate.
Specific embodiment
In order that the objects, technical solutions and advantages of the present invention become more apparent, below in conjunction with drawings and Examples, right
The present invention is further elaborated.
Step one, calculates red-green antagonism figure, blue-yellow antagonism figure:
(1.1) original image of RGB patterns is input into, and its width is calculated as W, and which is highly designated as H;Original image is decomposed into red
(R), green (G) and blue (B) three color channel images;
(1.2) yellow (Y) channel image is obtained using red, green two color channel images;
Y=(R+G)/2
(1.3) red-green antagonism figure I is calculated using R, G, B, YrgWith blue-yellow antagonism figure Iby;
Irg=R-G
Iby=B-Y
Step 2, samples to the pixel position of original image formed objects, builds sampled point chained list first L respectivelyrg
With sampled point chained list second Lby.Sampled point chained list first LrgFollow-up red-green antagonism figure I will be used forrgDefinition calculating, sampled point
Chained list second LbyBlue-yellow antagonism figure I will be used forbyDefinition calculating.The purpose for building sampled point chained list is have by extraction
The representational amount of calculation for focusing on the follow-up sharpness evaluation function of sampled point minimizing.Red-green antagonism figure IrgWith blue-yellow antagonism figure
IbyThe respective selection principle for focusing on sampled point is the locations complementary for making two sampled point chained lists as far as possible, is reducing amount of calculation
Simultaneously as far as possible fully using the colouring information of entire image.Concrete steps include:
(2.1) original image of input is divided into 16 subgraphs by size, each subgraph size is W/4 × H/4;
(2.2) as shown in Fig. 2 16 subgraphs are divided three classes focus window:Center window Wa, four side window mouth WbAnd
Corner window Wc;
4 adjacent subgraphs of original image central point constitute center window Wa;
4 subgraphs of original image corner constitute corner window Wc;
In original image, corner window Wc, center window WaPart in addition constitutes four side window mouth Wb.
(2.3) records center window WaThe position (x, y) of each pixel interior, adds sampled point chained list first LrgIn;In record
Heart window WaThe position of each pixel interior, adds sampled point chained list second LbyIn;
(2.4) to four side window mouth WbInterior pixel carries out horizontal dot interlace sampling, specifically, records four side window mouth W line by lineb
The position (x, y) of interior odd bits pixel, and it is added into sampled point chained list first LrgIn;Four side window mouth Ws are recorded line by linebInterior
The position (x, y) of even bit pixel, and it is added into sampled point chained list second LbyIn;
(2.5) to corner window WcInterior pixel carries out 2 times of down-samplings, i.e., horizontal and vertical carry out dot interlace sampling respectively,
And sampled pixel position is added sampled point chained list first LrgOr sampled point chained list second LbyIn.
Specifically, by corner window WcSome subwindows, the left side in the subwindow are divided into respectively according to 2 × 2 pixels
The position (x, y) of upper angle pixel adds sampled point chained list first LrgIn, the position (x, y) of the lower right corner pixel in the subwindow adds
Enter sampled point chained list second LbyIn.
Due to being located at field of view center subject goal more, therefore center window WaThe sample rate highest of interior pixel;Meanwhile, taking the photograph
In shadow composition, the effect of golden section point is most important, therefore, center window WaSize arrange cause golden section point lucky
It is located therein.Relative to center window Wa, four side window mouth WbWith corner window WcInterior nontarget area is increased, therefore, this two class
The sample rate of window is relatively low.It is 9/8 × W that the setting of focus window and sampling policy causes the length sum of two sampled point chained lists
× H, slightly larger than original image size.
Step 3, using all sharpness evaluation function values for focusing on sampled point (x, y) of improved Brenner functions statistics
Summation FMBrenner:
(3.1) red-green antagonism figure I is counted using improved Brenner function formulasrgBelong to sampled point chained list first in figure
LrgIn each pixel functional value and blue-yellow antagonism figure IbyInside belong to sampled point chained list second LbyIn each pixel function
Value:
MBc(i)=| Ic(Lc[i] .x+2, Lc[i].y)-Ic(Lc[i] .x, Lc[i].y)|×
|Ic(Lc[i] .x, Lc[i].y+2)-Ic(Lc[i] .x, Lc[i] .y) | c=rg, by
Wherein, (Lc[i] .x, Lc[i] .y) it is sampled point chained list LcIn i-th element location of pixels.
Improved Brenner functions not only allow for the gray scale difference that horizontal direction differs the pixel of two units, it is also contemplated that
Vertical direction differs the gray scale difference of the pixel of two units, can more comprehensively reflect the partial gradient change of entire image, meanwhile,
Original Brenner functions excessively do not increase amount of calculation relatively.
(3.2) all functional value F more than given threshold value T are countedMBrennerSum, as input color image clear
Degree.
Wherein, Lc.length it is sampled point chained list LcLength.
The corresponding program of this method can in embedded images collecting device, in operation process, by contrast result of calculation several times,
Select highest statistical value, you can real-time selection best focus scheme.
Coloured image auto focusing method provided by the present invention, makes full use of the colouring information of coloured image first, keeps away
The loss of caused color detail when having exempted from only to go to evaluate definition using gray-scale maps;Secondly, consider subject goal multidigit
In the importance of the characteristic and golden section point of field of view center, reduce the amount of calculation that increases because of statistical color information and
The negative effect of nontarget area, is effectively improved real-time and the accuracy of focusing;Finally, by improving Brenner letters
Number, on the premise of amount of calculation is not increased, more comprehensively reflects the definition of entire image.