Summary of the invention
For the defective that exists in the prior art, the purpose of this invention is to provide a kind of inhibition foreground color effective, simple, easy optimization and overflow and control the method for mixed brightness.
To achieve these goals, the technical solution used in the present invention is: a kind ofly suppress the method that foreground color overflows and control mixed brightness, may further comprise the steps:
(1) for the yuv space at input picture place, compression V value makes the UV space become a square space, adjusts and overflows the V value in the UV space of each pixel after compression in color, balance color and the input picture, and obtain to overflow the angle angle of color; The described color of overflowing refers to that the main color that will suppress in the image, described balance color refer to the balance look that will mix;
The described preparation method that overflows the angle angle of color is: supposes that the yuv space component value that overflows color is respectively ky, ku, kv, point (ku, kv) is designated as m to the distance of initial point,
The angle of point (ku, kv) is designated as angle, namely overflows the angle of color, angle=atan2 (kv, ku);
(2) with all pixel color of input picture and balance color in UV Space Rotating-angle angle, adjust U, the V value of all pixels of input picture and balance color;
(3) determine that according to overflowing scope and mixed edge input picture overflows the critical point in zone and adjusts coefficient, adjusts the pixel greater than critical point; The described scope of overflowing refers to the scope that the operating key edge will suppress color, and described mixed edge refers to the scope on operating key border;
The formula that described definite input picture overflows the critical point fRange in zone is fRange=umax * spill range/10+umax * blend edge/100, wherein umax represents the maximum of U in the yuv space, spill range represents the scope of overflowing, and blend edge represents mixed edge;
The formula that described definite input picture overflows the adjustment coefficient frange in zone is frange=umax * spill range;
To the method for adjusting greater than the pixel of critical point be:
When pu '>(fRange) time, pu "=(pu '-m) * (1-m
Range/10);
When pu '>(fRange) and (pu '+frange)/umax * hue * 2>1 the time, pv "=0;
When pu '>(fRange) and (pu '+frange)/umax * hue * 2<=1 the time, pv "=pv ' * (1-(pu '+frange)/umax * hue * 2).
Uout=pu″+bu′×(pu′+frange)/umax;
Vout=pv″+bv′×(pv′+frange)/umax;
When pu '>(fRange) and blend luma>0 the time, Yout=py+ (1-py) * blend luma * (pu '+frange)/2/umax+ (1-py) * blend edge * 0.005;
When pu '>(fRange) and blend luma<=0 the time, Yout=py+py * blend luma * (pu '+frange)/2/umax+py * blend edge * 0.005;
Wherein, U, the V value of pixel after pu " and pv " expression is adjusted, Uout, Vout, Yout represent to add the YUV value after the balance color, range represents the scope of overflowing, hue represents to overflow tone, blend luma represents mixed brightness, describedly overflows the skew that tone refers to control main color, and mixed brightness refers to the brightness on operating key border;
(4) with the color of all pixels in the input picture in UV Space Rotating angle angle, adjust U, the V value of all pixels after the rotation;
(5) the V value of all pixels of input picture is adjusted in UV space back-pressure is retracted former space.
Aforesaid a kind of method that foreground color overflows and control mixed brightness that suppresses, compression V value makes the UV space become a square space in the step (1), it is V=V * M/N that the formula that the V value in the UV space of each pixel after compression adopts in color and the input picture is overflowed in adjustment, V value before wherein the V on equal sign the right represents to compress, V value after the V on equal sign the right represents to compress, M is the maximum of U, and N is the maximum of V, and N is greater than M.
The formula that the U of adjustment all pixels of input picture and balance color, V value adopt in the aforesaid a kind of method that foreground color overflows and control mixed brightness that suppresses, step (2) is:
pu′=pu×cos(-angle)-pv×sin(-angle),
pv′=pu×sin(-angle)+pv×cos(-angle);
bu′=bu×cos(-angle)-bv×sin(-angle),
bv′=bu×sin(-angle)+bv×cos(-angle);
Wherein, pu, pv are U, the V value of pixel in the input picture before adjusting, and pu ', pv ' are U, the V value of pixel in the input picture after adjusting; Bu, bv are for adjusting U, the V value of forward horizontal stand color, and bu ', bv ' are for adjusting U, the V value of back balance color.
Aforesaid a kind of method that foreground color overflows and control mixed brightness that suppresses, in the step (4), first with Uout, Vout rotation angle angle, then according to formula pu " '=Uout * cos (angle)-Vout * sin (angle); pv " '=Uout * sin (angle)+Vout * cos (angle), adjust U, the V value of all pixels, wherein pu " ', pv " ' is U, the V value of pixel after adjusting.
Aforesaid a kind of method that foreground color overflows and control mixed brightness that suppresses, the former space of in the step (5) UV space back-pressure being retracted, the formula of V value employing of adjusting all pixels of input picture is V=V * N/M.
The method of the invention, by first the UV space is compressed and pixel color is rotated after again pixel is adjusted, and then return to the mode in former angle and former space, not only better to overflowing the effect that color suppresses and edge brightness is processed, and the method is simple, is very easy to optimize.
Embodiment
Describe the present invention below in conjunction with embodiment and accompanying drawing.
Fig. 1 has shown the method flow that present embodiment described inhibition foreground color overflows and control mixed brightness, mainly may further comprise the steps:
(1) at first color is then overflowed in choosing, then set overflow scope, overflow tone, balance color, mixed brightness, mixed edge.
Overflow color (spill color) and refer to the main color that will suppress in the image, overflow scope (spill range) and refer to the scope that the operating key edge will suppress color, overflow tone (spill hue) and refer to control the skew of main color, balance color (balance color) refers to the balance look that will mix, mixed brightness (blend luminance) refers to the brightness on operating key border, and mixed edge (blend edge) refers to the scope on operating key border.
(2) with the pixel value in the input picture by the BGR spatial alternation to yuv space, compression V value makes the UV space become a square space.In the UV space after compression, adjust the V value of overflowing each pixel in color, balance color and the input picture, then obtain to overflow the angle angle of color.
Compression V value can adopt formula V=V * M/N.Wherein, the V value after the V in equal sign left side represents to compress, the V value before the V on equal sign right side represents to compress; M is the maximum of U, M=0.436; N is the maximum of the front V of compression, V=0.615.Adopt the V value of overflowing each pixel in color and the input picture in the UV space after above-mentioned formula calculates compression.
With reference to Fig. 2.Suppose that the yuv space component value that overflows color is respectively ky, ku, kv, point (ku, kv) be designated as m to the distance of initial point,
The angle of point (ku, kv) is designated as angle, namely overflows the angle of color, angle=atan2 (kv, ku).
(3) with all pixel color of input picture and balance color in UV Space Rotating-angle angle, adjust U, the V value of all pixels of input picture and balance color.
With reference to Fig. 2.Suppose that each pixel P is respectively py, pu, pv (pv is the value after compressing) at the component value of yuv space in the input picture.The balance color is respectively by, bu, bv (bv is the value after compressing) at the component value of yuv space.For the ease of calculating, need to each pixel color and balance color rotation-angle angle, the definite straight line of initial point and point (ku, kv) be overlapped with the U axle.
Rotation-angle angle refers to rotate in the counterclockwise direction the angle angle take initial point as fixed point.
U, the V value of each pixel P and balance color can adopt following formula to calculate in the rear input picture of rotation:
pu′=pu×cos(-angle)-pv×sin(-angle);
pv′=pu×sin(-angle)+pv×cos(-angle)。
bu′=bu×cos(-angle)-bv×sin(-angle);
bv′=bu×sin(-angle)+bv×cos(-angle)。
Obtain the pixel (pu ', pv ') after the input picture rotation after the calculating, and postrotational balance color (bu ', bv ').
(4) determine that according to overflowing scope and mixed edge input picture overflows the critical point fRange in zone and adjusts coefficient frange, adjusts the pixel greater than critical point.
The geometric meaning of this step can be with reference to Fig. 2, at initial point and point (ku, kv) on the straight line of determining, the vertical line of this straight line is made in the position of determining according to the scope of overflowing and mixed edge, and the intersection point of straight line and vertical line is boundary Control point (being critical point fRange).It is not need the zone adjusted that boundary Control is put the determined vertical line left side, and (being the zone between two parallel vertical lines among Fig. 2) is the zone that needs adjustment to zone, the right to zone that Umax determines.
Determine to overflow regional critical point and can adopt following formula with the adjustment coefficient:
fRange=umax×spill?range/10+umax×blend?edge/100;
frange=umax×spill?range。
Wherein, umax represents that the U maximum is 0.436 in the yuv space component.
After having determined to overflow regional critical point and having adjusted coefficient, the pixel greater than critical point in the input picture is recomputated U, V, Y value according to following formula, and U, V result are added the balance color.Be not more than the pixel of critical point, i.e. pu '<=(fRange), maintenance initial value.
When pu '>(fRange) time, pu "=(pu '-m) * (1-m
Range/10);
When pu '>(fRange) and (pu '+frange)/umax * hue * 2>1 the time, pv "=0;
When pu '>(fRange) and (pu '+frange)/umax * hue * 2<=1 the time, pv "=pv ' * (1-(pu '+frange)/umax * hue * 2).
Uout=pu″+bu′×(pu′+frange)/umax;
Vout=pv″+bv′×(pv′+frange)/umax;
When pu '>(fRange) and blend luma>0 the time, Yout=py+ (1-py) * blend luma * (pu '+frange)/2/umax+ (1-py) * blend edge * 0.005;
When pu '>(fRange) and blend luma<=0 the time, Yout=py+py * blend luma * (pu '+frange)/2/umax+py * blend edge * 0.005.
In the above-mentioned formula, U, the V value of each pixel after recomputating in pu " and pv " the expression input picture, Uout, Vout, Yout represent to add the YUV value after the balance color, range represents the scope of overflowing, hue represents to overflow tone, and blend luma represents mixed brightness.
(5) color that will adjust rear pixel is namely rotated the angle angle to counter clockwise direction in UV Space Rotating angle angle, adjusts U, the V value of pixel; And make the UV space revert to original rectangular space the V value back-pressure contracting, adjust the V value of pixel.
First Uout, Vout rotation angle angle is got back under the former coordinate system, adjust U, the V value of pixel according to following formula, pu " '=Uout * cos (angle)-Vout * sin (angle), pv " '=Uout * sin (angle)+Vout * cos (angle).Then with the contracting of V value back-pressure, even V=V * N/M.Pv before the V on equal sign the right represents to compress herein " ', the pv after the V on the equal sign left side represents to compress herein " '.
(6) at last with Yout, pu " ', pv " ' change back to the BGR space, obtain final image.
In order to improve the implementation efficiency of said method, preferably adopt the SIMD of intel to strengthen instruction set SSE2.Because can carrying out the vector of integer or floating-point, calculates SSE2, so can calculate simultaneously the value of a plurality of pixels.In addition because the SSE2 instruction is easy to realize mask calculates so that when the calculating pixel value without any conditional branch statements, thereby also improved speed.
Result of the test shows: be on the processor of 2.5GHz a dominant frequency, the pixel value that calculates a width of cloth 720x576 sized images (BGRA space) only needs 4.5ms.If recycling multinuclear or Hyper-Threading will calculate mean allocation above each is examined or on the hardware thread, then the CPU of one four nuclear processes above-mentioned image only needs about 1.5ms.
The present invention is not limited to above-mentioned embodiment, and other execution modes that those skilled in the art's technical scheme according to the present invention draws belong to technological innovation scope of the present invention equally.