Summary of the invention
In view of this, the embodiment of the invention proposes a kind of portrait buffing method and device at digital photograph, can realize portrait buffing by operating in a key.
A kind of portrait buffing method that the embodiment of the invention proposes comprises the steps:
Choose the skin area of portrait in the original image;
The replicating original image obtains an intermediate images; Described intermediate images is carried out medium filtering, described medium filtering is specially: the picture element matrix of choosing N * N from intermediate images, with each position pixel value size ordering in this picture element matrix, with the position at the value of centre pixel value as this picture element matrix center;
In selected skin area, the pixel value of original image and the pixel value of the intermediate images behind the medium filtering are merged, obtain final image; Described pixel value merges and is specially: set the transparency t of intermediate images, for the coordinate in the skin area (i, j), the pixel value of this coordinate is bmp1 (i in the intermediate images, j), in the original image pixel value of this coordinate be bmp0 (i, j), according to formula result (i, j)=[bmp0 (i, j) * (1-t/100)+bmp1 (i, j) * t/100] calculating merging back coordinate (i, pixel value result j) (i, j).
A kind of portrait buffing device that the embodiment of the invention proposes comprises:
Skin area is chosen module, is used for choosing the skin area of original image portrait;
Mill skin processing module, be used for the replicating original image and obtain intermediate images, intermediate images is carried out medium filtering, described medium filtering is specially: the picture element matrix of choosing N * N from intermediate images, with each position pixel value size ordering in this picture element matrix, with the position at the value of centre pixel value as this picture element matrix center;
Merge output module, be used in skin area is chosen the selected skin area of module, the pixel value of the intermediate images behind the medium filtering that mill skin processing module is obtained and the pixel value merging of original image obtain final image; Described pixel value merges and is specially: set the transparency t of intermediate images, for skin area choose coordinate in the determined skin area of module (i, i), the pixel value of this coordinate is bmp1 (i in the intermediate images behind the medium filtering, j), in the original image pixel value of this coordinate be bmp0 (i, j), according to formula result (i, j)=[bmp0 (i, j) * (1-t/100)+bmp1 (i, j) * t/100] calculating merging back coordinate (i, pixel value result j) (i, j); And output unit, be used for after processing is finished in the joint account unit, the result being exported.
As can be seen from the above technical solutions, according to the skin area of choosing; Original image duplicated obtain intermediate images, intermediate images is carried out the mill skin that medium filtering is equivalent to realize the full figure scope; Again the pixel value of the intermediate images behind the medium filtering in the skin area scope and the pixel value of original image are merged, thereby realize only handling grinding skin in the skin area scope.In the scheme of the embodiment of the invention, the user only needs a key operation just can realize special processing to the portrait photo of shooting, and does not influence image quality, farthest for the user has saved time and expense, and also satisfactory for result.
Embodiment
For making the purpose, technical solutions and advantages of the present invention clearer, the present invention is further elaborated below in conjunction with accompanying drawing.
The realization flow of the portrait buffing that the embodiment of the invention proposes comprises the steps: as shown in Figure 1
Step 101:, choose the skin area of portrait based on the pixel value of click place.
This step can be divided into for two steps, the first step, primary election skin area; In second step, on the basis of the skin area of first step primary election, further determine the edge of skin area.
The specific practice of described primary election skin area can be: the pixel value that mouse is clicked is as basic pixel value, arbitrary coordinate (i in the computed image, j) the pixel value and the difference of basic pixel value, if difference is less than pre-set threshold, then think coordinate (i, j) pixel of locating belongs to skin area, otherwise coordinate (i, the pixel of j) locating does not belong to skin area.
Pixel value has a plurality of components usually, for example the pixel value of RGB pattern comprises red (Red), green (Green), blue (Blue) three components, above-mentioned difference can be these three differences that component calculates respectively, again with three differences respectively with three threshold ratios that set in advance, if the difference of each component is all then thought coordinate (i less than threshold value, j) pixel of locating belongs to skin area, if the difference that any one component arranged greater than threshold value coordinate (i, the pixel of j) locating does not belong to skin area.
In some cases, above-mentioned way may also be thought skin area to the pixel close with application on human skin of color in the image, therefore can add a qualifications again, and the pixel of skin area must directly or indirectly be communicated with the pixel of click place.Specific practice comprises:
Step a: the pixel of click place is made as pixel in the skin area.
Step b: the pixel of search and skin area direct neighbor, the pixel that calculating searches and the difference of basic pixel value; Difference is made as pixel in the skin area less than the pairing pixel of pre-set threshold;
Step c: judge whether to finish search, if then finish the process of choosing of skin area, otherwise return step b to the pixel of skin area direct neighbor.
After the primary election of having finished skin area, just can carry out the second step operation, spatial filtering is carried out in the marginal portion of skin area, the image at skin area edge is described specially, and with this image also as skin area.The purpose of second step operation is that edge parts such as canthus, the corners of the mouth also are divided in the skin area, and these parts are not handled by the mill skin.When less demanding, also can omit this operation to result.
Described spatial filtering just is to use Laplce's matrix, is enclosed within to carry out weighting matrix calculating on the original image.
Be the example of Laplce's matrix of one 5 * 5 below:
The matrix of above-mentioned laplace transform, the core value is 15, is-2 on every side.Just emphasizing pixel own and the difference of different pixels on every side.Can isolate the edge by different colours like this.In the practical application, each operator of Laplce's matrix also can be got other value, as long as can satisfy the requirement of isolating the edge.
With the pixel in the preset range around the edge pixel of primary election skin area all as alternative area.
For alternative area internal coordinate value is (i, pixel X j)
I, j, this pixel and adjacent and inferior adjacent pixel are formed one 5 * 5 matrix:
Each operator of matrix (1) and the pixel of matrix (2) correspondence position are multiplied each other, and with the summation that adds up again of gained product, with gained with again divided by the operator sum of matrix (1), (i j) locates value behind the spatial filtering just to obtain coordinate.
All pixels in the alternative area are all carried out after spatial filtering handles, and the image of alternative area can be described the border of skin area more accurately.
Step 102: the replicating original image obtains an intermediate images.
Step 103: intermediate images is carried out medium filtering.
Medium filtering is to all grey scale pixel value orderings in the moving window; the original gray-scale value that replaces the window center pixel with its intermediate value; it is a kind of nonlinear image smoothing method; its paired pulses interference level Noise Suppression is effective, can effectively protect the edge to be blured less when suppressing random noise.
Below by object lesson medium filtering is described.
Suppose from original image, to choose a size and be 3 * 3 picture element matrix:
Calculating the value of this matrix center now, is exactly with this position and the ordering of pixel value on every side thereof.Definition on every side, it is fixed to come according to moving window size, only comprises the pixel with its direct neighbor in this example, and then the moving window size is 3 * 3.Ranking results is as follows: 1,2,2,3,4,5,6,7,7.Find the value 4 of position in the centre.Then will be made as 4 with the pixel value of this matrix center position coordinates in the intermediate images.
Each pixel in the intermediate images is carried out aforementioned calculation successively, just obtain the intermediate images behind the medium filtering.
The size of moving window also can be taken as 5 * 5, then needs to consider and center pixel direct neighbor and inferior adjacent pixels.Needing the size of the image array of consideration also is 5 * 5.Medium filtering process in this case and above-mentioned 3 * 3 situation are similar, so repeat no more.
Step 104: in selected skin area, the pixel of intermediate images and the pixel of original image respective coordinates position are merged, obtain final image.
Described merging can be in the following way:
Set the transparency t of figure layer 1, for the coordinate in the skin area (i, j), in the intermediate images behind the medium filtering pixel value of this coordinate be bmp1 (i, j), the pixel value of this coordinate is bmp0 (i in the original image, j), coordinate after then merging (i, pixel value j) is:
result(i,j)=[bmp0(i,j)×(1-t/100)+bmp1(i,j)×t/100]
As a kind of preferred implementation, the described skin area of choosing is realized with the following method:
Newly-built one is covered plate figure layer on original image, and then original image is a Background From Layer;
Determine to cover the pixel corresponding, i.e. coordinate those pixels identical in the plate figure layer with the coordinate of skin area pixel with the skin area of Background From Layer;
The pixel value that covers the definite pixel of institute in the plate figure layer is made as constant value C 1, covers the pixel value that is left pixel in the plate figure layer and be set to constant value C 2.C1 can be taken as (#000000), shows as black region; C2 can be taken as (#FFFFFF), shows as white portion.In the practical application, C1 and C2 also can be taken as other predefined value.
Like this, see that all pixels have been divided into two parts in covering plate figure layer, the part of black is represented skin area, and the part of white is represented non-skin area, so just can choose skin area easily.
The embodiment of the invention has also proposed a kind of portrait buffing device, as shown in Figure 2, comprising:
Skin area is chosen module 210, is used for the pixel value based on click place, chooses the skin area of portrait in the original image;
Mill skin processing module 220 is used for the replicating original image and obtains intermediate images, and intermediate images is carried out medium filtering;
Merge output module 230, be used in skin area is chosen the selected skin area of module 210, the pixel of the intermediate images that mill skin processing module 220 is obtained and the pixel merging of original image respective coordinates position obtain final image.
Described skin area is chosen module 210 and is comprised: skin area primary election unit 211 and edge determining unit 212,
The pixel value that skin area primary election unit 211 is used for mouse is clicked is as basic pixel value, arbitrary coordinate (i in the computed image, j) the pixel value and the difference of basic pixel value, if difference is less than pre-set threshold, then think coordinate (i, j) pixel of locating belongs to skin area, otherwise coordinate (i, the pixel of j) locating does not belong to skin area;
Perhaps, described skin area primary election unit 211 is used for the pixel of click place is made as the pixel of skin area; The pixel of search and skin area direct neighbor, the pixel that calculating searches and the difference of basic pixel value; Difference is made as pixel in the skin area less than the pairing pixel of pre-set threshold;
Described edge determining unit 212 is used for the basis of the skin area definite in skin area primary election unit, determines the edge of skin area.
Described skin area is chosen module 210 and is comprised illiteracy plate figure layer processing unit 213, and described illiteracy plate figure layer processing unit 212 is used for a newly-built illiteracy plate figure layer on original image; Determine to cover the pixel corresponding, i.e. coordinate those pixels identical in the plate figure layer with the coordinate of skin area pixel with the skin area of original image; The pixel value that covers the definite pixel of institute in the plate figure layer is made as constant value C 1, covers the pixel value that is left pixel in the plate figure layer and be set to constant value C 2; Preferably, constant value C 1 is (#000000), shows as black region; C2 can be taken as (#FFFFFF), shows as white portion.
Then described edge determining unit 212 is used for spatial filtering is carried out in the marginal portion of covering plate figure layer skin area, specifically comprises: will cover the pixel of preset range interior pixel in plate figure layer skin area edge as alternative area; For alternative area internal coordinate value is (i, pixel X j)
I, j, be the pixel matrix of M * M with this pixel and the composition of pixel on every side size, described M is a natural number; With each element in this pixel matrix and predetermined size is that the operator of Laplce's matrix correspondence position of M * M multiplies each other respectively, with the summation that adds up again of gained product, gained and again divided by the operator sum of described Laplce's matrix, (i j) locates value behind the spatial filtering to obtain coordinate.
Preferably, described mill skin processing module 220 comprises:
Picture element matrix is chosen unit 221, is used for handling the picture element matrix that preceding pixel is chosen N * N from intermediate images;
Sequencing unit 222 is used for picture element matrix is chosen each position pixel value size ordering of picture element matrix of the selected N * N in unit 221, with the position at the value of centre pixel value as this picture element matrix center.
Described merging output module 230 comprises:
Joint account unit 231 is used to set the transparency t of intermediate images, chooses coordinate (i in the determined skin area of module for skin area, j), in the intermediate images behind the medium filtering pixel value of this coordinate be bmp1 (i, j), the pixel value of this coordinate is bmp0 (i in the original image, j), according to formula result (i, j)=[bmp0 (i, j) * (1-t/100)+bmp1 (i, j) * t/100] calculating merging back coordinate (i, and pixel value result j) (i, j);
Output unit 232 is used for after processing is finished in the joint account unit result being exported.
In the embodiment of the invention scheme, the user only needs a key operation just can realize special processing to the portrait photo of shooting, and does not influence image quality, has farthest saved time and expense for the user.And it is satisfactory for result.
Through the above description of the embodiments, those skilled in the art can be well understood to the present invention and can realize by the mode that software adds essential hardware platform, can certainly all implement, but the former is better embodiment under a lot of situation by hardware.Based on such understanding, all or part of can the embodying that technical scheme of the present invention contributes to background technology with the form of software product, this computer software product can be stored in the storage medium, as ROM/RAM, magnetic disc, CD etc., comprise that some instructions are with so that a computer equipment (can be personal computer, intelligent terminal or digital camera etc.) is carried out the described method of some part of each embodiment of the present invention or embodiment.
The above only is preferred embodiment of the present invention, not in order to restriction the present invention, all any modifications of being done within the spirit and principles in the present invention, is equal to and replaces and improvement etc., all should be included within protection scope of the present invention.