Background technology
In existing various imaging devices, the overwhelming majority adopts the CFA imageing sensor.Each sensitive component in such CCD or the cmos sensor can only be gathered a certain components of pixel color, and in the whole sensor dot matrix, each point has only a photoreceptor, that is to say for each pixel to collect a color component, and other two components will be lost.Therefore, two components that must provide a kind of method to refill to lose make each output pixel all have redness (R), green (G), blue (B) component output.
At present, a kind of fairly simple method is arranged, the mean value of respective color component calculates current damaged component around promptly adopting.
As shown in Figure 1, calculate green and the blue component lost the R33 position, adopt 5 * 5 zone calculating, then computing formula is:
(1)
For the entire image data, adopt corresponding method to calculate all damaged data.
Adopt this method,, will cause image to produce serious edge noise, be unfavorable for subsequent treatment dateout because the value of the value of fringe region and non-fringe region interacts.
And another improved bilinear interpolation (Bilinear Interpolation) method then is to adopt gradient to judge the color component that comes adaptometer damaged.
To at red component location of pixels interpolation green component, the formula below adopting calculates:
α is the correction coefficient of current gradient,
Be the mean value of the green component around the current location, Δ
R(i, j) be r (formula calculates below adopting for i, the j) Grad of present position:
(m,n)={(0,-2),(0,2),(-2,0),(2,0)}
(m,n)={(0,-1),(0,1),(-1,0),(1,0)}
To at blue component location of pixels interpolation green component, adopt said method too.
To at green component location of pixels interpolation red component, adopt following method:
Δ
G(i j) adopts (3) calculating by formula of nine points, sees Fig. 2.
To at blue component location of pixels interpolation red component, adopt following method:
Δ as shown in Figure 2
B(i j) adopts (3) calculating by formula of five points.
And, calculate (see figure 2) according to calculating damaged red component for calculating damaged blue component.
And for the choosing of α, β, three coefficients of γ, then be before the computing with handle after the mean square deviation (Mean Square Error (MSE)) of two width of cloth images.Making α, β, the γ value of MSE minimum is optimum value.Having provided one group of optimum value in the method is α=1/2, β=5/8, γ=3/4.Bring above-mentioned parameter into above-mentioned formula, be converted to the matrix form (see figure 2), the design factor of this color component of numeral in the color block.
Though this method has reduced the value of fringe region and the interactional influence of value of non-fringe region, has reduced edge noise.But owing to adopt the mode that compares MSE to calculate α, β, three coefficients of γ, the picture after feasible the processing is near original image, so also do not play the effect of edge sharpening.
Summary of the invention
The objective of the invention is to provide a kind of and can eliminate the edge noise that color interpolation brings, can increase the edge crispening color interpolation method based on gradient of edge sharpening effect again.
To achieve these goals, a kind of edge crispening color interpolation method based on gradient provided by the invention may further comprise the steps:
(1), set Grads threshold, make its span be [0,255];
(2), all damaged green components are carried out interpolation: obtain to want the level and the vertical gradient of interpolation point correspondence position, if two gradients all greater than step (1) threshold value, then strengthen obtaining damaged green component by the edge; If at least one Grad is then pressed corresponding mean value method interpolation less than threshold value;
(3), be that non-green component carries out the respective color interpolation to current point: obtain two diagonal gradients of current some correspondence position, if two gradients all greater than step (1) threshold value, then strengthen obtaining respective component by the edge; If at least one Grad is then pressed corresponding mean value method interpolation less than threshold value;
(4), be that green component carries out redness and blue component interpolation to current point: obtain the level and the vertical gradient of current some correspondence position, if two gradients all greater than step (1) threshold value, then strengthen obtaining respective component by the edge; If at least one Grad is then pressed corresponding mean value method interpolation less than threshold value.
Step of the present invention (2) is if two gradients all less than threshold value, then adopt two gradient counterparties to obtain damaged green component to mean value; If have only a gradient less than threshold value, then adopt the little gradient counterparty of relative value to mean value obtain damaged green component.
Step of the present invention (2) strengthens by the edge and obtains damaged green component and be: according to the magnitude relationship of level and vertical gradient respectively by horizontal gradient greater than, be equal to or less than three kinds of situations of vertical gradient and obtain green component.
At least one Grad of step of the present invention (3) is less than under the threshold value situation, adopt the little counterparty of gradient institute of relative value to mean value obtain its color component.
Step of the present invention (3) if two gradients all greater than threshold value, are obtained the color component process by the edge enhancing is:
Wherein, and C (i j) represents current i, the primitive color component of j position, and (i j) represents current i, the green component of j position to G.
At least one Grad of step of the present invention (4) is less than under the threshold value situation, the counterparty of gradient institute that wherein relative value is little to color component obtain with its direction mean value, another color component is then used to strengthen by its edge and is obtained.
Step of the present invention (4) if two gradients all greater than threshold value, are obtained the color component process by the edge enhancing is:
Wherein, B (i, j), R (i, j) and G (i j) represents current i respectively, the blueness of j position, redness and green component, (i j) represents current i to C, the primitive color component of j position.
The present invention calculates the gradient of four direction by utilizing existing color component value, and compares with the Grads threshold that sets in advance, judges whether current location is in the edge.If be in the edge, then the gradient of the four direction by current location relation is carried out respective edges and is strengthened, and can not introduce noise; Otherwise, then adopt the method for average color interpolation to carry out interpolation, help removing the power supply noise of the transducer generation of non-border district in the image.
Embodiment
Adopt to judge among the present invention that vertical, level and positive and negative diagonal four direction judge the gradient direction of current pixel position.Set Grads threshold Thre, same excessively relatively greatest gradient value of four direction and the magnitude relationship of Thre judge whether current point is boundary point, carrying out the edge thus strengthens, stipulate that in the present invention the Thre span is [0,255], when the Grad of current location during greater than Thre, can determine that then current location is in marginal position, carry out the edge by corresponding calculated and strengthen.
As shown in Figure 3, the present invention mainly may further comprise the steps:
(1), set Grads threshold, make its span be [0,255];
(2), as shown in Figure 4, all damaged green components are carried out interpolation: obtain to want the level and the vertical gradient of interpolation point correspondence position, if at least one Grad is then pressed corresponding mean value method interpolation less than step (1) threshold value.Wherein, if two gradients all less than threshold value, then adopt two gradient counterparties to obtain damaged green component to mean value; If have only a gradient less than threshold value, then adopt the little gradient counterparty of relative value to mean value obtain damaged green component.And when two gradients all greater than threshold value, then according to the magnitude relationship of level and vertical gradient respectively by horizontal gradient greater than, be equal to or less than three kinds of situations of vertical gradient, strengthen obtaining damaged green component successively by the edge:
As HG>VG
As HG<VG
Work as HG=VG
Wherein, and G (i, j) current i, the green component of j position, C (i j) represents current i, the primitive color component of j position, and HG and VG represent level and vertical gradient respectively.
(3), as shown in Figure 5, to current point is that non-green component carries out the respective color interpolation: the two diagonal gradients that obtain current some correspondence position, if at least one Grad is less than step (1) threshold value, then adopt the little counterparty of gradient institute of relative value to mean value obtain its color component:
Work as NEG=minG, adopt the value on the 45 degree directions to calculate its color component,
Work as NWG=minG, adopt the value on-45 degree directions to calculate its color component (minG is the minimum value of two diagonal gradient NEG, NWG); If two gradients all greater than threshold value, then strengthen obtaining respective component by the edge:
Wherein, (i j) represents current i to C, the primitive color component of j position, G (i, j) current i, the green component of j position.
(4), be that green component carries out redness and blue component interpolation: the level and the vertical gradient that obtain current some correspondence position to current point, if at least one Grad less than step (1) the threshold value counterparty of gradient institute that then wherein relative value is little to color component obtain with its direction mean value, another color component is then used to strengthen by its edge and is obtained:
minG=min(HG,VG)
When minG<Thre:
minG=HG
Other
Wherein, HG and VG are respectively level and vertical gradient, and Thre is a threshold value.
If two gradients all greater than step (1) threshold value, then strengthen obtaining respective component by the edge:
Wherein, and B (i, j) current i, the blue component of j position, R (i, j) current i, the red component of j position, (i j) represents current i to C, the primitive color component of j position.
Wherein, level, vertical and two diagonal gradient calculation are followed successively by:
HG=|2×C(i,j)-C(i,j-2)-C(i,j+2)|+|C(i,j+1)-C(i,j-1)|
VG=|2×C(i,j)-C(i+2,j)-C(i-2,j)|+|C(i+1,j)-C(i-1,j)|
NEG=|2×C(i,j)-C(i+2,j-2)-C(i-2,j+2)|+|C(i+1,j-1)-C(i-1,j+1)|
NWG=|2×C(i,j)-C(i+2,j+2)-C(i-2,j-2)|+|C(i+1,j+1)-C(i-1,j-1)|
Following example be detailed process by implementation process, be example with the B44 position among Fig. 1, at first calculate the green component values G44 of blue component position, its step is as follows:
(1) horizontal gradient (HG) and vertical gradient (VG) of calculating correspondence position.
HG=|2×B44-B42-B46|+|G45-G43|
VG=|2×B44-B64-B24|+|G54-G34|
(2), calculate current green component according to gradient magnitude.
(a) if HG<Thre and VG<Thre set up simultaneously;
(b) if HG<Thre sets up;
(c) if VG<Thre sets up;
(d) other but do not belong to above-mentioned three kinds of conditions;
As HG>VG
As HG<VG
Work as HG==VG
Wherein, adopt to use the same method and to calculate the green component values of red component position.
Then, calculate the red color component value of blue component position.Calculate R44, the value of the G44 that needs use previous step calculates, its step is as follows:
(1) calculates cornerwise gradient NEG, NWG and minimum value minG.
NEG=|2×B44-B62-B26|+|R53-R35|
NWG=|2×B44-B66-B22|+|R55-R33|
min?G=min(NEG,NWG)
(2), calculate the value of R44 according to gradient magnitude.
(a) if minG<Thre sets up;
Work as minG==NEG
Other
(b) other but do not belong to above-mentioned condition.
Wherein, the blue component value that adopting uses the same method can calculate the red component position is such as B33.
At last, calculate damaged red component and the blue component in green component position.With G43 is example, calculates B43 and R43, and its step is as follows:
(1) the gradient VG of the gradient HG of calculated level direction, vertical direction and minimum value minG.
HG=|2×G43-G41-G45|+|B44-B42|
VG=|2×G43-G23-G63|+|R53-R33|
minG=min(HG,VG)
(2) calculate corresponding value according to gradient magnitude.
(a) if minG<Thre sets up;
When minG==HG:
Other:
(b) other but do not belong to above-mentioned condition.