CN108198128B - Method and device for alpha channel boundary corrosion - Google Patents

Method and device for alpha channel boundary corrosion Download PDF

Info

Publication number
CN108198128B
CN108198128B CN201711319709.8A CN201711319709A CN108198128B CN 108198128 B CN108198128 B CN 108198128B CN 201711319709 A CN201711319709 A CN 201711319709A CN 108198128 B CN108198128 B CN 108198128B
Authority
CN
China
Prior art keywords
convolution
alpha
dimensional
channel image
pixel point
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201711319709.8A
Other languages
Chinese (zh)
Other versions
CN108198128A (en
Inventor
见良
郑鹏程
陶颖
刘铁华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Meishe Network Technology Co ltd
Original Assignee
Beijing Meishe Network Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Meishe Network Technology Co ltd filed Critical Beijing Meishe Network Technology Co ltd
Priority to CN201711319709.8A priority Critical patent/CN108198128B/en
Publication of CN108198128A publication Critical patent/CN108198128A/en
Application granted granted Critical
Publication of CN108198128B publication Critical patent/CN108198128B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • G06T3/18

Abstract

The invention relates to the field of image processing, in particular to a method and a device for alpha channel boundary corrosion; the method comprises the following steps: acquiring an alpha channel image of a target image; the alpha channel image comprises alpha values of all pixel points; performing one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point of the alpha channel image according to a preset convolution kernel and a preset convolution kernel radius; carrying out matting processing on the target image according to the alpha value of each pixel point of the alpha channel image after the convolution processing; wherein the convolution kernel
Figure DDA0001504514120000011
Sigma is a preset value, and sigma is more than or equal to 0 and less than or equal to 1; and p is the horizontal relative coordinate or the vertical relative coordinate of the pixel point participating in the convolution and the pixel point of the target convolution. In the embodiment of the invention, when the convolved alpha channel image is applied to the matting processing of the target image, the method has the effect of boundary corrosion; meanwhile, compared with two-dimensional convolution, the method simplifies convolution operation and is suitable for special effect processing and synthesis technology of high-quality videos or images.

Description

Method and device for alpha channel boundary corrosion
Technical Field
The invention relates to the field of image processing, in particular to a method and a device for alpha channel boundary corrosion.
Background
In image/video processing technology, it is a frequently encountered and widely applied requirement to scratch off a certain kind of color in an image/video. The essence of this method is that a key value is calculated for each pixel in the image given a color (possibly with other parameters attached), the key value of the pixel in the image with the same or close color is zero or smaller, and the key value of the pixel with larger color difference is larger or 1; then the key value can be used as an alpha (alpha) channel when the image is synthesized with the background image, thereby achieving the purpose of image matting.
The key image (hereinafter referred to as an alpha channel image) obtained by the key method often has a relatively sharp boundary, which is formed by alpha values with large contrast, for example, the alpha values of pixels inside the boundary are large, and the alpha values outside the boundary are small. When the image is synthesized by applying the alpha channel image and the background image, the contrast between the foreground and the background at the boundary of the alpha channel is also larger. However, sometimes it is desirable that the contrast at the boundary is not as great or sharp, which requires a softening process at the boundary of the alpha channel.
Both box blur (box blur) and Gaussian blur (Gaussian blur) in the existing method can achieve the effect of softening the boundary. They all have a problem in that they obscure the entire boundary and that places where the alpha value on the original boundary is small now become large, which causes the foreground of the composite image where it is not intended to appear in the final composite image. The requirements of people are as follows: after the boundary is softened, the boundary is still more clearly visible, but the interior of the boundary (where the alpha value is large) is softened inwards (also referred to as corrosion); the outer boundary (where the alpha value is small) is softened to the outside, and the alpha value is raised to some extent but cannot be too large (which may also be referred to as a kind of erosion to the outer boundary).
Disclosure of Invention
The technical problem to be solved by the embodiment of the invention is to provide a method and a device for alpha channel boundary corrosion.
In order to solve the above problem, an embodiment of the present invention discloses a method for alpha channel boundary erosion, which includes:
acquiring an alpha channel image of a target image; the alpha channel image comprises alpha values of all pixel points;
performing one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point of the alpha channel image according to a preset convolution kernel and a preset convolution kernel radius;
carrying out matting processing on the target image according to the alpha value of each pixel point of the alpha channel image after the convolution processing;
wherein the convolution kernel
Figure BDA0001504514100000021
Sigma is a preset value, and sigma is more than or equal to 0 and less than or equal to 1; and p is the horizontal relative coordinate or the vertical relative coordinate of the pixel point participating in the convolution and the pixel point of the target convolution.
Optionally, the step of performing one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point of the alpha channel image according to a preset convolution kernel and a preset convolution kernel radius includes:
calculating a transverse convolution parameter and a longitudinal convolution parameter according to a preset convolution kernel and a preset convolution kernel radius;
according to the transverse convolution parameters, respectively carrying out one-dimensional transverse convolution on alpha values of all pixel points corresponding to all rows in the alpha channel image;
acquiring an alpha value of each pixel point corresponding to each row in the alpha channel image after the one-dimensional transverse convolution processing;
and respectively carrying out one-dimensional longitudinal convolution on the alpha values of the pixel points corresponding to the columns according to the longitudinal convolution parameters.
Further, the step of performing one-dimensional transverse convolution on the alpha values of the pixel points corresponding to each row in the alpha channel image according to the transverse convolution parameters includes:
acquiring an alpha value sequence S (n) of each pixel point corresponding to each row in the alpha channel image; n-0, …, N-1;
according to the transverse convolution parameters, performing one-dimensional transverse convolution on S (n) corresponding to each row to obtain an alpha value sequence T (n) of each pixel point corresponding to each row in the alpha channel image after the one-dimensional transverse convolution processing;
wherein the content of the first and second substances,
Figure BDA0001504514100000031
Figure BDA0001504514100000032
k (m) is the transverse convolution parameter, m is 0, …, 2R; r is a preset convolution kernel radius; n is the number of pixels corresponding to each row.
Further, the step of performing one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point of the alpha channel image according to a preset convolution kernel and a preset convolution kernel radius further includes:
after the one-dimensional transverse convolution, performing compression correction on the alpha value of each pixel point in the alpha channel image after the one-dimensional transverse convolution processing;
after the one-dimensional longitudinal convolution, performing compression correction on the alpha value of each pixel point in the alpha channel image after the one-dimensional longitudinal convolution processing.
Optionally, the one-dimensional transverse convolution processing and the one-dimensional longitudinal convolution processing are performed on the alpha value of each pixel point of the alpha channel image, and the processing includes:
and calling a shader of the graphics processor to perform one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point of the alpha channel image.
The embodiment of the invention also discloses a device for etching the boundary of the alpha channel, which comprises:
the alpha value acquisition module is used for acquiring an alpha channel image of the target image; the alpha channel image comprises alpha values of all pixel points;
the convolution processing module is used for performing one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point of the alpha channel image according to a preset convolution kernel and a preset convolution kernel radius;
the matting processing module is used for carrying out matting processing on the target image according to the alpha value of each pixel point of the alpha channel image after the convolution processing;
wherein the convolution kernel
Figure BDA0001504514100000033
Sigma is a preset value, and sigma is more than or equal to 0 and less than or equal to 1; and p is the horizontal relative coordinate or the vertical relative coordinate of the pixel point participating in the convolution and the pixel point of the target convolution.
Optionally, the convolution processing module includes:
the convolution parameter unit is used for calculating a transverse convolution parameter and a longitudinal convolution parameter according to a preset convolution kernel and a preset convolution kernel radius;
the transverse convolution unit is used for respectively carrying out one-dimensional transverse convolution on the alpha values of all pixel points corresponding to all rows in the alpha channel image according to the transverse convolution parameters;
an alpha value updating unit, configured to obtain an alpha value of each pixel point corresponding to each row in the alpha channel image after the one-dimensional transverse convolution processing;
and the longitudinal convolution unit is used for respectively carrying out one-dimensional longitudinal convolution on the alpha values of the pixel points corresponding to the columns according to the longitudinal convolution parameters.
Further, the transverse convolution unit includes:
the horizontal alpha value sequence subunit is used for acquiring an alpha value sequence S (n) of each pixel point corresponding to each row in the alpha channel image; n-0, …, N-1;
the transverse convolution processing subunit is used for performing one-dimensional transverse convolution on the S (n) corresponding to each row according to the transverse convolution parameters to obtain an alpha value sequence T (n) of each pixel point corresponding to each row in the alpha channel image after the one-dimensional transverse convolution processing;
wherein the content of the first and second substances,
Figure BDA0001504514100000041
Figure BDA0001504514100000042
k (m) is the transverse convolution parameter, m is 0, …, 2R; r is a preset convolution kernel radius; n is the number of pixels corresponding to each row.
Further, the convolution processing module further includes:
the first correction unit is used for carrying out compression correction on the alpha value of each pixel point in the alpha channel image after the one-dimensional transverse convolution processing after the one-dimensional transverse convolution;
and the second correction unit is used for performing compression correction on the alpha value of each pixel point in the alpha channel image after the one-dimensional longitudinal convolution processing.
Optionally, the convolution processing module is further configured to: and calling a shader of the graphics processor to perform one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point of the alpha channel image.
Compared with the prior art, the embodiment of the invention has the following advantages:
in the embodiment of the invention, the alpha channel image of the target image is subjected to one-dimensional transverse convolution and one-dimensional longitudinal convolution through the preset convolution kernel and the preset convolution kernel radius, and the obtained convolved alpha channel image has the effect of boundary corrosion when being applied to the matting processing of the target image; meanwhile, compared with two-dimensional convolution, the method simplifies convolution operation and is suitable for special effect processing and synthesis technology of high-quality videos or images.
Drawings
FIG. 1 is a flowchart illustrating the steps of a method for alpha channel boundary erosion, in accordance with an embodiment of the present invention;
FIG. 2 is a flow chart of steps of another method of alpha channel boundary erosion according to an embodiment of the present invention;
FIG. 3 is a schematic illustration of a method of alpha channel boundary erosion in accordance with an embodiment of the present invention;
FIG. 4 is a schematic view of an apparatus for alpha channel boundary erosion according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
Referring to fig. 1, an embodiment of the present invention discloses a method for alpha channel boundary corrosion, which may specifically include steps 101-103:
step 101: acquiring an alpha channel image of a target image; the alpha channel image includes alpha values of the pixel points.
In an embodiment of the present invention, the alpha channel image may use 256 gray levels (0-255) to record transparency information of the alpha channel image, illustratively, 255 for fully transparent, 0 for fully opaque, and 100 for semi-transparent. Therefore, the alpha channel image can be used as a mask when the object image is subjected to the matting processing.
The alpha channel image of the target image may be predicted; or may be calculated according to the target image and the actual requirement, and the description is omitted here because examples exist in the background art.
Of course, the above-mentioned alpha channel image may be an alpha channel image for each pixel point in the target image, or may be an alpha channel image for a part of pixel points.
Step 102: performing one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point of the alpha channel image according to a preset convolution kernel and a preset convolution kernel radius;
wherein the convolution kernel
Figure BDA0001504514100000061
Sigma is a preset value, and sigma is more than or equal to 0 and less than or equal to 1; and p is the horizontal relative coordinate or the vertical relative coordinate of the pixel point participating in the convolution and the pixel point of the target convolution.
In the embodiment of the invention, one-dimensional transverse convolution processing can be carried out on the alpha values of the pixel points of each row in the alpha channel image along the transverse direction; and then carrying out one-dimensional longitudinal convolution processing on the alpha values of the pixel points of each column in the alpha channel image after the one-dimensional transverse convolution processing along the longitudinal direction. Or conversely, the one-dimensional longitudinal convolution processing of each column is firstly carried out, and then the one-dimensional transverse convolution processing is carried out on each row in the alpha channel image after the one-dimensional longitudinal convolution processing.
Certainly, the one-dimensional transverse convolution processing may also be performed on the alpha values of the pixel points in at least one row in the alpha channel image, and then the one-dimensional longitudinal convolution processing is performed on the alpha values of the pixel points in at least one column in the alpha channel image; then, one-dimensional horizontal convolution processing of other rows and one-dimensional vertical convolution processing of other columns are carried out. In summary, the order of the one-dimensional horizontal convolution processing and the one-dimensional vertical convolution processing is not limited by the embodiment of the present invention.
It will be appreciated that in computer processing, the convolution of an image by one-dimensional transverse convolution processing and one-dimensional longitudinal convolution is faster than two-dimensional image convolution.
Optionally, the step 102 of performing one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point of the alpha channel image according to a preset convolution kernel and a preset convolution kernel radius may specifically include: calculating a transverse convolution parameter and a longitudinal convolution parameter according to a preset convolution kernel and a preset convolution kernel radius; according to the transverse convolution parameters, respectively carrying out one-dimensional transverse convolution on alpha values of all pixel points corresponding to all rows in the alpha channel image; acquiring the alpha value of each pixel point corresponding to each row in the alpha channel image after the one-dimensional transverse convolution processing; and according to the longitudinal convolution parameters, respectively carrying out one-dimensional longitudinal convolution on the alpha values of the pixel points corresponding to the columns.
Aiming at each pixel point of the target convolution, determining the pixel point participating in the convolution as a pixel point of which the transverse relative coordinate of the pixel point convolved with the target is within R for one-dimensional transverse convolution processing according to the preset convolution kernel radius R; and for one-dimensional longitudinal convolution processing, determining the pixel points participating in convolution as the pixel points with the longitudinal relative coordinate of the pixel points convolved with the target within R.
Illustratively, for a pixel point of the target convolution with the coordinate of (X, Y), for the one-dimensional transverse convolution processing, the pixel points participating in the convolution are determined to be (X-2, Y), (X-1, Y), (X +1, Y), and (X +2, Y).
Similarly, the corresponding horizontal convolution parameter and vertical convolution parameter, that is, the weight of each corresponding pixel participating in convolution, may be calculated according to the horizontal relative coordinate or vertical relative coordinate of the pixel participating in convolution and the pixel of the target convolution, and the convolution kernel.
Illustratively, the horizontal convolution parameters for the above-mentioned pixel points (X-2, Y), (X-1, Y), (X +1, Y), and (X +2, Y) participating in the convolution are K (-2), K (-1), K (0), K (1), and K (2), respectively.
Then, the one-dimensional horizontal convolution is performed on the pixel point of the target convolution with the coordinate (X, Y) to obtain a new alpha value equal to: the sum of the products of the weight of each pixel participating in convolution and the alpha value of each pixel participating in convolution.
For the one-dimensional vertical convolution processing, reference is made to the description of the one-dimensional horizontal convolution processing described above, and details thereof are not repeated here.
In the embodiment of the invention, because parameter exchange does not exist between the rows in the one-dimensional transverse convolution processing of the rows, parallel calculation can be carried out; likewise, each column may also be computed in parallel; if the one-dimensional horizontal convolution processing and the one-dimensional vertical convolution processing are performed on each row/column in an interlaced manner, parameter exchange exists, and parallel calculation cannot be performed. Therefore, in the embodiment of the invention, the one-dimensional transverse convolution processing can be performed on each row firstly, and then the one-dimensional transverse convolution processing of each column is performed, so that the parallel calculation can be conveniently performed, the calculation efficiency is improved, and the calculation time is shortened; in addition, the cache can be fully utilized, and the calculation efficiency is improved.
In the embodiment of the invention, the alpha channel image of the target image can be optimized according to actual requirements, so that the calculation efficiency is improved. For example, the boundary region in the alpha channel image may be determined first; the boundary region is a region in which the gradient of the alpha value in the alpha channel image is greater than or equal to a preset gradient. In the embodiment of the present invention, the convolution processing may be performed on the boundary region in the alpha channel image, and the convolution processing is not performed on the regions other than the boundary region in the alpha channel image, so that the calculation efficiency may be greatly improved, especially for processing of high-quality (e.g., high-resolution) video or images.
Step 103: and carrying out matting processing on the target image according to the alpha value of each pixel point of the alpha channel image after the convolution processing.
In the embodiment of the invention, the convolved alpha channel image can be used as a mask, and the pixels corresponding to the target image can be subjected to matting according to the alpha value of each pixel.
When the image is synthesized with the background image, the boundary of the matting object corresponding to the boundary of the alpha channel image after convolution processing (the alpha value gradient is larger than the preset gradient) is softer and shows a corrosion effect, the inside of the boundary (where the alpha value is larger) is softened towards the inside, the boundary is still clear and visible, and the problem of boundary blurring after traditional blurring processing is avoided.
Compared with the prior art, the embodiment of the invention has the following advantages:
in the embodiment of the invention, the alpha channel image of the target image is subjected to one-dimensional transverse convolution and one-dimensional longitudinal convolution through the preset convolution kernel and the preset convolution kernel radius, and the obtained convolved alpha channel image has the effect of boundary corrosion when being applied to the matting processing of the target image; meanwhile, compared with two-dimensional convolution, the method simplifies convolution operation and is suitable for special effect processing and synthesis technology of high-quality videos or images.
Referring to fig. 2, an embodiment of the present invention discloses a method for alpha channel boundary corrosion, which may specifically include steps 201-207:
step 201: acquiring an alpha channel image of a target image; the alpha channel image includes alpha values of the pixel points.
Step 202: calculating a transverse convolution parameter and a longitudinal convolution parameter according to a preset convolution kernel and a preset convolution kernel radius;
wherein the convolution kernel
Figure BDA0001504514100000081
Sigma is a preset value, and sigma is more than or equal to 0 and less than or equal to 1; and p is the horizontal relative coordinate or the vertical relative coordinate of the pixel point participating in the convolution and the pixel point of the target convolution.
Referring to the descriptions of the transverse convolution parameters and the longitudinal convolution parameters in the above embodiments, K (-R), K (-R +1) … … K (0), K (1) … … K (R-1), and K (R) may be calculated based on the above-mentioned preset convolution kernel K (p) and preset convolution kernel radius R.
The radius R of the preset convolution kernel may be 1, 2, 3, or another natural number.
Step 203: acquiring an alpha value sequence S (n) of each pixel point corresponding to each row in the alpha channel image; n-0, …, N-1.
Exemplarily, for an alpha channel image having M rows × N columns of pixel points, the number of each pixel point in each row is N, and the sequence of alpha values of each pixel point corresponding to each row is s (N); n-0, …, N-1.
Of course, the number of pixels in each row may be different, for example, NLWherein L is the serial number of each row.
Step 204: according to the transverse convolution parameters, performing one-dimensional transverse convolution on S (n) corresponding to each row to obtain an alpha value sequence T (n) of each pixel point corresponding to each row in the alpha channel image after the one-dimensional transverse convolution processing;
wherein the content of the first and second substances,
Figure BDA0001504514100000091
Figure BDA0001504514100000092
k (m) is the transverse convolution parameter, m is 0, …, 2R; r is a preset convolution kernel radius; n is the number of pixels corresponding to each row.
Exemplarily, when R ═ 2, then
T(n)=S*(n-2)K(-2)+S*(n-1)K(-1)+S*(n)K(0)+S*(n+1)K(1)+S*(n+2)K(2);
When n is equal to 0, the alpha value after convolution of the first pixel point of the line
T(0)=S(0)K(-2)+S(0)K(-1)+S(0)K(0)+S(1)K(1)+S(2)K(2);
When n is equal to 1, i.e. the convolved alpha value of the first pixel point of the row
T(1)=S(0)K(-2)+S(0)K(-1)+S(1)K(0)+S(2)K(1)+S(3)K(2);
When N is more than or equal to 2 and less than or equal to N-3, the alpha value of the middle pixel point of the row after convolution is obtained
T(0)=S(n-2)K(-2)+S(n-1)K(-1)+S(n)K(0)+S(n+1)K(1)+S(n+2)K(2);
When N is equal to N-2, the alpha value of the last pixel point of the line after convolution
T(N-2)=S(N-4)K(-2)+S(N-3)K(-1)+S(N-2)K(0)+S(N-1)K(1)+S(N-1)K(2);
When N is equal to N-1, the alpha value after convolution of the last pixel point of the line
T(N-1)=S(N-3)K(-2)+S(N-2)K(-1)+S(N-1)K(0)+S(N-1)K(1)+S(N-1)K(2)。
In the embodiment of the present invention, after the one-dimensional transverse convolution, compression correction may be further performed on the alpha value of each pixel point in the alpha channel image after the one-dimensional transverse convolution processing.
Because the alpha value of each pixel point after the one-dimensional transverse convolution processing may be greater than the alpha theoretical maximum value a, the alpha value of the pixel point greater than a in the alpha values of the pixel points needs to be corrected, and the alpha values of other pixel points need to be synchronously corrected, so as to ensure the relative relationship of the alpha values of the pixel points, thereby obtaining a more reasonable and accurate convolution result.
Illustratively, an equal-proportion compression correction may be performed, for example, the largest alpha value α among the alpha values of the pixel points is determinedmaxThen, the alpha value of each pixel point can be passed through the ratio A/alphamaxProceed and etcAnd (4) proportional compression.
Illustratively, the compression correction may also be performed by:
calculating the sum Q of all the transverse convolution parameters;
calculating a transverse convolution correction parameter QA; the transverse convolution correction parameter is the product of the sum Q and a preset alpha theoretical maximum value A;
respectively calculating the difference value between the transverse convolution correction parameter QA and the alpha value alpha of each pixel point;
if the difference (QA-alpha) is larger than A, the alpha value of each pixel point is corrected to be 0;
if the difference (QA-alpha) is smaller than A, the alpha value of each pixel point is corrected to be A- (QA-alpha).
For example, when the alpha value is 0 to 1, A is 1; when the alpha value is 0-255, A is 255. When σ is 0.5 and R is 2, Q is K (-2) + K (-1) + K (0) + K (1) + K (2) is 1.27.
Step 205: and obtaining the alpha value of each pixel point corresponding to each row in the alpha channel image after the one-dimensional transverse convolution processing.
Exemplarily, for an alpha channel image having M rows × N columns of pixel points, the number of each pixel point in each column is M, and the alpha value sequence of each pixel point corresponding to each column is p (N); n-0, …, M-1.
Step 206: and according to the longitudinal convolution parameters, respectively carrying out one-dimensional longitudinal convolution on the alpha values of the pixel points corresponding to the columns.
For the one-dimensional vertical convolution processing, refer to the description of the one-dimensional horizontal convolution processing in the above-mentioned steps 203-204, which is not described herein again.
Illustratively, the above-mentioned p (n) sequence is subjected to the same convolution process as the above-mentioned t (n) sequence.
Similarly, after the one-dimensional longitudinal convolution, compression correction can be performed on the alpha value of each pixel point in the alpha channel image after the one-dimensional longitudinal convolution processing; the calibration method is as above.
Step 207: and carrying out matting processing on the target image according to the alpha value of each pixel point of the alpha channel image after the convolution processing.
Referring to fig. 3, in the embodiment of the present invention, an alpha channel image 301 of a 5 × 8 target image is subjected to one-dimensional transverse convolution processing to 302 and corrected to 303; the one-dimensional longitudinal convolution is processed into 304, and the correction is carried out again into 305; where σ is 0.5, R is 2, and a is 1.
It can be seen that in 301 before convolution processing, the alpha values of the columns of the alpha channel image of the target image are 0, 0.1, 0.2, 0.8, 1.0, and 1.0, respectively, so it can be understood that when the alpha channel image is used for matting processing, the boundary (corresponding to the vicinity of 0.8 of the 5 th column) will be very sharp (the gradient of the alpha values is very large), and the effect of erosion will not be obvious (for example, erosion from the 5 th row to the right, i.e., softening to the inside of the boundary). In 305 after the convolution processing, the alpha values of the columns are respectively 0, 0.608, 0.965, 1.0 and 1.0, and it can be obviously seen that the right side of the boundary (corresponding to the vicinity of 0.608 of the 5 th column) is corroded from the 5 th row to the right, that is, softened towards the inside of the boundary, so that the corrosion effect is realized, and the boundary is soft; furthermore, the gradient of the alpha value to the left of the boundary is large, so that the boundary is still clearly apparent.
In the embodiment of the present invention, a Shader (Shader) of a Graphics Processing Unit (GPU) may be invoked to perform one-dimensional horizontal convolution processing and one-dimensional vertical convolution processing on the alpha values of each pixel point of the alpha channel image.
Generally, an algorithm or a program corresponding to the convolution processing can be loaded in a shader; setting the transverse convolution parameters in a shader, and performing one-dimensional transverse convolution; and setting the longitudinal convolution parameters, and performing one-dimensional longitudinal convolution.
When processing in the GPU, convolution processing can be carried out through a graphics processing unit with multiple threads: for example, dividing data of an input alpha channel image into a plurality of sub-arrays (rows or columns); processing the divided sub-arrays through a special execution thread (one-dimensional transverse convolution processing or one-dimensional longitudinal convolution processing), and putting a processing result into a correspondingly generated storage area; and combining the processing results.
Therefore, by using the shader of the graphics processor, more efficient cache space and faster IO (input output) can be utilized, and the computing efficiency is improved; in addition, aiming at the parallel characteristic of the GPU, one-dimensional transverse convolution of each row or one-dimensional longitudinal convolution of each column is carried out through parallel calculation and superposition, so that the convolution calculation is more efficient.
Compared with the prior art, the embodiment of the invention has the following advantages:
in the embodiment of the invention, the alpha channel image of the target image is subjected to one-dimensional transverse convolution and one-dimensional longitudinal convolution through the preset convolution kernel and the preset convolution kernel radius, and the obtained convolved alpha channel image has the effect of boundary corrosion when being applied to the matting processing of the target image; meanwhile, compared with two-dimensional convolution, the method simplifies convolution operation and is suitable for special effect processing and synthesis technology of high-quality videos or images; in addition, in the embodiment of the present invention, the above-described one-dimensional transverse convolution and one-dimensional longitudinal convolution processing may be performed by a graphics processor, so that the convolution calculation is more efficient.
For simplicity of explanation, the method embodiments are described as a series of acts or combinations, but those skilled in the art will appreciate that the embodiments are not limited by the order of acts described, as some steps may occur in other orders or concurrently with other steps in accordance with the embodiments of the invention. Further, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred and that no particular act is required to implement the invention.
Referring to fig. 4, an embodiment of the present invention discloses an apparatus for alpha channel boundary erosion, which may specifically include:
an alpha value obtaining module 401, configured to obtain an alpha channel image of the target image; the alpha channel image comprises alpha values of all pixel points;
a convolution processing module 402, configured to perform one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point of the alpha channel image according to a preset convolution kernel and a preset convolution kernel radius;
a matting processing module 403, configured to perform matting processing on the target image according to an alpha value of each pixel point of the convolved alpha channel image;
wherein the convolution kernel
Figure BDA0001504514100000121
Sigma is a preset value, and sigma is more than or equal to 0 and less than or equal to 1; and p is the horizontal relative coordinate or the vertical relative coordinate of the pixel point participating in the convolution and the pixel point of the target convolution.
Optionally, the convolution processing module 402 may include:
the convolution parameter unit is used for calculating a transverse convolution parameter and a longitudinal convolution parameter according to a preset convolution kernel and a preset convolution kernel radius;
the transverse convolution unit is used for respectively carrying out one-dimensional transverse convolution on the alpha values of the pixel points corresponding to each row in the alpha channel image according to the transverse convolution parameters;
an alpha value updating unit, configured to obtain an alpha value of each pixel point corresponding to each row in the alpha channel image after the one-dimensional transverse convolution processing;
and the longitudinal convolution unit is used for respectively carrying out one-dimensional longitudinal convolution on the alpha values of the pixel points corresponding to the columns according to the longitudinal convolution parameters.
Further, the above-mentioned transverse convolution unit includes:
a horizontal alpha value sequence subunit, configured to obtain an alpha value sequence s (n) of each pixel point corresponding to each row in the alpha channel image; n-0, …, N-1;
a transverse convolution processing subunit, configured to perform one-dimensional transverse convolution on s (n) corresponding to each row according to the transverse convolution parameter, so as to obtain an alpha value sequence t (n) of each pixel point corresponding to each row in the alpha channel image after the one-dimensional transverse convolution processing;
wherein the content of the first and second substances,
Figure BDA0001504514100000131
Figure BDA0001504514100000132
k (m) is the transverse convolution parameter, m is 0, …, 2R; r is a preset convolution kernel radius; n is the number of pixels corresponding to each row.
Further, the convolution processing module 402 may further include:
a first correction unit, configured to perform compression correction on the alpha value of each pixel point in the alpha channel image after the one-dimensional transverse convolution processing after the one-dimensional transverse convolution;
and the second correction unit is used for performing compression correction on the alpha value of each pixel point in the alpha channel image after the one-dimensional longitudinal convolution processing.
Optionally, the convolution processing module 402 is further configured to: and calling a shader of the graphic processor to perform one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha values of all the pixel points of the alpha channel image.
Compared with the prior art, the embodiment of the invention has the following advantages:
in the embodiment of the invention, the alpha channel image of the target image is subjected to one-dimensional transverse convolution and one-dimensional longitudinal convolution through the preset convolution kernel and the preset convolution kernel radius, and the obtained convolved alpha channel image has the effect of boundary corrosion when being applied to the matting processing of the target image; meanwhile, compared with two-dimensional convolution, the method simplifies convolution operation and is suitable for special effect processing and synthesis technology of high-quality videos or images; in addition, in the embodiment of the present invention, the above-described one-dimensional transverse convolution and one-dimensional longitudinal convolution processing may be performed by a graphics processor, so that the convolution calculation is more efficient.
For the device embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, refer to the partial description of the method embodiment.
In the description provided herein, numerous specific details are set forth. It is understood, however, that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that the invention as claimed requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this invention.
Those skilled in the art will appreciate that the modules in the device in an embodiment may be adaptively changed and disposed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments described herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the invention and form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention may be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names.

Claims (8)

1. A method of alpha channel boundary erosion, comprising:
acquiring a boundary area in an alpha channel image of a target image; the alpha channel image comprises alpha values of all pixel points; the boundary region is a region in which the alpha value gradient in the alpha channel image is greater than or equal to a preset gradient;
performing one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point of the alpha channel image according to a preset convolution kernel and a preset convolution kernel radius;
carrying out matting processing on the target image according to the alpha value of each pixel point of the alpha channel image after the convolution processing;
wherein the convolution kernel
Figure FDA0003245658710000011
Sigma is a preset value, and sigma is more than or equal to 0 and less than or equal to 1; p is the convolution of the pixel points participating in the convolution with the targetThe horizontal relative coordinates or the vertical relative coordinates of the pixel points;
the step of performing one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point in the boundary area of the alpha channel image according to a preset convolution kernel and a preset convolution kernel radius comprises the following steps:
performing one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point in the boundary area of the alpha channel image according to a preset convolution kernel and a preset convolution kernel radius; when the one-dimensional transverse convolution processing and the one-dimensional longitudinal convolution processing are carried out, the one-dimensional transverse convolution processing is firstly carried out on the pixel points of each row in parallel, and then the one-dimensional longitudinal convolution processing is carried out on the pixel points of each column in parallel;
after the one-dimensional transverse convolution, performing compression correction on the alpha value of each pixel point in the alpha channel image after the one-dimensional transverse convolution processing;
after the one-dimensional longitudinal convolution, performing compression correction on the alpha value of each pixel point in the alpha channel image after the one-dimensional longitudinal convolution;
the compressing and correcting the alpha value of each pixel point in the alpha channel image after the one-dimensional transverse convolution processing comprises the following steps:
calculating the sum of each transverse convolution parameter, obtaining a transverse convolution correction parameter by the sum and a preset alpha theoretical maximum value, calculating the difference value between the transverse convolution correction parameter and the alpha value alpha of each pixel point, and performing compression correction on the alpha value of each pixel point in the alpha channel image after the one-dimensional transverse convolution processing through the difference value;
the compression correction of the alpha value of each pixel point in the alpha channel image after the one-dimensional longitudinal convolution processing comprises:
calculating the sum of each longitudinal convolution parameter, obtaining a longitudinal convolution correction parameter from the sum and a preset alpha theoretical maximum value, calculating the difference value between the longitudinal convolution correction parameter and the alpha value alpha of each pixel point, and performing compression correction on the alpha value of each pixel point in the alpha channel image after the one-dimensional longitudinal convolution processing through the difference value.
2. The method as claimed in claim 1, wherein said step of performing one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point of said alpha channel image according to a preset convolution kernel and a preset convolution kernel radius comprises:
calculating a transverse convolution parameter and a longitudinal convolution parameter according to a preset convolution kernel and a preset convolution kernel radius;
according to the transverse convolution parameters, respectively carrying out one-dimensional transverse convolution on alpha values of all pixel points corresponding to all rows in the alpha channel image;
acquiring an alpha value of each pixel point corresponding to each row in the alpha channel image after the one-dimensional transverse convolution processing;
and respectively carrying out one-dimensional longitudinal convolution on the alpha values of the pixel points corresponding to the columns according to the longitudinal convolution parameters.
3. The method according to claim 2, wherein said step of performing one-dimensional horizontal convolution on the alpha values of each pixel point corresponding to each row in the alpha channel image according to the horizontal convolution parameter comprises:
acquiring an alpha value sequence S (n) of each pixel point corresponding to each row in the alpha channel image; n-0, …, N-1;
according to the transverse convolution parameters, performing one-dimensional transverse convolution on S (n) corresponding to each row to obtain an alpha value sequence T (n) of each pixel point corresponding to each row in the alpha channel image after the one-dimensional transverse convolution processing;
wherein the content of the first and second substances,
Figure FDA0003245658710000021
Figure FDA0003245658710000031
k (m) is the transverse convolution parameter, m is 0, …, 2R; r is a preset convolution kernel radius; n is the number of pixels corresponding to each row.
4. The method as claimed in any one of claims 1 to 3, wherein the performing one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point of the alpha channel image comprises:
and calling a shader of the graphics processor to perform one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point of the alpha channel image.
5. An apparatus for alpha channel boundary erosion, comprising:
the alpha value acquisition module is used for acquiring a boundary area in an alpha channel image of the target image; the alpha channel image comprises alpha values of all pixel points; the boundary region is a region in which the alpha value gradient in the alpha channel image is greater than or equal to a preset gradient;
the convolution processing module is used for performing one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point of the alpha channel image according to a preset convolution kernel and a preset convolution kernel radius;
the matting processing module is used for carrying out matting processing on the target image according to the alpha value of each pixel point of the alpha channel image after the convolution processing;
wherein the convolution kernel
Figure FDA0003245658710000032
Sigma is a preset value, and sigma is more than or equal to 0 and less than or equal to 1; p is the horizontal relative coordinate or the vertical relative coordinate of the pixel point participating in the convolution and the pixel point of the target convolution;
the convolution processing module is specifically used for performing one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point in the boundary area of the alpha channel image according to a preset convolution kernel and a preset convolution kernel radius; when the one-dimensional transverse convolution processing and the one-dimensional longitudinal convolution processing are performed, the one-dimensional transverse convolution processing is performed on the pixel points of each row in parallel, and then the one-dimensional longitudinal convolution processing is performed on the pixel points of each column in parallel.
6. The apparatus of claim 5, wherein the convolution processing module comprises:
the convolution parameter unit is used for calculating a transverse convolution parameter and a longitudinal convolution parameter according to a preset convolution kernel and a preset convolution kernel radius;
the transverse convolution unit is used for respectively carrying out one-dimensional transverse convolution on the alpha values of all pixel points corresponding to all rows in the alpha channel image according to the transverse convolution parameters;
an alpha value updating unit, configured to obtain an alpha value of each pixel point corresponding to each row in the alpha channel image after the one-dimensional transverse convolution processing;
the longitudinal convolution unit is used for respectively carrying out one-dimensional longitudinal convolution on the alpha values of the pixel points corresponding to the columns according to the longitudinal convolution parameters; the first correction unit is used for performing compression correction on the alpha value of each pixel point in the alpha channel image after the one-dimensional transverse convolution processing, and comprises the following steps:
calculating the sum of each transverse convolution parameter, obtaining a transverse convolution correction parameter by the sum and a preset alpha theoretical maximum value, calculating the difference value between the transverse convolution correction parameter and the alpha value alpha of each pixel point, and performing compression correction on the alpha value of each pixel point in the alpha channel image after the one-dimensional transverse convolution processing through the difference value;
the second correction unit is configured to perform compression correction on the alpha value of each pixel point in the alpha channel image after the one-dimensional longitudinal convolution processing, and includes:
calculating the sum of each longitudinal convolution parameter, obtaining a longitudinal convolution correction parameter from the sum and a preset alpha theoretical maximum value, calculating the difference value between the longitudinal convolution correction parameter and the alpha value alpha of each pixel point, and performing compression correction on the alpha value of each pixel point in the alpha channel image after the one-dimensional longitudinal convolution processing through the difference value.
7. The apparatus of claim 6, wherein the transverse convolution unit comprises:
the horizontal alpha value sequence subunit is used for acquiring an alpha value sequence S (n) of each pixel point corresponding to each row in the alpha channel image; n-0, …, N-1;
the transverse convolution processing subunit is used for performing one-dimensional transverse convolution on the S (n) corresponding to each row according to the transverse convolution parameters to obtain an alpha value sequence T (n) of each pixel point corresponding to each row in the alpha channel image after the one-dimensional transverse convolution processing;
wherein the content of the first and second substances,
Figure FDA0003245658710000041
Figure FDA0003245658710000042
k (m) is the transverse convolution parameter, m is 0, …, 2R; r is a preset convolution kernel radius; n is the number of pixels corresponding to each row.
8. The apparatus of any of claims 5 to 7, wherein the convolution processing module is further configured to: and calling a shader of the graphics processor to perform one-dimensional transverse convolution processing and one-dimensional longitudinal convolution processing on the alpha value of each pixel point of the alpha channel image.
CN201711319709.8A 2017-12-12 2017-12-12 Method and device for alpha channel boundary corrosion Active CN108198128B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711319709.8A CN108198128B (en) 2017-12-12 2017-12-12 Method and device for alpha channel boundary corrosion

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711319709.8A CN108198128B (en) 2017-12-12 2017-12-12 Method and device for alpha channel boundary corrosion

Publications (2)

Publication Number Publication Date
CN108198128A CN108198128A (en) 2018-06-22
CN108198128B true CN108198128B (en) 2021-12-03

Family

ID=62574340

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711319709.8A Active CN108198128B (en) 2017-12-12 2017-12-12 Method and device for alpha channel boundary corrosion

Country Status (1)

Country Link
CN (1) CN108198128B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110136163B (en) * 2019-04-29 2021-02-12 中国科学院自动化研究所 Hand motion fuzzy automatic cutout and application in human body soft segmentation and background replacement

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101764914A (en) * 2008-12-10 2010-06-30 新奥特(北京)视频技术有限公司 Method of alpha channel boundary corrosion
CN101763627A (en) * 2008-12-12 2010-06-30 新奥特(北京)视频技术有限公司 Method and device for realizing Gaussian blur
CN106997608A (en) * 2016-01-22 2017-08-01 五八同城信息技术有限公司 A kind of method and device for generating halation result figure

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2000270208A (en) * 1999-03-12 2000-09-29 Fuji Xerox Co Ltd Image processor and image processing method
US8744184B2 (en) * 2004-10-22 2014-06-03 Autodesk, Inc. Graphics processing method and system
CN105678724A (en) * 2015-12-29 2016-06-15 北京奇艺世纪科技有限公司 Background replacing method and apparatus for images

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101764914A (en) * 2008-12-10 2010-06-30 新奥特(北京)视频技术有限公司 Method of alpha channel boundary corrosion
CN101763627A (en) * 2008-12-12 2010-06-30 新奥特(北京)视频技术有限公司 Method and device for realizing Gaussian blur
CN106997608A (en) * 2016-01-22 2017-08-01 五八同城信息技术有限公司 A kind of method and device for generating halation result figure

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
《二维高斯模糊和可分离核形式的快速实现》;zxpddfg;《https://blog.csdn.net/zxpddfg/article/details/45912561?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-7.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-7.control》;20150522;第1-6页 *
《影视后期个性化抠像插件的开发》;王楠;《安庆师范学院学报( 自然科学版)》;20151130(第4期);第52-57页 *

Also Published As

Publication number Publication date
CN108198128A (en) 2018-06-22

Similar Documents

Publication Publication Date Title
CN107454284B (en) Video denoising method and computing device
CN102104713A (en) Adaptive edge enhancement using directional components from non-linear filtering
EP2997539B1 (en) Method and device for processing input image data
JP2011250125A5 (en)
US11238560B2 (en) Image down-scaling with pixel sets selected via blue noise sampling
CN113870293A (en) Image processing method, image processing device, electronic equipment and storage medium
US20160300331A1 (en) Scalable massive parallelization of overlapping patch aggregation
US20160042498A1 (en) System and method for increasing the bit depth of images
CN111242066B (en) Large-size image target detection method, device and computer readable storage medium
CN108198128B (en) Method and device for alpha channel boundary corrosion
JP2007535267A (en) Image processing apparatus and method
US20040008204A1 (en) Switching sample buffer context in response to sample requests for real-time sample filtering and video generation
CN109416743B (en) Three-dimensional convolution device for identifying human actions
CN106878586B (en) reconfigurable parallel image detail enhancement method and device
EP0855682B1 (en) Scan line rendering of convolutions
CN110807113B (en) Non-iterative elimination method for rectangular primitive overlap in visual layout
CN110084866B (en) Computed tomography method and device
JP7140491B2 (en) Image processing device, image processing method, and program
Khan et al. Realization of Balanced Contrast Limited Adaptive Histogram Equalization (B-CLAHE) for Adaptive Dynamic Range Compression of Real Time Medical Images
CN105513004A (en) Image distortion correction system, storage method thereof, and addressing method
KR101699029B1 (en) Image Processing Device Improving Area Processing Speed and Processing Method Thereof
US9330445B2 (en) Local contrast enhancement method and apparatus
KR100808087B1 (en) A streaming maximum intensity projection volume rendering method
JP4031013B2 (en) Texture mapping circuit
CN108805846A (en) The method and its system of binary Images Processing optimization

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant