WO2023103684A1 - 人像头发流动特效处理方法、装置、介质和电子设备 - Google Patents

人像头发流动特效处理方法、装置、介质和电子设备 Download PDF

Info

Publication number
WO2023103684A1
WO2023103684A1 PCT/CN2022/130618 CN2022130618W WO2023103684A1 WO 2023103684 A1 WO2023103684 A1 WO 2023103684A1 CN 2022130618 W CN2022130618 W CN 2022130618W WO 2023103684 A1 WO2023103684 A1 WO 2023103684A1
Authority
WO
WIPO (PCT)
Prior art keywords
hair
flow
pixel
sub
hair flow
Prior art date
Application number
PCT/CN2022/130618
Other languages
English (en)
French (fr)
Inventor
贺天童
包泽华
Original Assignee
北京字节跳动网络技术有限公司
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
Priority claimed from CN202111477583.3A external-priority patent/CN114219877B/zh
Application filed by 北京字节跳动网络技术有限公司 filed Critical 北京字节跳动网络技术有限公司
Publication of WO2023103684A1 publication Critical patent/WO2023103684A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T13/00Animation
    • G06T13/203D [Three Dimensional] animation
    • G06T13/403D [Three Dimensional] animation of characters, e.g. humans, animals or virtual beings

Definitions

  • the embodiments of the present disclosure relate to the technical field of image processing, and in particular, to a method for processing a special effect of flowing hair of a portrait, a device for processing a special effect of flowing hair of a portrait, and a computer-readable storage medium and electronic equipment for implementing the method for processing a special effect of flowing hair of a portrait.
  • a hair flow special effect picture can be added to the portrait area in the video, thereby improving the interest and visual effect of the video.
  • the entire hair area of the portrait in the video will be processed when adding, and it is impossible to process some hair areas to add hair flow special effects, which makes the flexibility of adding hair flow special effects poor, and the fidelity of hair flow special effects images is also low.
  • embodiments of the present disclosure provide a method for processing special effects of flowing hair on portraits, a device for processing special effects on flowing hair on portraits, and a computer-readable storage medium for implementing the method for processing special effects on flowing hair on portraits and electronic equipment.
  • an embodiment of the present disclosure provides a method for processing a portrait hair flow special effect, including:
  • the first hair flow data including the flow distance of each pixel in the hair region along a preset flow direction
  • each of the second hair flow data includes the flow of each pixel in the corresponding hair sub-region speed
  • a time parameter is acquired, and a hair flow special effect video is generated based on the time parameter, the second hair flow data corresponding to each of the hair sub-regions, and the original image.
  • the method also includes:
  • erosion parameters include pixel width and/or pixel height
  • the etching operation is performed on the mask to achieve layering on the hair region to obtain multiple hair sub-regions, including:
  • the first etching result data includes the pixel corresponding to each pixel in the mask first pixel value
  • each first pixel value in the first corrosion result data with a first preset threshold, and determining a first hair sub-region based on pixels whose first pixel values are greater than or equal to the first preset threshold,
  • the second hair sub-region is determined based on pixels whose first pixel values are smaller than the first preset threshold.
  • the acquisition of corrosion parameters required for corrosion operations includes:
  • the etching operation is performed on the mask to achieve layering on the hair region to obtain multiple hair sub-regions, including:
  • An erosion operation is performed on the mask by a shader (Shader) running in a graphics processing unit (GPU), so as to implement layering on the hair region to obtain multiple hair sub-regions.
  • a shader Shader
  • GPU graphics processing unit
  • the method also includes:
  • the second corrosion result data includes the second hair sub-region The second pixel value corresponding to each pixel point;
  • each second pixel value in the second corrosion result data with a second preset threshold, and determining a third hair sub-region based on pixels whose second pixel values are greater than or equal to the second preset threshold; Wherein, the second preset threshold is smaller than the first preset threshold.
  • the method also includes:
  • the determining the second hair flow data corresponding to each of the hair sub-regions based on the first hair flow data includes:
  • the second hair flow data corresponding to each of the hair sub-regions is determined.
  • the second hair flow data corresponding to each hair sub-region is determined based on the first adjustment coefficient corresponding to each of the hair sub-regions and the first hair flow data Previously, the method further included:
  • the determining the second hair flow data corresponding to each hair sub-region based on the first adjustment coefficient corresponding to each of the hair sub-regions and the first hair flow data includes:
  • Second hair flow data corresponding to each of the hair sub-regions is determined.
  • the method before performing normalization processing on the first hair flow data and obtaining target hair flow data, the method further includes:
  • the said first hair flow data is normalized to obtain the target hair flow data, including:
  • the first hair flow data is normalized to obtain target hair flow data.
  • the first hair flow data is normalized to obtain the target hair flow data, including:
  • the target hair flow data is determined based on the sum value corresponding to each pixel in the first hair flow data.
  • the acquiring time parameters, based on the time parameters, the second hair flow data corresponding to each of the hair sub-regions, and the original image, generating a hair flow special effect video includes:
  • each of the third hair flow data includes each pixel in the corresponding hair sub-region the first flow offset of the point;
  • a hair flow special effect video is generated.
  • the method also includes:
  • the determining the corresponding third hair flow data based on the time parameter and the second hair flow data corresponding to each hair sub-region includes:
  • first hair flow special effect image data is determined as the hair flow special effect image data.
  • the method also includes:
  • each of the fourth hair flow data includes each of the corresponding hair sub-regions The second flow offset of the pixel
  • the hair flow special effect image data is determined based on the second hair flow special effect image data and the first hair flow special effect image data.
  • an embodiment of the present disclosure provides a device for processing special effects of human hair flow, including:
  • a data determination module configured to determine the mask of the hair region in the original image and the first hair flow data, the first hair flow data including the flow distance of each pixel of the hair region along a preset flow direction;
  • a hair layering module configured to perform an erosion operation on the mask, so as to layer the hair region to obtain multiple hair subregions
  • a data calculation module configured to determine the second hair flow data corresponding to each of the hair sub-regions based on the first hair flow data; wherein, each of the second hair flow data includes the corresponding hair sub-region The flow speed of each pixel;
  • the special effect processing module is configured to acquire a time parameter, and generate a hair flow special effect video based on the time parameter, the second hair flow data corresponding to each of the hair sub-regions, and the original image.
  • an embodiment of the present disclosure provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method for processing a human portrait hair flowing special effect described in any of the above-mentioned embodiments are implemented.
  • an electronic device including:
  • the processor is configured to execute the steps of the method for processing the flow special effect of human portrait hair in any one of the above-mentioned embodiments by executing the computer program.
  • an embodiment of the present disclosure provides a computer program product, the computer program product includes a computer program or an instruction, and when the computer program or instruction is run on a computer, the computer executes the computer program described in any of the above embodiments. The steps of the method for processing the flowing special effects of portrait hair are described.
  • an embodiment of the present disclosure provides a computer program, the program code included in the computer program causes the computer to execute the steps of the method for processing human hair flow special effects described in any of the above embodiments when executed by a computer.
  • the hair flow special effect processing method, device, medium and electronic equipment determine the mask of the hair region in the original image and the first hair flow data, the first hair flow data includes each of the hair regions The flow distance of the pixel points along the preset flow direction; performing an erosion operation on the mask to layer the hair region to obtain a plurality of hair sub-regions; based on the first hair flow data, determine each of the hair The second hair flow data corresponding to the sub-region, wherein each of the second hair flow data includes the flow velocity of each pixel in the corresponding hair sub-region; obtain time parameters, based on the time parameters, each of the The second hair flow data corresponding to the hair sub-region and the original image are used to generate a hair flow special effect video.
  • the layering of the hair region can be realized through the erosion operation of the mask of the hair region in the original image, so that a part of the hair region, such as one or more hair subregions, can be processed to add a hair flow special effect picture , so that the flexibility of adding hair flow special effects is better, meeting the needs of different users to add hair flow special effects personalizedly.
  • adding time parameters to realize the hair flow special effects picture the quality of the hair flow special effect picture is better, such as hair flow continuous, flow special effects The picture fidelity is higher.
  • FIG. 1 is a flow chart of a method for processing a portrait hair flow special effect according to an embodiment of the present disclosure
  • FIG. 2 is a flow chart of a method for processing a portrait hair flow special effect according to another embodiment of the present disclosure
  • Fig. 3 is a schematic diagram of the delamination effect of the corrosion operation on the hair region according to the embodiment of the present disclosure
  • FIG. 4 is a flow chart of a method for processing a portrait hair flow special effect according to another embodiment of the present disclosure
  • FIG. 5 is a flow chart of a method for processing a portrait hair flow special effect according to yet another embodiment of the present disclosure
  • FIG. 6 is a schematic diagram of a hair flow special effect processing device for portraits according to an embodiment of the present disclosure
  • FIG. 7 is a schematic diagram of an electronic device implementing a method for processing a human portrait hair flow special effect according to an embodiment of the present disclosure.
  • At least one (item) means one or more, and “multiple” means two or more.
  • “And/or” is used to describe the association relationship of associated objects, which means that there can be three kinds of relationships, for example, “A and/or B” can mean: only A exists, only B exists, and A and B exist at the same time. Among them, A and B can be singular or plural.
  • the character “/” generally indicates that the contextual objects are an “or” relationship.
  • At least one of the following” or similar expressions refer to any combination of these items, including any combination of single or plural items.
  • At least one item (piece) of a, b or c can mean: a, b, c, "a and b", “a and c", “b and c", or "a and b and c ", where a, b, c can be single or multiple.
  • FIG. 1 is a flow chart of a method for processing human hair flowing special effects shown in an embodiment of the present disclosure.
  • the method can be executed by an electronic device such as a smart phone, and can specifically include the following steps:
  • Step S101 Determine the mask of the hair region in the original image and the first hair flow data, the first hair flow data includes the flow distance of each pixel of the hair region along a preset flow direction.
  • the hair region of the person's head in the original image can be segmented to obtain a mask (mask), which facilitates subsequent processing of the hair region in the image.
  • the preset flow direction may include the X direction of the two-dimensional plane, that is, the left-right direction and the Y direction, that is, the up-down direction
  • the first hair flow data may include the flow distance x (-1 ⁇ x ⁇ 1) of each pixel point P in the hair region along the X direction ) and/or the flow distance y along the Y direction (-1 ⁇ y ⁇ 1), that is, the predicted offset distance along the X direction and the Y direction
  • the absolute value of the flow distance x is less than or equal to 1 pixel width
  • the flow The absolute value of the distance y is less than or equal to 1 pixel height.
  • the values of x and y can be positive or negative.
  • a positive value of x means the flow direction is right, a negative value of x means the flow direction is left, and y
  • a positive value indicates that the flow direction is upward, and a negative value of y indicates that the flow direction is downward.
  • Step S102 Perform an erosion operation on the mask to achieve layering of the hair region to obtain multiple hair sub-regions.
  • the mask of the hair region can be binarized, and then an erosion (Erode) operation can be performed.
  • Corrosion operation is one of the morphological operations in image processing. Taking the center point of the template pixel structure as the center, finding a pixel point in the image that can satisfy the template pixel structure is corrosion. For example, moving the template pixel structure, if the template pixel If the intersection of the structure and the image (including at least one pixel) completely belongs to the area of the image, save the pixels in the intersection, and then continue to move the pixel structure of the template to perform the erosion operation until all the pixels in the intersection that meet the conditions form an image The result of erosion by template pixel structures.
  • the template pixel structure is, for example, a rectangular structure in which the pixel height is multiplied by the pixel width, but it is not limited thereto.
  • the hair region in the image is layered by an erosion operation to obtain multiple hair subregions, and each hair subregion is a part of the hair region.
  • multiple etching operations can be performed, and the specific number of times can be set according to needs, which is not limited.
  • the number of hair sub-regions can also be determined according to needs, which is not limited in this embodiment.
  • Step S103 Based on the first hair flow data, determine the second hair flow data corresponding to each of the hair sub-regions; wherein, each of the second hair flow data includes each pixel corresponding to the hair sub-region point flow velocity.
  • the first hair flow data such as the flow distance x along the X direction and/or the flow distance y along the Y direction of each pixel point P of the hair region, based on the first hair flow data such as each pixel point P i along the X direction
  • the flow distance x i in the direction and/or the flow distance y i along the Y direction and time determine the second hair flow data of each hair sub-region, that is, the flow velocity of each pixel in each hair sub-region.
  • the hair area includes 10,000 pixels, and the layered hair sub-area 1 includes 3,000 pixels, the hair sub-area 2 includes 5,000 pixels, and the hair sub-area 3 includes 2,000 pixels, then based on the hair sub-area 1
  • the flow distance x along the X direction and/or the flow distance y along the Y direction corresponding to each of the 3000 pixels in divided by the unit time such as 1 second to obtain the flow velocity of each pixel in the hair sub-region 1, such as the flow speed in the X direction Flow velocity and/or flow velocity in the Y direction.
  • Step S104 Obtain a time parameter, and generate a hair flow special effect video based on the time parameter, the second hair flow data corresponding to each of the hair sub-regions, and the original image.
  • the time parameter may be a timestamp of the current time, but is not limited thereto.
  • the flow velocity of each pixel in the hair sub-region 1 multiplying it with the time parameter can determine the flow distance of each pixel in the hair sub-region 1, that is, the offset distance from the original position, so as to determine the offset hair
  • a static user photo is automatically generated as a video screen with special effects of hair flowing and floating in the hair area.
  • the layering of the hair region can be realized through the corrosion operation of the mask of the hair region in the original image, so that part of the hair region can be processed to add the hair flow special effect picture, so that the flexibility of adding the hair flow special effect is relatively high.
  • the quality of hair flow special effects pictures is better, such as continuous hair flow and high fidelity of flow special effects pictures.
  • the method may further include step 201: acquiring corrosion parameters required for the corrosion operation, the corrosion parameters including pixel width and/or pixel height .
  • the erosion operation is a pixel-by-pixel operation, and the position of the pixels around a pixel needs to be known.
  • the erosion parameter can be the pixel width widthOffset and/or the pixel height heightOffset, which is convenient for pixel-by-pixel offset during the erosion operation , such as the template pixel structure moves from one pixel position by one pixel width and/or pixel height to another pixel position.
  • the buffer RT can be configured during actual processing to record the intermediate process of the erosion operation, and erosion parameters such as pixel width widthOffset and pixel height heightOffset can be stored in the buffer RT.
  • step S102 an erosion operation is performed on the mask to achieve stratification of the hair region to obtain multiple hair sub-regions, which may specifically include the following steps:
  • Step S202 Based on the pixel width and/or pixel height, perform an etching operation on the mask pixel by pixel to obtain first etching result data, the first etching result data includes each pixel in the mask The point corresponds to the first pixel value.
  • the pixel width widthOffset and the pixel height heightOffset are read from the buffer RT, and the mask is etched pixel by pixel based on the pixel width and/or pixel height, and the intermediate result of the erosion operation can be written into the buffer RT, and finally obtain the first corrosion result data, that is, the first pixel value corresponding to each pixel point in the mask, such as the RGB value.
  • Step S203 Comparing the value of each first pixel in the first corrosion result data with the first preset threshold, and determining the first hair based on the pixels whose first pixel value is greater than or equal to the first preset threshold In the sub-region, the second hair sub-region is determined based on pixels whose first pixel values are smaller than the first preset threshold.
  • the first preset threshold can be set according to needs, which is not limited.
  • comparing each first pixel value in the first corrosion result data, such as the RGB value, with the size of the first preset threshold, based on the fact that the first pixel value, such as the RGB value, is greater than or equal to the first preset threshold Determine the first hair sub-region 301 based on the pixels, and determine the second hair sub-region such as the region composed of regions 302 and 303 based on the first pixel value, such as pixels whose RGB values are smaller than the first preset threshold. This achieves the division of the hair region into two layers or parts.
  • step S103 can be executed.
  • the layering of the hair region can be realized through the erosion operation of the mask of the hair region in the original image, so that part of the hair region can be processed to add the hair flow special effect picture, so that the flexibility of adding the hair flow special effect is relatively high.
  • the quality of the hair flow special effect picture is better, such as continuous hair flow and high fidelity of the flow special effect picture.
  • the corrosion operation based on the above corrosion parameters can improve the accuracy of the results of the corrosion operation, and further improve the accuracy of the layering results of the hair area, so that the accuracy of the position of the subsequent addition of hair flow special effects is improved, and the hair flow special effect picture is improved. quality.
  • obtaining the corrosion parameters required for the corrosion operation in the above step S201 may specifically include: obtaining the corrosion parameters required for the corrosion operation through a specified Lua code running in a central processing unit (CPU).
  • CPU central processing unit
  • Lua is currently the most popular, lightweight embedded scripting language.
  • the specified Lua code to run can configure the buffer RT, and configure erosion parameters such as pixel width widthOffset and pixel height heightOffset in the buffer RT, and read from the buffer RT when using Get the erosion parameters required by the erosion operation, such as pixel width widthOffset and pixel height heightOffset.
  • the advantages of Lua code can be used to improve the processing efficiency when adding hair flow special effects.
  • an erosion operation is performed on the mask, so as to implement layering on the hair region to obtain multiple hair sub-regions, Specifically, it may include: performing an erosion operation on the mask by using a shader (Shader) running in a graphics processing unit (GPU), so as to implement layering on the hair region to obtain multiple hair sub-regions.
  • a shader Shader
  • GPU graphics processing unit
  • the erosion parameters required by the Shader for the erosion operation may be acquired by a specified Lua code running in the CPU.
  • the efficiency of the erosion operation is improved, and the overall processing efficiency when adding hair flow effects is improved.
  • the method may further include the following steps:
  • Step S401 Based on the pixel width and/or pixel height, perform a pixel-by-pixel erosion operation on the second hair sub-region to obtain second erosion result data, the second erosion result data including the second hair The second pixel value corresponding to each pixel in the sub-region.
  • the pixel width widthOffset and pixel height heightOffset are read from the buffer RT, based on the pixel width and/or pixel height, a pixel-by-pixel erosion operation is performed on the second hair sub-region, and the intermediate result of the erosion operation can be written into the buffer area RT, and finally obtain the second corrosion result data, that is, the second pixel value corresponding to each pixel point in the second hair sub-region, such as the RGB value.
  • Step S402 Comparing the value of each second pixel in the second corrosion result data with a second preset threshold, and determining the third hair based on the pixels whose second pixel values are greater than or equal to the second preset threshold A sub-region; wherein, the second preset threshold is smaller than the first preset threshold.
  • the second preset threshold can also be set as required, which is not limited.
  • compare the size of each second pixel value in the second corrosion result data, such as the RGB value, with the second preset threshold, based on the second pixel value, such as the RGB value being greater than or equal to the second preset threshold The pixel points determine the third hair sub-region such as the region 303 .
  • the hair region is divided into three layers or three parts.
  • the number of specific layers can be set as required. This implementation This example is not limited.
  • the flexible layering of the hair region can be realized by performing multiple corrosion operations on the mask of the hair region in the original image, so as to process part of the hair region to add a hair flow special effect picture, so that the hair flow special effect can be added
  • the flexibility is better to meet the needs of different users to add hair flow special effects.
  • the method may further include the following steps:
  • Step S501 Obtain the first adjustment coefficient corresponding to each hair sub-region; wherein, the first adjustment coefficients corresponding to different hair sub-regions are different.
  • the first adjustment coefficient can be preset, for example, it can be customized according to different display effect requirements of the hair special effect screen, and the first adjustment coefficient corresponding to different hair sub-regions, that is, different layers of hair after layering is different.
  • determining the second hair flow data corresponding to each of the hair sub-regions may specifically include:
  • Step S502 Based on the first adjustment coefficient corresponding to each of the hair sub-regions and the first hair flow data, determine the second hair flow data corresponding to each of the hair sub-regions.
  • the first hair flow data includes the flow distance x along the X direction and/or the flow distance y along the Y direction of each pixel point P in the hair region, and each hair subregion calculated based on the first hair flow data
  • the corresponding second hair flow data that is, the flow velocity of each pixel in each hair sub-region may not be ideal, and it is necessary to control and adjust the flow velocity to make it ideal such as to meet the requirements of the controllable target velocity. Therefore, in this embodiment, the adjustment can be made according to the first adjustment coefficient corresponding to each hair sub-region, so that the second hair flow data, that is, the flow speed of each pixel in each hair sub-region is controllable.
  • the calculated flow velocity of each pixel point such as the flow velocity in the X direction and the flow velocity in the Y direction are multiplied by the first adjustment coefficient to be adjusted After the flow velocity of each pixel, such as the adjusted flow velocity of each pixel along the X direction and the flow velocity of the Y direction are obtained.
  • the flow speed of each pixel in each hair sub-region is adjusted so that it can be controlled at the target speed requirement, and the flow velocity corresponding to each hair sub-region
  • the different first adjustment coefficients can make the finally displayed hair flow special effects different, so as to meet the demand for personalized hair flow special effects.
  • step S502 based on the first adjustment coefficient corresponding to each of the hair sub-regions and the first hair flow data, determine each Before the second hair flow data corresponding to the hair sub-region, the method may further include step A: performing normalization processing on the first hair flow data to obtain target hair flow data.
  • the first hair flow data includes the flow distance x along the X direction and/or the flow distance y along the Y direction of each pixel point P in the hair region, where the values of x and y are usually small, generally between - Between 0.02 and 0.02. Therefore, the calculation and processing directly based on the first hair flow data has a large quantization error, which is not convenient for calculation and processing. Therefore, in this embodiment, normalization processing is first performed on the first hair flow data, and then subsequent calculation processing is performed.
  • determining the second hair flow data corresponding to each of the hair sub-regions may specifically include: Based on the first adjustment coefficient corresponding to each of the hair sub-regions and the target hair flow data, second hair flow data corresponding to each of the hair sub-regions is determined.
  • the flow distance x of one pixel point along the X direction is normalized to obtain x', and x' is divided by a unit time such as 1 second to obtain the pixel point along the X direction
  • the flow velocity v of the pixel point is multiplied by the corresponding first adjustment coefficient to obtain the adjusted flow velocity v' of the pixel along the X direction, and the value of the flow velocity v' is between 0 and 1 , other pixels are also processed in the same way; in addition, the data processing method in the Y direction is also the same way, and will not be repeated here.
  • step A normalization processing is performed on the first hair flow data, and before the target hair flow data is obtained, the method may further include step B: determining each hair region in the original image The maximum and minimum values of the flow distance of the pixel.
  • step A normalization processing is performed on the first hair flow data to obtain target hair flow data, which may specifically include step A': based on the maximum and minimum values of the flow distance, the first The hair flow data is normalized to obtain the target hair flow data.
  • step A' based on the maximum value and the minimum value of the flow distance, the first hair flow data is normalized to obtain the target hair flow data, which may specifically include the following steps: calculating the The difference between the maximum value and the minimum value of the above-mentioned flow distance;
  • x' x*(x max -x min )+x min ;
  • x' is the target hair flow data corresponding to the pixel point, that is, the normalized flow distance
  • x max is the maximum value of the flow distance in the X direction
  • x min is the minimum value of the flow distance in the X direction.
  • y' y*(Y max -Y min )+Y min ;
  • y' is the target hair flow data corresponding to the pixel point, that is, the normalized flow distance
  • Y max is the maximum value of the flow distance in the Y direction
  • Y min is the minimum value of the flow distance in the Y direction.
  • step S104 may specifically include the following steps:
  • the time parameter t may be a time stamp, such as "384289346932.832897".
  • the second hair flow data is the flow velocity of each pixel in the corresponding hair sub-region, so the time parameter t is multiplied by the flow velocity of each pixel to obtain the corresponding third hair flow data, that is, each pixel
  • the first flow offset of a point is the offset distance.
  • the second flow offset can be determined.
  • a hair flow offset region ie, the hair subregion is shifted from one original location region to another location region over time.
  • a first pixel value such as an RGB value of a position corresponding to the first hair flow offset area in the original image is obtained by sampling.
  • the acquired first pixel value such as the RGB value of the position corresponding to the first hair flow offset region
  • hair flow special effect image data such as RGB value data
  • the preset number of frames can be set as required, and there is no limit to this.
  • a hair flow special effect video is generated based on the obtained hair flow special effect image data with a preset number of frames, such as 5 frames, and each frame of hair flow special effect image data corresponds to one frame of image.
  • the layering of the hair region can be realized through the corrosion operation of the mask of the hair region in the original image, so that part of the hair region can be processed to add the hair flow special effect picture, so that the flexibility of adding the hair flow special effect is relatively high. Good, to meet the needs of different users to add hair flow special effects.
  • the time is continuously changing. Add time parameters to realize the hair flow special effect picture. .
  • the method may further include the following steps:
  • the second adjustment coefficient can be set as required, which is not limited.
  • the remainder can be obtained by using the remainder function MOD.
  • determining the corresponding third hair flow data may specifically include: based on the second parameter value and The second hair flow data corresponding to each hair sub-region is used to determine the corresponding third hair flow data.
  • the second parameter value a f is obtained based on the time parameter t, which is essentially a time parameter, so the second hair flow data corresponding to each hair sub-region is the flow velocity of each pixel multiplied by the second parameter value a f , the corresponding third hair flow data, that is, the first flow offset of each pixel, that is, the offset distance can be obtained. Then execute step c) to step d.
  • determining the hair flow special effect image data based on the first pixel value corresponding to the first hair flow offset area may specifically include: based on the first pixel value corresponding to the first hair flow offset area, and The second parameter value is determined as the first hair flow special effect image data as the hair flow special effect image data.
  • the first hair flow special effect image data such as RGB value data is generated based on the obtained first pixel value such as the RGB value of the position corresponding to the first hair flow offset area and multiplied by the second parameter value a f , and used as the The above-mentioned hair flow special effect image data, then return to step a) until the hair flow special effect image data of the preset frame number is obtained, and then perform step f).
  • the time parameter is added to realize the hair flow special effect picture, wherein the time parameter is multiplied by the second adjustment coefficient and the remainder is taken before subsequent calculation, which can ensure the periodicity of the hair flow in the generated hair flow special effect and enrich the hair flow.
  • the picture quality of hair flow special effect is good, such as the continuity of hair flow is good, and the fidelity of hair flow special effect picture is improved.
  • the method may further include the following steps:
  • Step 1) Determine a third parameter value based on the second parameter value, where the sum of the third parameter value and the second parameter value is equal to one.
  • the third parameter value a r 1-a f .
  • Step 2) Based on the third parameter value and the second hair flow data corresponding to each of the hair sub-regions, determine the corresponding fourth hair flow data, each of the fourth hair flow data includes the corresponding hair sub-region The second flow offset for each pixel in the region.
  • the third parameter value a r is also obtained based on the time parameter t, which is also a time parameter in nature, so the second hair flow data corresponding to each hair sub-region, that is, the flow speed of each pixel point can also be multiplied by the third
  • the parameter value a r obtains the corresponding fourth hair flow data, that is, the second flow offset of each pixel point, that is, the offset distance.
  • Step 3) Obtaining a second hair flow offset region based on each of the fourth hair flow data and the original image.
  • the second flow offset can be determined.
  • Two hair flow offset areas that is, the hair sub-area is offset from one original position area to another position area as time changes.
  • Step 4) acquiring a second pixel value corresponding to the second hair flow offset region in the original image.
  • a second pixel value such as an RGB value of a position corresponding to the second hair flow offset area in the original image is obtained by sampling.
  • Step 5 Based on the second pixel value corresponding to the second hair flow offset area and the third parameter value, determine the second hair flow special effect image data;
  • the second hair flow special effect image data such as RGB value data
  • Step 6) Determine the hair flow special effect image data based on the second hair flow special effect image data and the first hair flow special effect image data.
  • the final hair flow special effect image data is generated based on the second hair flow special effect image data such as RGB value data and the first hair flow special effect image data such as RGB value data.
  • two flow offsets are respectively determined based on the second parameter value and the third parameter value, and then two hair flow offset areas are determined, and then based on the corresponding positions of the two hair flow offset areas in the original image
  • the pixel values of the hair flow special effect, the second parameter value and the third parameter value are fused to generate the final hair flow special effect image data, so that the image quality of the hair flow special effect, such as the fidelity of the image, can be further improved.
  • An embodiment of the present disclosure provides a special effect processing device for portrait hair flow.
  • the special effect processing device for portrait hair flow may include:
  • a data determination module 601 configured to determine the mask of the hair region in the original image and the first hair flow data, the first hair flow data includes the flow distance of each pixel of the hair region along a preset flow direction;
  • a hair layering module 602 configured to perform an erosion operation on the mask, so as to layer the hair region to obtain multiple hair subregions;
  • a data calculation module 603, configured to determine the second hair flow data corresponding to each of the hair sub-regions based on the first hair flow data; wherein, each of the second hair flow data includes the corresponding hair sub-region The flow velocity of each pixel in the area;
  • the special effect processing module 604 is configured to acquire a time parameter, and generate a hair flow special effect video based on the time parameter, the second hair flow data corresponding to each of the hair sub-regions, and the original image.
  • the device further includes a parameter obtaining module, configured to obtain corrosion parameters required for the corrosion operation, where the corrosion parameters include pixel width and/or pixel height.
  • the hair layering module 602 is further configured to perform a pixel-by-pixel erosion operation on the mask based on the pixel width and/or pixel height to obtain first erosion result data, the first erosion result data including The first pixel value corresponding to each pixel point in the mask; comparing each first pixel value in the first corrosion result data with the first preset threshold value, based on the first pixel value being greater than or equal to the first pixel value
  • the first hair sub-region is determined based on the pixels of the first preset threshold, and the second hair sub-region is determined based on the pixels whose first pixel value is smaller than the first preset threshold.
  • the parameter obtaining module is configured to obtain the corrosion parameters required by the corrosion operation through a specified Lua code running in the central processing unit.
  • the hair layering module 602 is configured to perform an erosion operation on the mask through a shader running in a graphics processor, so as to implement layering on the hair region to obtain multiple hair sub-regions.
  • the hair layering module 602 is further configured to perform a pixel-by-pixel erosion operation on the second hair sub-region based on the pixel width and/or pixel height to obtain second erosion result data , the second corrosion result data includes a second pixel value corresponding to each pixel point in the second hair sub-region; compare each second pixel value in the second corrosion result data with a second preset threshold The size of the third hair sub-region is determined based on the pixel points whose second pixel value is greater than or equal to the second preset threshold; wherein the second preset threshold is smaller than the first preset threshold.
  • the device further includes a coefficient acquisition module, configured to acquire a first adjustment coefficient corresponding to each of the hair sub-regions; wherein, the first adjustment coefficients corresponding to different hair sub-regions are different.
  • the data calculation module 603 is configured to determine the second hair flow data corresponding to each hair sub-region based on the first adjustment coefficient corresponding to each hair sub-region and the first hair flow data.
  • the device may further include a normalization processing module, configured to, in the data calculation module, based on the first adjustment coefficient corresponding to each of the hair sub-regions and the first hair flow data, Before determining the second hair flow data corresponding to each of the hair sub-regions, the first hair flow data is normalized to obtain target hair flow data.
  • the data calculation module is configured to determine the second hair flow data corresponding to each hair sub-region based on the first adjustment coefficient corresponding to each hair sub-region and the target hair flow data.
  • the data determination module is further configured to determine the hair in the original image before the normalization processing module performs normalization processing on the first hair flow data to obtain the target hair flow data.
  • the normalization processing module is configured to perform normalization processing on the first hair flow data based on the maximum and minimum values of the flow distance to obtain target hair flow data.
  • the normalization processing module is used to: calculate the difference between the maximum value and the minimum value of the flow distance; respectively calculate the difference between the flow distance corresponding to each pixel in the first hair flow data and the The product value of the difference; respectively calculate the sum of the product value corresponding to each pixel point in the first hair flow data and the minimum value; based on the value corresponding to each pixel point in the first hair flow data The sum value determines the target hair flow data.
  • the special effect processing module is configured to: obtain a time parameter; determine corresponding third hair flow data based on the time parameter and the second hair flow data corresponding to each of the hair sub-regions, Each of the third hair flow data includes the first flow offset of each pixel in the corresponding hair sub-region; based on each of the third hair flow data and the original image, the first hair flow offset is obtained Obtain the first pixel value corresponding to the first hair flow offset area in the original image; determine the hair flow special effect image data based on the first pixel value corresponding to the first hair flow offset area, and return The step of acquiring the time parameter is until the hair flow special effect image data of the preset frame number is obtained; based on the hair flow special effect image data of the preset frame number, a hair flow special effect video is generated.
  • the device may further include a parameter processing module, configured to multiply the time parameter by a second adjustment coefficient to obtain a first parameter value, and the second adjustment coefficient is a natural number greater than 1; Calculate the remainder of the first parameter value to obtain the second parameter value.
  • the special effect processing module is configured to determine corresponding third hair flow data based on the second parameter value and the second hair flow data corresponding to each of the hair sub-regions.
  • the special effect processing module is further configured to determine first hair flow special effect image data as the hair flow special effect image based on the first pixel value corresponding to the first hair flow offset region and the second parameter value data.
  • the parameter processing module is further configured to determine a third parameter value based on the second parameter value, and the sum of the third parameter value and the second parameter value is equal to one.
  • the special effect processing module is further configured to determine corresponding fourth hair flow data based on the third parameter value and the second hair flow data corresponding to each of the hair sub-regions, each of the fourth hair flow data Including the second flow offset of each pixel in the corresponding hair sub-region; based on each of the fourth hair flow data and the original image to obtain the second hair flow offset area; obtain the original image
  • the hair flow special effect image data is determined based on the second hair flow special effect image data and the first hair flow special effect image data.
  • modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory.
  • the features and functions of two or more modules or units described above may be embodied in one module or unit.
  • the features and functions of one module or unit described above can be further divided to be embodied by a plurality of modules or units.
  • Components shown as modules or units may or may not be physical units, may be located in one place, or may be distributed over multiple network elements. Part or all of the modules can be selected according to actual needs to realize the purpose of the disclosed scheme. It can be understood and implemented by those skilled in the art without creative effort.
  • modules are only logical modules divided according to the specific functions they implement, and are not used to limit specific implementation methods. For example, they can be implemented in software, hardware, or a combination of software and hardware. In actual implementation, each of the above modules may be implemented as an independent physical entity, or may also be implemented by a single entity (for example, a processor (CPU or DSP, etc.), an integrated circuit, etc.). In addition, the above-mentioned various modules are shown with dotted lines in the drawings to indicate that these modules may not actually exist, and the operations/functions realized by them may be realized by the device or the processing circuit itself.
  • the device may also include a memory that can store various information generated in operation by the device, each module included in the device, programs and data for operations, data to be transmitted by the communication unit, etc. .
  • the memory can be volatile memory and/or non-volatile memory.
  • memory may include, but is not limited to, random access memory (RAM), dynamic random access memory (DRAM), static random access memory (SRAM), read only memory (ROM), flash memory.
  • RAM random access memory
  • DRAM dynamic random access memory
  • SRAM static random access memory
  • ROM read only memory
  • flash memory any type of volatile memory
  • the memory could also be located external to the device.
  • An embodiment of the present disclosure also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method for processing the flow special effect of human portrait hair described in any one of the above-mentioned embodiments are implemented.
  • the readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any combination thereof. More specific examples (non-exhaustive list) of readable storage media include: electrical connection with one or more conductors, portable disk, hard disk, random access memory (RAM), read only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
  • RAM random access memory
  • ROM read only memory
  • EPROM or flash memory erasable programmable read-only memory
  • CD-ROM compact disk read-only memory
  • optical storage devices magnetic storage devices, or any suitable combination of the foregoing.
  • the computer readable storage medium may include a data signal carrying readable program code in baseband or as part of a carrier wave traveling as a data signal. Such propagated data signals may take many forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing.
  • a readable storage medium may also be any readable medium other than a readable storage medium that can send, propagate or transport a program for use by or in conjunction with an instruction execution system, apparatus or device.
  • the program code contained on the readable storage medium may be transmitted by any suitable medium, including but not limited to wireless, cable, optical cable, RF, etc., or any suitable combination of the above.
  • the present disclosure provides a computer program product, the computer program product comprising computer programs or instructions, which, when run on a computer, cause the computer to execute The steps of the method for processing the flowing special effects of human portrait hair according to any one of the above-mentioned embodiments.
  • the present disclosure provides a computer program, the program code included in the computer program, when executed by a computer, enables the computer to implement the method for processing human hair flow special effects described in any of the above embodiments A step of.
  • the electronic device may include a processor 701 and a memory 702, and the memory 702 is used to store a computer program.
  • the processor 701 is configured to execute the steps of the method for processing the flowing special effect of human portrait hair in any one of the above-mentioned embodiments by executing the computer program.
  • the electronic device may be a smart phone, a tablet computer, etc., which is not limited in this embodiment.

Landscapes

  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Image Processing (AREA)

Abstract

本公开涉及一种人像头发流动特效处理方法、装置、介质和电子设备,其中方法包括:确定原始图像中头发区域的掩膜以及第一头发流动数据,所述第一头发流动数据包括所述头发区域每个像素点沿预设流动方向的流动距离;对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域;基于所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据;其中每个所述第二头发流动数据包括对应的所述头发子区域每个像素点的流动速度;获取时间参数,基于所述时间参数、每个所述头发子区域对应的第二头发流动数据以及所述原始图像,生成头发流动特效视频。

Description

人像头发流动特效处理方法、装置、介质和电子设备
相关申请的交叉引用
本申请是以申请号为202111477583.3、申请日为2021年12月06日的中国申请为基础,并主张其优先权,该中国申请的公开内容在此作为整体引入本申请中。
技术领域
本公开实施例涉及图像处理技术领域,尤其涉及一种人像头发流动特效处理方法,人像头发流动特效处理装置,以及实现人像头发流动特效处理方法的计算机可读存储介质和电子设备。
背景技术
随着短视频的广泛传播和视频处理技术的提升,视频处理方式变得丰富多样,其中,在视频中添加特效越来越流行。
相关技术中可在视频中人像区域添加头发流动特效画面,从而提高视频的趣味性和视觉效果。但是目前添加时视频中人像的头发区域整个都会被处理,无法实现对部分头发区域处理以添加头发流动特效画面,使得头发流动特效添加的灵活性较差,头发流动特效画面逼真度也较低。
发明内容
为了解决上述技术问题或者至少部分地解决上述技术问题,本公开实施例提供了一种人像头发流动特效处理方法,人像头发流动特效处理装置,以及实现人像头发流动特效处理方法的计算机可读存储介质和电子设备。
第一方面,本公开实施例提供了一种人像头发流动特效处理方法,包括:
确定原始图像中头发区域的掩膜以及第一头发流动数据,所述第一头发流动数据包括所述头发区域每个像素点沿预设流动方向的流动距离;
对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域;
基于所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据;其中,每个所述第二头发流动数据包括对应的所述头发子区域每个像素点的流动速度;
获取时间参数,基于所述时间参数、每个所述头发子区域对应的第二头发流动数据以及所述原始图像,生成头发流动特效视频。
在本公开的一些实施例中,所述方法还包括:
获取腐蚀操作所需的腐蚀参数,所述腐蚀参数包括像素宽度和/或像素高度;
所述对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域,包括:
基于所述像素宽度和/或像素高度,对所述掩膜进行逐像素点的腐蚀操作,得到第一腐蚀结果数据,所述第一腐蚀结果数据包括所述掩膜中每个像素点对应的第一像素值;
比较所述第一腐蚀结果数据中的每个第一像素值与第一预设阈值的大小,基于第一像素值大于或等于所述第一预设阈值的像素点确定第一头发子区域,基于第一像素值小于所述第一预设阈值的像素点确定第二头发子区域。
在本公开的一些实施例中,所述获取腐蚀操作所需的腐蚀参数,包括:
通过中央处理器(CPU)中运行的指定Lua代码获取腐蚀操作所需的所述腐蚀参数;
和/或,
所述对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域,包括:
通过图形处理器(GPU)中运行的着色器(Shader)对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域。
在本公开的一些实施例中,所述方法还包括:
基于所述像素宽度和/或像素高度,对所述第二头发子区域进行逐像素点的腐蚀操作,得到第二腐蚀结果数据,所述第二腐蚀结果数据包括所述第二头发子区域中每个像素点对应的第二像素值;
比较所述第二腐蚀结果数据中的每个第二像素值与第二预设阈值的大小,基于第二像素值大于或等于所述第二预设阈值的像素点确定第三头发子区域;其中,所述第二预设阈值小于所述第一预设阈值。
在本公开的一些实施例中,所述方法还包括:
获取每个所述头发子区域对应的第一调节系数;其中,不同的所述头发子区域对应的第一调节系数不同;
所述基于所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据,包括:
基于每个所述头发子区域对应的第一调节系数,以及所述第一头发流动数据,确定每 个所述头发子区域对应的第二头发流动数据。
在本公开的一些实施例中,所述基于每个所述头发子区域对应的第一调节系数,以及所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据之前,所述方法还包括:
对所述第一头发流动数据进行归一化处理,得到目标头发流动数据;
所述基于每个所述头发子区域对应的第一调节系数,以及所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据,包括:
基于每个所述头发子区域对应的第一调节系数,以及所述目标头发流动数据,确定每个所述头发子区域对应的第二头发流动数据。
在本公开的一些实施例中,所述对所述第一头发流动数据进行归一化处理,得到目标头发流动数据之前,所述方法还包括:
确定所述原始图像中头发区域中每个像素点的流动距离的最大值和最小值;
所述对所述第一头发流动数据进行归一化处理,得到目标头发流动数据,包括:
基于所述流动距离的最大值和最小值,对所述第一头发流动数据进行归一化处理,得到目标头发流动数据。
在本公开的一些实施例中,基于所述流动距离的最大值和最小值,对所述第一头发流动数据进行归一化处理,得到目标头发流动数据,包括:
计算所述流动距离的最大值和最小值的差值;
分别计算所述第一头发流动数据中每个像素点对应的流动距离与所述差值的乘积值;
分别计算所述第一头发流动数据中每个像素点对应的所述乘积值与所述最小值的和值;
基于所述第一头发流动数据中每个像素点对应的所述和值,确定所述目标头发流动数据。
在本公开的一些实施例中,所述获取时间参数,基于所述时间参数、每个所述头发子区域对应的第二头发流动数据以及所述原始图像,生成头发流动特效视频,包括:
获取时间参数;
基于所述时间参数,以及每个所述头发子区域对应的第二头发流动数据,确定对应的第三头发流动数据,每个所述第三头发流动数据包括对应的头发子区域中每个像素点的第一流动偏移量;
基于每个所述第三头发流动数据,以及所述原始图像得到第一头发流动偏移区域;
获取所述原始图像中所述第一头发流动偏移区域对应的第一像素值;
基于所述第一头发流动偏移区域对应的第一像素值,确定头发流动特效图像数据,返回所述获取时间参数的步骤,直至得到预设帧数的头发流动特效图像数据;
基于所述预设帧数的头发流动特效图像数据,生成头发流动特效视频。
在本公开的一些实施例中,所述方法还包括:
对所述时间参数乘以第二调节系数,得到第一参数值,所述第二调节系数是大于1的自然数;
对所述第一参数值求余数,得到第二参数值;
所述基于所述时间参数,以及每个所述头发子区域对应的第二头发流动数据,确定对应的第三头发流动数据,包括:
基于所述第二参数值以及每个所述头发子区域对应的第二头发流动数据,确定对应的第三头发流动数据;
所述基于所述第一头发流动偏移区域对应的第一像素值,确定头发流动特效图像数据,包括:
基于所述第一头发流动偏移区域对应的第一像素值,以及所述第二参数值,确定第一头发流动特效图像数据并作为所述头发流动特效图像数据。
在本公开的一些实施例中,所述方法还包括:
基于所述第二参数值,确定第三参数值,所述第三参数值与所述第二参数值之和等于一;
基于所述第三参数值以及每个所述头发子区域对应的第二头发流动数据,确定对应的第四头发流动数据,每个所述第四头发流动数据包括对应的头发子区域中每个像素点的第二流动偏移量;
基于每个所述第四头发流动数据,以及所述原始图像得到第二头发流动偏移区域;
获取所述原始图像中所述第二头发流动偏移区域对应的第二像素值;
基于所述第二头发流动偏移区域对应的第二像素值,以及所述第三参数值,确定第二头发流动特效图像数据;
基于所述第二头发流动特效图像数据、所述第一头发流动特效图像数据,确定所述头发流动特效图像数据。
第二方面,本公开实施例提供一种人像头发流动特效处理装置,包括:
数据确定模块,用于确定原始图像中头发区域的掩膜以及第一头发流动数据,所述第一头发流动数据包括所述头发区域每个像素点沿预设流动方向的流动距离;
头发分层模块,用于对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域;
数据计算模块,用于基于所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据;其中,每个所述第二头发流动数据包括对应的所述头发子区域每个像素点的流动速度;
特效处理模块,用于获取时间参数,基于所述时间参数、每个所述头发子区域对应的第二头发流动数据以及所述原始图像,生成头发流动特效视频。
第三方面,本公开实施例提供一种计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现上述任一实施例所述人像头发流动特效处理方法的步骤。
第四方面,本公开实施例提供一种电子设备,包括:
处理器;以及
存储器,用于存储计算机程序;
其中,所述处理器配置为经由执行所述计算机程序来执行上述任一实施例所述人像头发流动特效处理方法的步骤。
第五方面,本公开实施例提供一种计算机程序产品,所述计算机程序产品包含计算机程序或指令,当所述计算机程序或指令在计算机上运行时,使得所述计算机执行上述任一实施例所述人像头发流动特效处理方法的步骤。
第六方面,本公开实施例提供一种计算机程序,所述计算机程序包括的程序代码在由计算机执行时使得计算机执行上述任一实施例所述人像头发流动特效处理方法的步骤。
本公开实施例提供的人像头发流动特效处理方法、装置、介质和电子设备,确定原始图像中头发区域的掩膜以及第一头发流动数据,所述第一头发流动数据包括所述头发区域每个像素点沿预设流动方向的流动距离;对所述掩膜进行腐蚀操作以对所述头发区域实现分层得到多个头发子区域;基于所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据,其中每个所述第二头发流动数据包括对应的所述头发子区域每个像素点的流动速度;获取时间参数,基于所述时间参数、每个所述头发子区域对应的第二头发流动数据以及所述原始图像,生成头发流动特效视频。这样,本实施例中可以通过对原始 图像中头发区域的掩膜的腐蚀操作实现对头发区域的分层,从而可以实现对部分头发区域如一个或多个头发子区域处理以添加头发流动特效画面,使得头发流动特效添加的灵活性较好,满足不同用户个性化添加头发流动特效的需求,另外,加入时间参数实现头发流动特效画面,头发流动特效画面质量较好,如头发流动连续、流动特效画面逼真度较高等。
附图说明
此处的附图被并入说明书中并构成本说明书的一部分,示出了符合本公开的实施例,并与说明书一起用于解释本公开的原理。
为了更清楚地说明本公开实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,对于本领域普通技术人员而言,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。
图1为本公开实施例人像头发流动特效处理方法流程图;
图2为本公开另一实施例人像头发流动特效处理方法流程图;
图3为本公开实施例腐蚀操作对头发区域分层效果示意图;
图4为本公开又一实施例人像头发流动特效处理方法流程图;
图5为本公开再一实施例人像头发流动特效处理方法流程图;
图6为本公开实施例人像头发流动特效处理装置示意图;
图7为本公开实施例实现人像头发流动特效处理方法的电子设备示意图。
具体实施方式
为了能够更清楚地理解本公开的上述目的、特征和优点,下面将对本公开的方案进行进一步描述。需要说明的是,在不冲突的情况下,本公开的实施例及实施例中的特征可以相互组合。
在下面的描述中阐述了很多具体细节以便于充分理解本公开,但本公开还可以采用其他不同于在此描述的方式来实施;显然,说明书中的实施例只是本公开的一部分实施例,而不是全部的实施例。
应当理解,在下文中,“至少一个(项)”是指一个或者多个,“多个”是指两个或两个以上。“和/或”用于描述关联对象的关联关系,表示可以存在三种关系,例如,“A和/或B”可以表示:只存在A,只存在B以及同时存在A和B三种情况,其中A,B可以是单数或者复数。字符“/”一般表示前后关联对象是一种“或”的关系。“以下至少一项(个)”或其类似表达,是 指这些项中的任意组合,包括单项(个)或复数项(个)的任意组合。例如,a,b或c中的至少一项(个),可以表示:a,b,c,“a和b”,“a和c”,“b和c”,或“a和b和c”,其中a,b,c可以是单个,也可以是多个。
图1为本公开实施例示出的人像头发流动特效处理方法流程图,该方法可以由电子设备如智能手机等执行,具体可以包括以下步骤:
步骤S101:确定原始图像中头发区域的掩膜以及第一头发流动数据,所述第一头发流动数据包括所述头发区域每个像素点沿预设流动方向的流动距离。
示例性的,本实施例中可以对原始图像中的人物的头部的头发区域分割得到掩膜(mask),便于后续对图像中的头发区域进行处理。预设流动方向可以包括二维平面的X方向即左右方向和Y方向即上下方向,第一头发流动数据可以包括头发区域每个像素点P沿X方向的流动距离x(-1≤x≤1)和/或沿Y方向的流动距离y(-1≤y≤1),也即预测的沿X方向和Y方向各自的偏移距离,流动距离x的绝对值小于等于1个像素宽度,流动距离y的绝对值小于等于1个像素高度,x和y的取值可以是正值,也可以是负值,x取正值表示流动方向为右,x取负值表示流动方向为左,y取正值表示流动方向为上,y取负值表示流动方向为下。
步骤S102:对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域。
具体的,可以对头发区域的mask进行二值化处理,然后进行腐蚀(Erode)操作。腐蚀操作是图像处理中形态学操作中的一种,以模板像素结构的中心点为准心,在图像中找能满足模板像素结构的像素点即为腐蚀,例如移动模板像素结构,如果模板像素结构与图像的交集(包括至少一个像素点)完全属于图像的区域内,则保存该交集中的像素点,然后继续移动模板像素结构进行腐蚀操作,直至所有满足条件的交集中的像素点构成图像被模板像素结构腐蚀的结果。其中模板像素结构例如是像素高度乘以像素宽度的矩形结构,但也不限于此。
本实施例中通过腐蚀操作实现对图像中的头发区域进行分层,以得到多个头发子区域,每个头发子区域是头发区域中的一部分。其中可以进行多次腐蚀操作,具体次数可以根据需要设置,对此不作限制,头发子区域的数量也可根据需要确定,本实施例中对此也不作限制。
步骤S103:基于所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流 动数据;其中,每个所述第二头发流动数据包括对应的所述头发子区域每个像素点的流动速度。
示例性的,第一头发流动数据如头发区域每个像素点P沿X方向的流动距离x和/或沿Y方向的流动距离y,基于第一头发流动数据如每个像素点P i沿X方向的流动距离x i和/或沿Y方向的流动距离y i以及时间,确定每个头发子区域的第二头发流动数据即每个头发子区域中每个像素点的流动速度。例如头发区域包括10000个像素点,而分层后的头发子区域1包括3000个像素点,头发子区域2包括5000个像素点,头发子区域3包括2000个像素点,那么基于头发子区域1中3000个像素点各自对应的沿X方向的流动距离x和/或沿Y方向的流动距离y,除以单位时间如1秒得到头发子区域1中各个像素点的流动速度,如X方向的流动速度和/或沿Y方向的流动速度。
步骤S104:获取时间参数,基于所述时间参数、每个所述头发子区域对应的第二头发流动数据以及所述原始图像,生成头发流动特效视频。
示例性的,时间参数可以是当前时间的时间戳,但不限于此。在得到例如头发子区域1中各个像素点的流动速度之后,与时间参数相乘可以确定头发子区域1中各个像素点的流动距离即从原始位置偏移后的距离,从而确定偏移后头发子区域1中各个像素点的位置区域,然后在该位置区域结合原始图像融合生成头发流动特效视频,其他头发子区域也是相同的处理,最终得到整个的头发流动特效视频。例如将静态用户照片自动生成头发区域发丝流动漂浮特效视频画面。
本实施例中可以通过对原始图像中头发区域的掩膜的腐蚀操作实现对头发区域的分层,从而可以实现对部分头发区域处理以添加头发流动特效画面,使得头发流动特效添加的灵活性较好,满足不同用户个性化添加头发流动特效的需求,另外,加入时间参数实现头发流动特效画面,头发流动特效画面质量较好,如头发流动连续、流动特效画面逼真度较高等。
在上述实施例的基础上,在一个实施例中,如图2所示,所述方法还可以包括步骤201:获取腐蚀操作所需的腐蚀参数,所述腐蚀参数包括像素宽度和/或像素高度。
示例性的,腐蚀操作是逐像素点的操作,需要知道一个像素点周围的像素点的位置,腐蚀参数可以是像素宽度widthOffset和/或像素高度heightOffset,这样便于腐蚀操作时的逐像素点偏移,如模板像素结构从一个像素点位置移动一个像素宽度和/或像素高度到达另一个像素点位置。实际处理时可以配置缓冲区RT,用来记录腐蚀操作的中间过程,腐蚀参 数如像素宽度widthOffset和像素高度heightOffset可以存储于缓冲区RT。
步骤S102中对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域,具体可以包括以下步骤:
步骤S202:基于所述像素宽度和/或像素高度,对所述掩膜进行逐像素点的腐蚀操作,得到第一腐蚀结果数据,所述第一腐蚀结果数据包括所述掩膜中每个像素点对应的第一像素值。
示例性的,从所述缓冲区RT中读取像素宽度widthOffset和像素高度heightOffset,基于像素宽度和/或像素高度对掩膜进行逐像素点的腐蚀操作,腐蚀操作的中间结果可以写入缓冲区RT,最终得到第一腐蚀结果数据即掩膜中每个像素点对应的第一像素值如RGB值。
步骤S203:比较所述第一腐蚀结果数据中的每个第一像素值与第一预设阈值的大小,基于第一像素值大于或等于所述第一预设阈值的像素点确定第一头发子区域,基于第一像素值小于所述第一预设阈值的像素点确定第二头发子区域。
示例性的,第一预设阈值可以根据需要设置,对此不作限制。结合图3中所示,比较第一腐蚀结果数据中的每个第一像素值如RGB值与第一预设阈值的大小,基于第一像素值如RGB值大于或等于第一预设阈值的像素点确定第一头发子区域301,基于第一像素值如RGB值小于第一预设阈值的像素点确定第二头发子区域如区域302和303组成的区域。这样即实现将头发区域分成两层即两部分。步骤S203之后即可跳转执行步骤S103。
本实施例中可以通过对原始图像中头发区域的掩膜的腐蚀操作实现对头发区域的分层,从而可以实现对部分头发区域处理以添加头发流动特效画面,使得头发流动特效添加的灵活性较好,满足不同用户个性化添加头发流动特效的需求,另外,加入时间参数实现头发流动特效画面,头发流动特效画面质量较好,如头发流动连续、流动特效画面逼真度较高等。另外,基于上述腐蚀参数进行腐蚀操作,可以提高腐蚀操作的结果的准确性,进而提高对头发区域的分层结果的准确性,使得后续添加头发流动特效的位置准确性提高,提升头发流动特效画面质量。
在一个实施例中,上述步骤S201中获取腐蚀操作所需的腐蚀参数,具体可以包括:通过中央处理器(CPU)中运行的指定Lua代码获取腐蚀操作所需的所述腐蚀参数。
具体的,Lua是目前最为流行的、轻量级嵌入式脚本语言。通过编写指定的Lua代码,并运行于CPU中,该运行的指定Lua代码可以配置缓冲区RT,并在缓冲区RT中配置腐蚀参数如像素宽度widthOffset和像素高度heightOffset,使用时从缓冲区RT读取腐蚀操作 所需的该腐蚀参数如像素宽度widthOffset和像素高度heightOffset。如此可以利用Lua代码的优点提升在添加头发流动特效时的处理效率。
在另一个实施例中,或者在上述实施例基础上的又一个实施例中,上述步骤S102中对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域,具体可以包括:通过图形处理器(GPU)中运行的着色器(Shader)对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域。
示例性的,在一个示例中,Shader进行腐蚀操作所需的腐蚀参数可以由CPU中运行的指定Lua代码获取。通过CPU中的指定Lua代码和GPU中的Shader的协同工作,提升了腐蚀操作的效率,进而提升在添加头发流动特效时的整体处理效率。
在上述任一实施例的基础上,在又一个实施例中,如图4所示,所述方法还可以包括以下步骤:
步骤S401:基于所述像素宽度和/或像素高度,对所述第二头发子区域进行逐像素点的腐蚀操作,得到第二腐蚀结果数据,所述第二腐蚀结果数据包括所述第二头发子区域中每个像素点对应的第二像素值。
示例性的,从缓冲区RT中读取像素宽度widthOffset和像素高度heightOffset,基于像素宽度和/或像素高度对第二头发子区域进行逐像素点的腐蚀操作,腐蚀操作的中间结果可以写入缓冲区RT,最终得到第二腐蚀结果数据即第二头发子区域中每个像素点对应的第二像素值如RGB值。
步骤S402:比较所述第二腐蚀结果数据中的每个第二像素值与第二预设阈值的大小,基于第二像素值大于或等于所述第二预设阈值的像素点确定第三头发子区域;其中,所述第二预设阈值小于所述第一预设阈值。
示例性的,第二预设阈值也可以根据需要设置,对此不作限制。再次结合图3中所示,比较第二腐蚀结果数据中的每个第二像素值如RGB值与第二预设阈值的大小,基于第二像素值如RGB值大于或等于第二预设阈值的像素点确定第三头发子区域如区域303。这样即实现将头发区域分成三层即三部分。可选的,也可以继续基于第二像素值如RGB值小于第二预设阈值的像素点确定第四头发子区域实现将头发区域分成四层,具体分层的数量可以根据需要设置,本实施例中对此不作限制。
本实施例中可以通过对原始图像中头发区域的掩膜的多次腐蚀操作实现对头发区域的灵活分层,从而可以实现对部分头发区域处理以添加头发流动特效画面,使得头发流动 特效添加的灵活性较好,满足不同用户个性化添加头发流动特效的需求。
在上述任一实施例的基础上,在又一个实施例中,如图5所示,所述方法还可以包括以下步骤:
步骤S501:获取每个所述头发子区域对应的第一调节系数;其中,不同的所述头发子区域对应的第一调节系数不同。
示例性的,该第一调节系数可以预先设置,例如根据头发特效画面的不同展示效果需求自定义设置,不同头发子区域即分层后不同层的头发对应的第一调节系数不同。
步骤S103中基于所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据,具体可以包括:
步骤S502:基于每个所述头发子区域对应的第一调节系数,以及所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据。
示例性的,第一头发流动数据包括头发区域每个像素点P沿X方向的流动距离x和/或沿Y方向的流动距离y,基于该第一头发流动数据计算得到的每个头发子区域对应的第二头发流动数据即每个头发子区域中每个像素点的流动速度可能并不理想,需要控制调整流动速度使其变得理想如满足可控目标速度的要求。因此本实施例中,可以根据每个头发子区域对应的第一调节系数来进行调整,使得第二头发流动数据即每个头发子区域中每个像素点的流动速度可控。
在一个示例中,针对每个头发子区域如头发子区域1,其中计算得到的各个像素点的流动速度如X方向的流动速度和Y方向的流动速度分别再乘以第一调节系数即得到调整后每个像素点的流动速度,如得到调整后每个像素点沿X方向的流动速度和Y方向的流动速度。
本实施例中,基于每个头发子区域对应的第一调节系数,调整每个头发子区域中每个像素点的流动速度,使其可控在目标速度的要求,每个头发子区域对应的第一调节系数不同,可以使得最终展示的头发流动特效不同,从而满足个性化添加头发流动特效的需求。
为了方便计算处理,提高添加头发流动特效处理的效率,在一个实施例中,步骤S502中基于每个所述头发子区域对应的第一调节系数,以及所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据之前,所述方法还可以包括步骤A:对所述第一头发流动数据进行归一化处理,得到目标头发流动数据。
示例性的,第一头发流动数据包括头发区域每个像素点P沿X方向的流动距离x和/ 或沿Y方向的流动距离y,其中x和y的取值通常较小,一般均在-0.02和0.02之间。因此直接基于第一头发流动数据进行计算处理量化误差较大,不便于计算处理。因此本实施例中先对第一头发流动数据进行归一化处理,之后再进行后续计算处理。
相应的,步骤S502中基于每个所述头发子区域对应的第一调节系数,以及所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据,具体可以包括:基于每个所述头发子区域对应的第一调节系数,以及所述目标头发流动数据,确定每个所述头发子区域对应的第二头发流动数据。
在一个示例中,针对每个头发子区域,例如对其中一个像素点沿X方向的流动距离x归一化处理得到x’,用x’除以单位时间如1秒得到该像素点沿X方向的流动速度v,该流动速度v再乘以对应的第一调节系数,即得到调整后的该像素点沿X方向的流动速度v’,该流动速度v’的取值介于0和1之间,其他像素点也是同样的处理过程;另外,Y方向的数据处理方式也是与此相同的方式,此处不再赘述。
在一个实施例中,步骤A中对所述第一头发流动数据进行归一化处理,得到目标头发流动数据之前,所述方法还可以包括步骤B:确定所述原始图像中头发区域中每个像素点的流动距离的最大值和最小值。相应的,步骤A中对所述第一头发流动数据进行归一化处理,得到目标头发流动数据,具体可以包括步骤A’:基于所述流动距离的最大值和最小值,对所述第一头发流动数据进行归一化处理,得到目标头发流动数据。
在一个实施例中,步骤A’中基于所述流动距离的最大值和最小值,对所述第一头发流动数据进行归一化处理,得到目标头发流动数据,具体可以包括以下步骤:计算所述流动距离的最大值和最小值的差值;
分别计算所述第一头发流动数据中每个像素点对应的流动距离与所述差值的乘积值;分别计算所述第一头发流动数据中每个像素点对应的所述乘积值与所述最小值的和值;基于所述第一头发流动数据中每个像素点对应的所述和值,确定所述目标头发流动数据。
示例性的,针对每个像素点在X方向的流动距离x,以上归一化处理过程可以用以下公式表达:
x’=x*(x max-x min)+x min
其中,x’是像素点对应的目标头发流动数据即归一化后的流动距离,x max是X方向的流动距离的最大值,x min是X方向的流动距离的最小值。
针对每个像素点在Y方向的流动距离y,以上归一化处理过程可以用以下公式表达:
y’=y*(Y max-Y min)+Y min
其中,y’是像素点对应的目标头发流动数据即归一化后的流动距离,Y max是Y方向的流动距离的最大值,Y min是Y方向的流动距离的最小值。
在上述任一实施例的基础上,在一个实施例中,步骤S104具体可以包括以下步骤:
步骤a):获取时间参数t。
示例性的,该时间参数t可以是时间戳,如“384289346932.832897”。
步骤b):基于所述时间参数t,以及每个所述头发子区域对应的第二头发流动数据,确定对应的第三头发流动数据,每个所述第三头发流动数据包括对应的头发子区域中每个像素点的第一流动偏移量。
示例性的,第二头发流动数据即相应头发子区域每个像素点的流动速度,因此时间参数t乘以每个像素点的流动速度,即可得到对应的第三头发流动数据即每个像素点的第一流动偏移量即偏移的距离。
步骤c):基于每个所述第三头发流动数据,以及所述原始图像得到第一头发流动偏移区域。
示例性的,针对每个头发子区域,基于其中每个像素点的第一流动偏移量即偏移的距离与原始图像对应的该每个像素点的原始坐标位置比对,即可确定第一头发流动偏移区域,即随着时间变化,该头发子区域从一个原始位置区域偏移到另一位置区域。
步骤d):获取所述原始图像中所述第一头发流动偏移区域对应的第一像素值。
示例性的,采样获取原始图像中第一头发流动偏移区域对应的位置的第一像素值如RGB值。
步骤e):基于所述第一头发流动偏移区域对应的第一像素值,确定头发流动特效图像数据,返回所述获取时间参数的步骤,直至得到预设帧数的头发流动特效图像数据。
示例性的,基于获取的第一头发流动偏移区域对应的位置的第一像素值如RGB值,生成头发流动特效图像数据如RGB值数据,然后返回步骤a)获取下一时间参数,重复上述过程直至得到预设帧数的头发流动特效图像数据。其中预设帧数可以根据需要设置,对此不作限制。
步骤f):基于所述预设帧数的头发流动特效图像数据,生成头发流动特效视频。
示例性的,基于得到的预设帧数如5帧的头发流动特效图像数据,生成头发流动特效视频,每帧头发流动特效图像数据对应一帧图像。
本实施例中可以通过对原始图像中头发区域的掩膜的腐蚀操作实现对头发区域的分层,从而可以实现对部分头发区域处理以添加头发流动特效画面,使得头发流动特效添加的灵活性较好,满足不同用户个性化添加头发流动特效的需求,另外,时间是连续变化的,加入时间参数实现头发流动特效画面,头发流动特效画面质量如头发流动连续性好,头发流动特效画面逼真度提高。
在上述实施例的基础上,在一个实施例中,所述方法还可以包括以下步骤:
步骤i):对所述时间参数乘以第二调节系数,得到第一参数值,所述第二调节系数是大于1的自然数。
示例性的,第二调节系数可以根据需要设置,对此不作限制。
步骤ii):对所述第一参数值求余数,得到第二参数值。
示例性的,求余数可以采用求余函数MOD得到,例如第二调节系数是4,则第二参数值a f=mod(t*4,1)。
相应的,步骤b)中基于所述时间参数,以及每个所述头发子区域对应的第二头发流动数据,确定对应的第三头发流动数据,具体可包括:基于所述第二参数值以及每个所述头发子区域对应的第二头发流动数据,确定对应的第三头发流动数据。
示例性的,第二参数值a f是基于时间参数t得到,本质也是一个时间参数,因此每个头发子区域对应的第二头发流动数据即每个像素点的流动速度乘以第二参数值a f,即可得到对应的第三头发流动数据即每个像素点的第一流动偏移量即偏移的距离。然后执行步骤c)~步骤d。
步骤e)中基于所述第一头发流动偏移区域对应的第一像素值,确定头发流动特效图像数据,具体可以包括:基于所述第一头发流动偏移区域对应的第一像素值,以及所述第二参数值,确定第一头发流动特效图像数据并作为所述头发流动特效图像数据。
示例性的,基于获取的第一头发流动偏移区域对应的位置的第一像素值如RGB值再乘以第二参数值a f,生成第一头发流动特效图像数据如RGB值数据并作为所述头发流动特效图像数据,然后返回步骤a)直至得到预设帧数的头发流动特效图像数据,然后执行步骤f)。
本实施例中,加入时间参数实现头发流动特效画面,其中对时间参数乘以第二调节系数并取余数再进行后续计算,可以保证生成的头发流动特效中的头发流动的周期性,丰富了头发流动特效样式,同时头发流动特效画面质量如头发流动连续性好,头发流动特效画 面逼真度提高。
在上述实施例的基础上,在一个实施例中,所述方法还可以包括以下步骤:
步骤1):基于所述第二参数值,确定第三参数值,所述第三参数值与所述第二参数值之和等于一。示例性的,第三参数值a r=1-a f
步骤2):基于所述第三参数值以及每个所述头发子区域对应的第二头发流动数据,确定对应的第四头发流动数据,每个所述第四头发流动数据包括对应的头发子区域中每个像素点的第二流动偏移量。
示例性的,第三参数值a r也是基于时间参数t得到,本质也是一个时间参数,因此每个头发子区域对应的第二头发流动数据即每个像素点的流动速度还可以乘以第三参数值a r,得到对应的第四头发流动数据即每个像素点的第二流动偏移量即偏移的距离。
步骤3):基于每个所述第四头发流动数据,以及所述原始图像得到第二头发流动偏移区域。
示例性的,针对每个头发子区域,基于其中每个像素点的第二流动偏移量即偏移的距离与原始图像对应的该每个像素点的原始坐标位置比对,即可确定第二头发流动偏移区域,即随着时间变化,该头发子区域从一个原始位置区域偏移到另一位置区域。
步骤4):获取所述原始图像中所述第二头发流动偏移区域对应的第二像素值。
示例性的,采样获取原始图像中第二头发流动偏移区域对应的位置的第二像素值如RGB值。
步骤5):基于所述第二头发流动偏移区域对应的第二像素值,以及所述第三参数值,确定第二头发流动特效图像数据;
示例性的,基于获取的第二头发流动偏移区域对应的位置的第二像素值如RGB值再乘以第三参数值a r,生成第二头发流动特效图像数据如RGB值数据。
步骤6):基于所述第二头发流动特效图像数据、所述第一头发流动特效图像数据,确定所述头发流动特效图像数据。
示例性的,基于第二头发流动特效图像数据如RGB值数据以及上述第一头发流动特效图像数据如RGB值数据,生成最终的头发流动特效图像数据。
本实施例中基于第二参数值和第三参数值分别确定了两个流动偏移量,进而确定两个头发流动偏移区域,然后基于该两个头发流动偏移区域在原始图像中对应位置的像素值以及第二参数值和第三参数值,融合生成最终的头发流动特效图像数据,如此可以使得头发 流动特效画面质量如画面逼真度进一步提高。
需要说明的是,尽管在附图中以特定顺序描述了本公开中方法的各个步骤,但是,这并非要求或者暗示必须按照该特定顺序来执行这些步骤,或是必须执行全部所示的步骤才能实现期望的结果。附加的或备选的,可以省略某些步骤,将多个步骤合并为一个步骤执行,以及/或者将一个步骤分解为多个步骤执行等。另外,也易于理解的是,这些步骤可以是例如在多个模块/进程/线程中同步或异步执行。
本公开实施例提供一种人像头发流动特效处理装置,如图6所示人像头发流动特效处理装置可包括:
数据确定模块601,用于确定原始图像中头发区域的掩膜以及第一头发流动数据,所述第一头发流动数据包括所述头发区域每个像素点沿预设流动方向的流动距离;
头发分层模块602,用于对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域;
数据计算模块603,用于基于所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据;其中,每个所述第二头发流动数据包括对应的所述头发子区域每个像素点的流动速度;
特效处理模块604,用于获取时间参数,基于所述时间参数、每个所述头发子区域对应的第二头发流动数据以及所述原始图像,生成头发流动特效视频。
在一个实施例中,所述装置还包括参数获取模块,用于获取腐蚀操作所需的腐蚀参数,所述腐蚀参数包括像素宽度和/或像素高度。
所述头发分层模块602,还用于基于所述像素宽度和/或像素高度,对所述掩膜进行逐像素点的腐蚀操作,得到第一腐蚀结果数据,所述第一腐蚀结果数据包括所述掩膜中每个像素点对应的第一像素值;比较所述第一腐蚀结果数据中的每个第一像素值与第一预设阈值的大小,基于第一像素值大于或等于所述第一预设阈值的像素点确定第一头发子区域,基于第一像素值小于所述第一预设阈值的像素点确定第二头发子区域。
在一个实施例中,所述参数获取模块,用于通过中央处理器中运行的指定Lua代码获取腐蚀操作所需的所述腐蚀参数。
在一个实施例中,所述头发分层模块602,用于通过图形处理器中运行的着色器对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域。
在一个实施例中,所述头发分层模块602,还用于基于所述像素宽度和/或像素高度, 对所述第二头发子区域进行逐像素点的腐蚀操作,得到第二腐蚀结果数据,所述第二腐蚀结果数据包括所述第二头发子区域中每个像素点对应的第二像素值;比较所述第二腐蚀结果数据中的每个第二像素值与第二预设阈值的大小,基于第二像素值大于或等于所述第二预设阈值的像素点确定第三头发子区域;其中,所述第二预设阈值小于所述第一预设阈值。
在一个实施例中,所述装置还包括系数获取模块,用于获取每个所述头发子区域对应的第一调节系数;其中,不同的所述头发子区域对应的第一调节系数不同。
所述数据计算模块603,用于基于每个所述头发子区域对应的第一调节系数,以及所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据。
在一个实施例中,所述装置还可包括归一化处理模块,用于在所述数据计算模块基于每个所述头发子区域对应的第一调节系数,以及所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据之前,对所述第一头发流动数据进行归一化处理,得到目标头发流动数据。所述数据计算模块,用于基于每个所述头发子区域对应的第一调节系数,以及所述目标头发流动数据,确定每个所述头发子区域对应的第二头发流动数据。
在一个实施例中,所述数据确定模块还用于在所述归一化处理模块对所述第一头发流动数据进行归一化处理,得到目标头发流动数据之前,确定所述原始图像中头发区域中每个像素点的流动距离的最大值和最小值。所述归一化处理模块,用于基于所述流动距离的最大值和最小值,对所述第一头发流动数据进行归一化处理,得到目标头发流动数据。
在一个实施例中,归一化处理模块用于:计算所述流动距离的最大值和最小值的差值;分别计算所述第一头发流动数据中每个像素点对应的流动距离与所述差值的乘积值;分别计算所述第一头发流动数据中每个像素点对应的所述乘积值与所述最小值的和值;基于所述第一头发流动数据中每个像素点对应的所述和值,确定所述目标头发流动数据。
在一个实施例中,所述特效处理模块,用于:获取时间参数;基于所述时间参数,以及每个所述头发子区域对应的第二头发流动数据,确定对应的第三头发流动数据,每个所述第三头发流动数据包括对应的头发子区域中每个像素点的第一流动偏移量;基于每个所述第三头发流动数据,以及所述原始图像得到第一头发流动偏移区域;获取所述原始图像中所述第一头发流动偏移区域对应的第一像素值;基于所述第一头发流动偏移区域对应的第一像素值,确定头发流动特效图像数据,返回所述获取时间参数的步骤,直至得到预设帧数的头发流动特效图像数据;基于所述预设帧数的头发流动特效图像数据,生成头发流动特效视频。
在一个实施例中,所述装置还可包括参数处理模块,用于对所述时间参数乘以第二调节系数,得到第一参数值,所述第二调节系数是大于1的自然数;对所述第一参数值求余数,得到第二参数值。所述特效处理模块,用于基于所述第二参数值以及每个所述头发子区域对应的第二头发流动数据,确定对应的第三头发流动数据。所述特效处理模块,还用于基于所述第一头发流动偏移区域对应的第一像素值,以及所述第二参数值,确定第一头发流动特效图像数据并作为所述头发流动特效图像数据。
在一个实施例中,所述参数处理模块,还用于基于所述第二参数值,确定第三参数值,所述第三参数值与所述第二参数值之和等于一。
所述特效处理模块,还用于基于所述第三参数值以及每个所述头发子区域对应的第二头发流动数据,确定对应的第四头发流动数据,每个所述第四头发流动数据包括对应的头发子区域中每个像素点的第二流动偏移量;基于每个所述第四头发流动数据,以及所述原始图像得到第二头发流动偏移区域;获取所述原始图像中所述第二头发流动偏移区域对应的第二像素值;基于所述第二头发流动偏移区域对应的第二像素值,以及所述第三参数值,确定第二头发流动特效图像数据;基于所述第二头发流动特效图像数据、所述第一头发流动特效图像数据,确定所述头发流动特效图像数据。
关于上述实施例中的装置,其中各个模块执行操作的具体方式以及带来的相应技术效果已经在有关该方法的实施例中进行了对应的详细描述,此处将不做详细阐述说明。
应当注意,尽管在上文详细描述中提及了用于动作执行的设备的若干模块或者单元,但是这种划分并非强制性的。实际上,根据本公开的实施方式,上文描述的两个或更多模块或者单元的特征和功能可以在一个模块或者单元中具体化。反之,上文描述的一个模块或者单元的特征和功能可以进一步划分为由多个模块或者单元来具体化。作为模块或单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现木公开方案的目的。本领域普通技术人员在不付出创造性劳动的情况下,即可以理解并实施。
应注意,上述各个模块仅是根据其所实现的具体功能划分的逻辑模块,而不是用于限制具体的实现方式,例如可以以软件、硬件或者软硬件结合的方式来实现。在实际实现时,上述各个模块可被实现为独立的物理实体,或者也可由单个实体(例如,处理器(CPU或DSP等)、集成电路等)来实现。此外,上述各个模块在附图中用虚线示出指示这些模块可以并不实际存在,而它们所实现的操作/功能可由装置或处理电路本身来实 现。
此外,尽管未示出,该装置也可以包括存储器,其可以存储由装置、装置所包含的各个模块在操作中产生的各种信息、用于操作的程序和数据、将由通信单元发送的数据等。存储器可以是易失性存储器和/或非易失性存储器。例如,存储器可以包括但不限于随机存储存储器(RAM)、动态随机存储存储器(DRAM)、静态随机存取存储器(SRAM)、只读存储器(ROM)、闪存存储器。当然,存储器可也位于该装置之外。
本公开实施例还提供一种计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现上述任一项实施例所述人像头发流动特效处理方法的步骤。
示例性的,该可读存储介质例如可以为但不限于电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。可读存储介质的更具体的例子(非穷举的列表)包括:具有一个或多个导线的电连接、便携式盘、硬盘、随机存取存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。
所述计算机可读存储介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了可读程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。可读存储介质还可以是可读存储介质以外的任何可读介质,该可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。可读存储介质上包含的程序代码可以用任何适当的介质传输,包括但不限于无线、有线、光缆、RF等等,或者上述的任意合适的组合。
根据本公开的一个或多个实施例,本公开提供了一种计算机程序产品,所述计算机程序产品包含计算机程序或指令,当所述计算机程序或指令在计算机上运行时,使得所述计算机执行上述任一实施例所述人像头发流动特效处理方法的步骤。
根据本公开的一个或多个实施例,本公开提供了一种计算机程序,所述计算机程序包括的程序代码在由计算机执行时使得计算机实现上述任一项实施例所述人像头发流动特效处理方法的步骤。
本公开实施例还提供一种电子设备,如图7所示电子设备可包括处理器701以及存储器702,存储器702用于存储计算机程序。其中,所述处理器701配置为经由执行所述计算机程序来执行上述任一项实施例中所述人像头发流动特效处理方法的步骤。示例性的,电子设备可以是智能手机、平板电脑等,本实施例中对此不作限制。
需要说明的是,在本文中,诸如“第一”和“第二”等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。
以上所述仅是本公开的具体实施方式,使本领域技术人员能够理解或实现本公开。对这些实施例的多种修改对本领域的技术人员来说将是显而易见的,本文中所定义的一般原理可以在不脱离本公开的精神或范围的情况下,在其它实施例中实现。因此,本公开将不会被限制于本文所述的这些实施例,而是要符合与本文所公开的原理和新颖特点相一致的最宽的范围。

Claims (16)

  1. 一种人像头发流动特效处理方法,包括:
    确定原始图像中头发区域的掩膜以及第一头发流动数据,所述第一头发流动数据包括所述头发区域每个像素点沿预设流动方向的流动距离;
    对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域;
    基于所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据;其中,每个所述第二头发流动数据包括对应的所述头发子区域每个像素点的流动速度;
    获取时间参数,基于所述时间参数、每个所述头发子区域对应的第二头发流动数据以及所述原始图像,生成头发流动特效视频。
  2. 根据权利要求1所述的方法,其中,所述方法还包括:
    获取腐蚀操作所需的腐蚀参数,所述腐蚀参数包括像素宽度和/或像素高度;
    所述对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域,包括:
    基于所述像素宽度和/或像素高度,对所述掩膜进行逐像素点的腐蚀操作,得到第一腐蚀结果数据,所述第一腐蚀结果数据包括所述掩膜中每个像素点对应的第一像素值;
    比较所述第一腐蚀结果数据中的每个第一像素值与第一预设阈值的大小,基于第一像素值大于或等于所述第一预设阈值的像素点确定第一头发子区域,基于第一像素值小于所述第一预设阈值的像素点确定第二头发子区域。
  3. 根据权利要求2所述的方法,其中,所述获取腐蚀操作所需的腐蚀参数,包括:
    通过中央处理器中运行的指定Lua代码获取腐蚀操作所需的所述腐蚀参数;
    和/或,
    所述对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域,包括:
    通过图形处理器中运行的着色器对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域。
  4. 根据权利要求2或3所述的方法,其中,所述方法还包括:
    基于所述像素宽度和/或像素高度,对所述第二头发子区域进行逐像素点的腐蚀操作,得到第二腐蚀结果数据,所述第二腐蚀结果数据包括所述第二头发子区域中每个像素点对 应的第二像素值;
    比较所述第二腐蚀结果数据中的每个第二像素值与第二预设阈值的大小,基于第二像素值大于或等于所述第二预设阈值的像素点确定第三头发子区域;其中,所述第二预设阈值小于所述第一预设阈值。
  5. 根据权利要求1所述的方法,其中,所述方法还包括:
    获取每个所述头发子区域对应的第一调节系数;其中,不同的所述头发子区域对应的第一调节系数不同;
    所述基于所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据,包括:
    基于每个所述头发子区域对应的第一调节系数,以及所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据。
  6. 根据权利要求5所述的方法,其中,在所述基于每个所述头发子区域对应的第一调节系数,以及所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据之前,所述方法还包括:
    对所述第一头发流动数据进行归一化处理,得到目标头发流动数据;
    所述基于每个所述头发子区域对应的第一调节系数,以及所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据,包括:
    基于每个所述头发子区域对应的第一调节系数,以及所述目标头发流动数据,确定每个所述头发子区域对应的第二头发流动数据。
  7. 根据权利要求6所述的方法,其中,在所述对所述第一头发流动数据进行归一化处理,得到目标头发流动数据之前,所述方法还包括:
    确定所述原始图像中头发区域中每个像素点的流动距离的最大值和最小值;
    所述对所述第一头发流动数据进行归一化处理,得到目标头发流动数据,包括:
    基于所述流动距离的最大值和最小值,对所述第一头发流动数据进行归一化处理,得到目标头发流动数据。
  8. 根据权利要求7所述的方法,其中,基于所述流动距离的最大值和最小值,对所述第一头发流动数据进行归一化处理,得到目标头发流动数据,包括:
    计算所述流动距离的最大值和最小值的差值;
    分别计算所述第一头发流动数据中每个像素点对应的流动距离与所述差值的乘积值;
    分别计算所述第一头发流动数据中每个像素点对应的所述乘积值与所述最小值的和值;
    基于所述第一头发流动数据中每个像素点对应的所述和值,确定所述目标头发流动数据。
  9. 根据权利要求1~7任一项所述的方法,其中,所述获取时间参数,基于所述时间参数、每个所述头发子区域对应的第二头发流动数据以及所述原始图像,生成头发流动特效视频,包括:
    获取时间参数;
    基于所述时间参数,以及每个所述头发子区域对应的第二头发流动数据,确定对应的第三头发流动数据,每个所述第三头发流动数据包括对应的头发子区域中每个像素点的第一流动偏移量;
    基于每个所述第三头发流动数据,以及所述原始图像得到第一头发流动偏移区域;
    获取所述原始图像中所述第一头发流动偏移区域对应的第一像素值;
    基于所述第一头发流动偏移区域对应的第一像素值,确定头发流动特效图像数据,返回所述获取时间参数的步骤,直至得到预设帧数的头发流动特效图像数据;
    基于所述预设帧数的头发流动特效图像数据,生成头发流动特效视频。
  10. 根据权利要求9所述的方法,其中,所述方法还包括:
    对所述时间参数乘以第二调节系数,得到第一参数值,所述第二调节系数是大于1的自然数;
    对所述第一参数值求余数,得到第二参数值;
    所述基于所述时间参数,以及每个所述头发子区域对应的第二头发流动数据,确定对应的第三头发流动数据,包括:
    基于所述第二参数值以及每个所述头发子区域对应的第二头发流动数据,确定对应的第三头发流动数据;
    所述基于所述第一头发流动偏移区域对应的第一像素值,确定头发流动特效图像数据,包括:
    基于所述第一头发流动偏移区域对应的第一像素值,以及所述第二参数值,确定第一头发流动特效图像数据并作为所述头发流动特效图像数据。
  11. 根据权利要求10所述的方法,其中,所述方法还包括:
    基于所述第二参数值,确定第三参数值,所述第三参数值与所述第二参数值之和等于一;
    基于所述第三参数值以及每个所述头发子区域对应的第二头发流动数据,确定对应的第四头发流动数据,每个所述第四头发流动数据包括对应的头发子区域中每个像素点的第二流动偏移量;
    基于每个所述第四头发流动数据,以及所述原始图像得到第二头发流动偏移区域;
    获取所述原始图像中所述第二头发流动偏移区域对应的第二像素值;
    基于所述第二头发流动偏移区域对应的第二像素值,以及所述第三参数值,确定第二头发流动特效图像数据;
    基于所述第二头发流动特效图像数据、所述第一头发流动特效图像数据,确定所述头发流动特效图像数据。
  12. 一种人像头发流动特效处理装置,包括:
    数据确定模块,用于确定原始图像中头发区域的掩膜以及第一头发流动数据,所述第一头发流动数据包括所述头发区域每个像素点沿预设流动方向的流动距离;
    头发分层模块,用于对所述掩膜进行腐蚀操作,以对所述头发区域实现分层得到多个头发子区域;
    数据计算模块,用于基于所述第一头发流动数据,确定每个所述头发子区域对应的第二头发流动数据;其中,每个所述第二头发流动数据包括对应的所述头发子区域每个像素点的流动速度;
    特效处理模块,用于获取时间参数,基于所述时间参数、每个所述头发子区域对应的第二头发流动数据以及所述原始图像,生成头发流动特效视频。
  13. 一种计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现权利要求1~11任一项所述的人像头发流动特效处理方法。
  14. 一种电子设备,包括:
    处理器;以及
    存储器,用于存储计算机程序;
    其中,所述处理器配置为经由执行所述计算机程序来执行根据权利要求1~11中任一项所述的人像头发流动特效处理方法。
  15. 一种计算机程序产品,所述计算机程序产品包含计算机指令,所述计算机指令在 计算机上运行时使得所述计算机执行根据权利要求1-11中任一所述的人像头发流动特效处理方法。
  16. 一种计算机程序,所述计算机程序包括程序代码,所述程序代码在由计算机执行时使得计算机执行根据权利要求1-11中任一所述的人像头发流动特效处理方法。
PCT/CN2022/130618 2021-12-06 2022-11-08 人像头发流动特效处理方法、装置、介质和电子设备 WO2023103684A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111477583.3 2021-12-06
CN202111477583.3A CN114219877B (zh) 2021-12-06 人像头发流动特效处理方法、装置、介质和电子设备

Publications (1)

Publication Number Publication Date
WO2023103684A1 true WO2023103684A1 (zh) 2023-06-15

Family

ID=80699869

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/130618 WO2023103684A1 (zh) 2021-12-06 2022-11-08 人像头发流动特效处理方法、装置、介质和电子设备

Country Status (1)

Country Link
WO (1) WO2023103684A1 (zh)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111047675A (zh) * 2018-10-11 2020-04-21 真玫智能科技(深圳)有限公司 一种头发仿真的方法及装置
CN111586444A (zh) * 2020-06-05 2020-08-25 广州繁星互娱信息科技有限公司 视频处理方法、装置、电子设备及存储介质
CN111986212A (zh) * 2020-08-20 2020-11-24 杭州趣维科技有限公司 一种人像发丝流动特效实现方法
CN113516743A (zh) * 2020-03-27 2021-10-19 北京达佳互联信息技术有限公司 头发的渲染方法、装置、电子设备及存储介质
CN114219877A (zh) * 2021-12-06 2022-03-22 北京字节跳动网络技术有限公司 人像头发流动特效处理方法、装置、介质和电子设备

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111047675A (zh) * 2018-10-11 2020-04-21 真玫智能科技(深圳)有限公司 一种头发仿真的方法及装置
CN113516743A (zh) * 2020-03-27 2021-10-19 北京达佳互联信息技术有限公司 头发的渲染方法、装置、电子设备及存储介质
CN111586444A (zh) * 2020-06-05 2020-08-25 广州繁星互娱信息科技有限公司 视频处理方法、装置、电子设备及存储介质
CN111986212A (zh) * 2020-08-20 2020-11-24 杭州趣维科技有限公司 一种人像发丝流动特效实现方法
CN114219877A (zh) * 2021-12-06 2022-03-22 北京字节跳动网络技术有限公司 人像头发流动特效处理方法、装置、介质和电子设备

Also Published As

Publication number Publication date
CN114219877A (zh) 2022-03-22

Similar Documents

Publication Publication Date Title
US10810435B2 (en) Segmenting objects in video sequences
CN106709871B (zh) 利用活动掩码的图像合成的方法和系统
WO2021115136A1 (zh) 视频图像的防抖方法、装置、电子设备和存储介质
TW201426493A (zh) 自繪控制項的螢幕適配方法及裝置
US20170329502A1 (en) Method and device for processing image
US11978216B2 (en) Patch-based image matting using deep learning
WO2021218016A1 (zh) 一种图片裁剪方法、装置、计算机设备及存储介质
US20230326110A1 (en) Method, apparatus, device and media for publishing video
JP7379684B2 (ja) 画像生成方法及び装置並びにコンピュータプログラム
US10930033B1 (en) Content aware tracing for generating vector drawings
CN111258519A (zh) 屏幕分屏实现方法、装置、终端和介质
CN113506305B (zh) 三维点云数据的图像增强方法、语义分割方法及装置
WO2022048414A1 (zh) 一种图像生成方法、装置、设备及存储介质
US9786055B1 (en) Method and apparatus for real-time matting using local color estimation and propagation
KR100780057B1 (ko) 동영상 그레쥬얼 샷 변환 장치 및 그 방법
CN113538623A (zh) 确定目标图像的方法、装置、电子设备及存储介质
US20220122258A1 (en) Image Content Snapping Guidelines
WO2023103684A1 (zh) 人像头发流动特效处理方法、装置、介质和电子设备
WO2023071595A1 (zh) 一种音效展示方法及终端设备
CN106354381B (zh) 图像文件的处理方法及装置
CN109543495A (zh) 一种人脸关键点标注方法、装置、电子设备及存储介质
WO2023151214A1 (zh) 图像生成方法、系统、电子设备、存储介质和产品
CN114219877B (zh) 人像头发流动特效处理方法、装置、介质和电子设备
CN112929562B (zh) 视频抖动的处理方法、装置、设备以及存储介质
CN115311397A (zh) 用于图像渲染的方法、装置、设备和存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22903107

Country of ref document: EP

Kind code of ref document: A1