Background technology
At present, various stylized special efficacys are applied to Online Video chat occasion, strengthen the image of entertainment effect or change oneself.Such special efficacy has had some realizations in the middle of the USB webcam driver of the MSN of Microsoft Messenger, sieve skill.Is the abstract method for cartoon, animation style of reality one of stylized system, is commonly called cartoon styleization.It has attracted to pay close attention to widely recently.
The application scenario of cartoon style system is divided into two classes, and a class is to handle the cartoon style system of static images, and another kind of is the cartoon style system that handles video.For the cartoon style system of traditional processing static images, they are very low to the requirement of real-time, so they are not suitable for video is handled in real time.And for the cartoon style system of in the past processing video, there are two problems.One is that travelling speed is still slower, is not suitable for the application that real-times such as Online Video chat are had relatively high expectations; Another is because the edge detection results of successive frame differs greatly, and causes visual effect undesirable.
As previously mentioned, because the Online Video chat is had higher requirement to the real-time of cartoon style system, therefore need carry out processing such as edge sharpening, rim detection and quantification at image and improve, thereby obtain faster speed and better visual effect.
Summary of the invention
Carry out problems such as edge sharpening, rim detection and quantification treatment in order to solve image, the object of the present invention is to provide a kind of cartoon stylization method towards online real-time application.
The technical solution used in the present invention is:
(1) utilizing iterative bidirectional filtering that image is carried out edge sharpening handles;
(2) on processing result of iterative bidirectional filtering, use the real time implementation of Gauss-Laplace method to realize carrying out rim detection, to obtain sketch effect;
(3) on processing result of iterative bidirectional filtering, quantize, to obtain oil paint effect;
(4) result with rim detection and color quantizing carries out combination, to obtain cartoon effect.
The beneficial effect that the present invention has is:
At first, improved edge detection algorithm speed is fast, and the visual effect in successive frame surpassed the edge detection method that other use fixed thresholds, such as the Canny operator.Secondly, in cataloged procedure, marginal date is separated with quantized data, thereby improved code efficiency, reduce code check.At last, based on the real-time video stylization, the present invention is suitable for the application of high real-time requirement.
In the process of video stylization, rim detection is the highest part of computation complexity.In this step, process of the present invention has adopted improving one's methods based on Gauss-Laplce.Except edge detection method faster, the present invention adopts the mode of tabling look-up to obtain filter factor and quantized value in prolonging nonlinear diffusion and color quantizing process.This processing mode can be avoided calculating Gauss equation into each pixel, thereby further accelerates the speed of whole stylizing method.
Embodiment
The present invention includes following four big steps, as shown in drawings:
(1) utilizing iterative bidirectional filtering that image is carried out edge sharpening handles;
(2) on processing result of iterative bidirectional filtering, use the real time implementation of Gauss-Laplace method to realize carrying out rim detection, to obtain sketch effect;
(3) on processing result of iterative bidirectional filtering, quantize, to obtain oil paint effect;
(4) result with rim detection and color quantizing carries out combination, to obtain cartoon effect.
Concrete steps are as follows:
In the image the higher fringe region of contrast by sharpening, and lower regional smoothed of contrast; On the one-dimensional space, bidirectional filtering can be represented with following formula:
X wherein
0Be central point p
0Ordinate or horizontal ordinate, x is the ordinate or the horizontal ordinate of point in the filter window around the central point, s is the distance of central point to the filter window edge, I (p
0) be p
0Gray-scale value, r
0Be p
0The filtering result; F (x, x
0) be p
0Bidirectional filter on every side is defined as:
f(x,x
0)=g
s(x-x
0,σ
s)·g
t(I(p)-I(p
0),σ
t)(2)
σ wherein
sAnd σ
tBe the space and the tone ratio of bidirectional filtering;
g
sAnd g
tBe important space and tone weight coefficient, be defined as by Gauss equation:
The one dimension bidirectional filtering is applied on first dimension space; Intermediate result is carried out filtering on second dimension space, can reduce computation complexity greatly like this.
Consider the parameter in formula (1) and (2), the field of definition of input parameter is:
The filter window size is set to 9 * 9; Therefore two-dimensional array of initialization has wherein been preserved all possible corresponding filtering result according to input parameter; The size of array is 4 * 256; Only need obtain in the array when then image being carried out filtering operation | x-x
0| row, the | I (p)-I (p
0) | the data of row.
2. utilize the circulation symmetry characteristic of Gauss-Laplace's equation, made the size of question blank control within the acceptable range;
Discrete Gauss-Laplce's mask is defined as:
Wherein k to make the mask coefficient and approach 0, promptly k satisfies:
Because the circulation symmetry characteristic of Gauss-Laplace's equation, the coefficient array of mask can be represented with table 1; W (i) represents Gauss-Laplce's mask numerical value; The size of this array is:
Therefore the question blank of Gauss-Laplce's mask can be expressed as:
LUT[i][j]=w(i)×j (8)
Wherein i is the position of mask, and j is the gray-scale value that will carry out the point of Gauss-Laplce's mask.The field of definition of i and j can be expressed as:
3. the conventional quantization method has been carried out the lifting on the speed.Quantizing equation is defined as:
Q wherein
ClosestBe to approach p most
0The quantification edge of gray-scale value, Δ q is a quantization width,
It is the parameter of the sharp-pointed degree in control edge;
Similar with bidirectional filtering, quantizing the unique parameter of equation is I (p
0); Field of definition is:
0≤I(p
0)≤255(11)
Therefore one-dimension array of initialization is preserved all possible quantized result; The size of this array is 256; By simply obtaining I (p in the array
0) individual value obtains a p immediately
0Quantized value.
4. 2 and 3 result is carried out combination: rim detection is the position that has the edge, and then the value of capture vegetarian refreshments is 0; Otherwise the value of capture vegetarian refreshments is color quantizing result's a value.