Disclosure of Invention
The invention aims to provide an interpolation processing method in an image processing process, so that contour recognition and smoothing processing aiming at an image can be realized, the influence of noise on the image is reduced, and the quality of the image can be effectively improved.
The purpose of the invention is realized by the following technical scheme:
the invention provides an interpolation processing method in an image processing process, which comprises the following steps:
calculating two lines of pixel component values of the color according to three lines of color pixel components to obtain five lines of pixel component values of the color;
obtaining five sets of pixel component values for the color from the five row pixel component values;
the component values in the five groups of pixel component values are subjected to pairwise difference taking and absolute value taking, and then are summed respectively to obtain a valve value;
and judging whether the pixel points are contours or not according to the threshold and the diagonal difference values in the five groups of pixel component values, if so, calculating all component values of the corresponding pixel points, and otherwise, respectively calculating the average value of the known component sum of the pixel points and respectively using the average value as all component values of the corresponding pixel points.
The method for judging whether the pixel points are outlines comprises the following steps:
and when any one of the two diagonal difference values in each group is larger than the threshold value, the pixel point is an outline, otherwise, the pixel point is not the outline.
The method for judging whether the pixel points are outlines further comprises the following steps:
and respectively recording the outline judgment results of each group aiming at the five groups of component values, judging the corresponding pixel points to be the outlines when the judgment results aiming at the current group are the outlines and at least three of the five judgment results corresponding to the five groups are the outlines, and otherwise, judging the corresponding pixel points not to be the outlines.
The color is green.
The component values include: a green G component value, a red R component value, and a blue B component value.
The interpolation processing method includes:
in three rows of known pixel points, calculating the G component value of the corresponding pixel point according to the values of all the G components, calculating the R component value of the corresponding pixel point according to the values of all the R components, and calculating the B component value of the corresponding pixel point according to the values of all the B components.
It can be seen from the above technical solutions that, in order to reduce the blurring of the contour and the influence of noise on the image, the present invention first identifies the contour, and then smoothes the part which is not the contour, so that not only can the blurring problem of the image edge caused by the normal linear interpolation method be reduced, thereby keeping the definition of the contour, but also the influence of noise on the image can be reduced, i.e. more obvious color distortion can be reduced. Thus, the implementation of the present invention can greatly improve the quality of the image, i.e., a higher quality interpolated image can be obtained.
Detailed Description
The invention provides a method for solving the problem that noise affects an image and identifies a contour, in particular provides an interpolation algorithm for realizing contour identification and smoothness, and the interpolation algorithm provided by the invention comprises the following steps: firstly, the color component with the largest effective information amount in the pixel is used for identifying the contour, and then, each mean value of three components in the pixel is calculated and determined according to the contour identification result.
Specifically, in the present invention, fifty percent of green color in a filter array of a Bayer color filter is used to identify the contour, and certainly, if the effective information amount of other colors is more, other colors may be used to identify the contour.
In summary, in the contour identification process: firstly, estimating G components of upper and lower lines through each response value of three lines of color filters, then carrying out upper and lower and left and right contour judgment on each G component, and further identifying the contour part of the G component when judging that two or more directions have contours. After the contour is identified, further interpolation is carried out on the contour part, and mean value smoothing processing is carried out on three components of the non-contour part.
That is, the present invention mainly performs the contour recognition by responding to the largest green among three colors of RGB (red, green and blue) in the implementation process. The corresponding processing procedure comprises the following steps:
(1) Firstly, estimating the G components of the upper and lower lines through each response value of three lines to obtain a 5 multiplied by 5 array;
(2) Then, in the 5 × 5 array, the vertical and horizontal contour determination is performed for each G component, and when it is determined that there is a contour in two or more directions, the G component further identifies the contour portion.
(3) After the contour is identified, further interpolation is carried out on the contour part, and smoothing processing is carried out on three components of the non-contour part.
The object of the present invention can be achieved by the above-mentioned treatments (1) to (3).
For further understanding of the present invention, a specific implementation of the interpolation processing method in the image processing process according to the present invention will be described in detail below.
As shown in fig. 1, the corresponding processing procedure specifically includes:
step 11: calculating green pixel components of five lines from the green pixel components of three lines;
as shown in fig. 2, the following parameters are first calculated:
G12=(G21+G23)/2;G14=(G23+G25)/2;
G52=(G41+G43)/2;G54=(G43+G45)/2;
the values of G12 and G14 of the first row in fig. 2 and the values of G52 and G54 of the fifth row are obtained through the above calculation, so that the G components of the five rows are estimated from the G components (G21, G23, G25, G41, G4, G45) of the middle three rows in fig. 2.
Step 12: five groups of green component values are obtained according to the five-element green components obtained through calculation, and particularly, five groups of corresponding values can be obtained in the middle, east, south, west and north directions in fig. 2;
from the 5 × 5 matrix shown in fig. 2, one can obtain: five groups of values of G23G32G43G34, G23G43G25G45, G32G34G54G52, G21G23G41G43, and G12G14G32G 34.
Step 13: calculating a threshold value for judging whether the contour is the contour or not according to the five groups of values;
and respectively subtracting every two of the four components in the five groups of values, taking absolute values, and then respectively summing the two absolute values to respectively obtain a threshold value for judging whether the value is the contour, namely facs (i), i (1: 5), which comprises the following steps:
facs(i)=fac_a*fac(i),(0≤fac_a≤1);
wherein facs (i) is a threshold value for judging whether the contour is in each group; fac _ a is a contour adjustment coefficient, typically 0.5, th is a control coefficient, and typically 16 may be taken.
Step 14: calculating the diagonal difference of each component in the five groups of component values, and calculating two diagonal difference values according to four component values in each group of components;
in the step, it is further required to determine whether the component is a contour, specifically, it is determined whether the component is a contour by subtracting the diagonal angles of each group of components in G23G32G43G3, G12G14G32G34, G23G43G25G45, G32G34G54G52, G21G23G41G 43;
step 15: determining each temp (i) value according to the calculation result of the diagonal difference;
the method specifically comprises the following steps: and judging whether a difference value larger than facs (i) exists in the result obtained by calculation, namely temp (i) =1 when one of two difference values in each group of components is larger than facs (i). Otherwise, temp (i) =0, and step 16 is performed.
Step 16: judging whether the current point is a contour or not according to each temp (i) value;
specifically, when temp (1) =1 and temp (2) + temp (3) + temp (4) + temp (5) > 2, the current point (i.e. the center point of the 5 × 5 matrix) is the contour, and step 17 is performed, otherwise, the point is not the contour, and step 18 is performed.
And step 17: calculating values of the R component, the G component and the B component according to the contour judgment result;
(1) Calculating R component
Red component R = (R31 + R33+ R35)/3;
(2) Calculating the G component
In the middle region G23G32G43G34, when the difference in absolute value of the corresponding diagonal difference is greater than facs (1), then the value of the green component G is:
otherwise, when (G23 + G32-G34-G43) > facsd, (facsd = facs (1) × m,0 < m < 1), then:
dv = | r1-r2| + | r3-r2| r1, r2, r3 are the sum of each row of the middle 3 × 3 matrix.
dh = | c1-c2| + | c3-c2| c1, c2, c3 are the sums for each column of the middle 3 × 3 matrix.
When dv > dh, then G = (G32 + G34)/2;
when dv < dh, G = (G23 + G43)/2;
when dv = dh, G = (G23 + G43+ G32+ G34)/4;
otherwise, if (G12 + G32-G34-G43) is less than or equal to facsd, G = (G23 + G43+ G32+ G34)/4;
(3) Calculating a component B;
as also shown in fig. 2, in the four small triangles G21B22G23G32, G23B 24G25G34, G41B42G43G32, G45B44G43G34 around G32 and G34,
1. when | G21-B22| is > | G23-B22| and | G23-B22| is > | G32-B22|,
tmpg22= G32, tmpg22 being an intermediate correlation quantity of G;
2. when | G21-B22| is > | G23-B22| and | G23-B22| is ≦ | G32-B22|,
tmpg22=G23;
3. when | G21-B22| ≦ | G23-B22| and | G21-B22| > | G32-B22 |;
tmpg22=G32;
4. if the conditions are not met, tmpg22= G21;
tmpg22=tmpg22-B22。
the other correlation values tmpg42, tmpg24, and tmpg44 are obtained in the same manner based on the order of arrangement of the small triangles, and thus the value of the B component can be calculated as:
B=G-(tmpg22+tmpg42+tmpg24+tmpg44)/4;
step 18: when the point is judged not to be the contour, the three components of the point are obtained by the mean value of the components of the middle 3 multiplied by 5 matrix;
for example, when temp (1) =1 and temp (2) + temp (3) + temp (4) + temp (5) > 2 are not satisfied, the point is a non-contour, G = (G21 + G23+ G25+ G32+ G34+ G41+ G43+ G45)/8, and similarly, the calculation method of the B, R component is not described again.
The following describes a specific implementation process of the method according to the present invention, with reference to fig. 3 as an example.
In fig. 3, G13= (G22 + G24)/2; g53= (G42 + G44)/2;
five sets of values were obtained from fig. 3: G22G24G42G44, G33G42G31G22, G24G35G 44G33, G33G44G53G42 and G13G24G33G22, and whether G33 is the contour is judged according to the five groups of values, wherein the specific judging method is described above and is not described in detail herein.
When the contour is judged to be the contour,
wherein G (i) is each of the intermediate 3 × 5G components; 0 < fac _ g < 64, generally 18; g _ th (j) is the correlation quantity of each G component of the middle 3 × 5; g = G33+ G _ th, G _ th being the average of all G _ th (i);
tmpg32=(G22+G31+G42+G33)/4;
tmpg34=(G24+G35+G44+G33)/4;
R=G-(tmpg32+tmpg34-R32-R34)/2;
the corresponding solution for the B component is as follows:
tmpb32=(B21+B41+B43+B23)/4;
tmpb34=(B23+B43+B45+B25)/4;
in the two surrounding small triangles G22B23G24G33 and G42B43G44G33,
1. tmpg23= G33 when | G22-B23| > | G24-B23| and | G24-B23| > | G33-B23 |;
2. tmpg23= G24 when | G22-B23| > | G24-B23| and | G24-B23| ≦ | G33-B23 |;
3. tmpg23= G33 when | G22-B23| ≦ | G24-B23| and | G22-B23| > | G33-B23 |;
4. when none of the above conditions is met, tmpg23= G22.
tmpg23=tmpg23-B23;
Obtaining tmpg43 according to the arrangement sequence of the small triangles;
tmpkb32=tmpg32-tmpb32;
tmpkb23=tmpg23-B23;
tmpkb34=tmpg34-tmpb34;
tmpkb43=tmpg43-B43;
then, B = G- (tmpkb 23+ tmpkb43+ tmpkb32+ tmpkb 34)/4.
Similarly, when the point is determined not to be a contour, the three components of the point are obtained from the mean of the components of the middle 3 × 5 matrix.
In addition, since the positions of the G components in fig. 2 and fig. 5, and fig. 3 and fig. 4 are the same, the calculation method of the G component is the same, and the calculation methods of the B component and the R component can be obtained by corresponding exchange, so that detailed description is not repeated here.
In summary, the present invention can perform denoising and interpolation operations simultaneously, thereby reducing the blurring of the image edge caused by the conventional linear interpolation method, and reducing more obvious color distortion. The method can obtain interpolation images with higher quality.
The above description is only for the preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.