WO2022261828A1 - Image processing method and apparatus, electronic device, and computer-readable storage medium - Google Patents

Image processing method and apparatus, electronic device, and computer-readable storage medium Download PDF

Info

Publication number
WO2022261828A1
WO2022261828A1 PCT/CN2021/100148 CN2021100148W WO2022261828A1 WO 2022261828 A1 WO2022261828 A1 WO 2022261828A1 CN 2021100148 W CN2021100148 W CN 2021100148W WO 2022261828 A1 WO2022261828 A1 WO 2022261828A1
Authority
WO
WIPO (PCT)
Prior art keywords
image
region
hair
hair mask
interest
Prior art date
Application number
PCT/CN2021/100148
Other languages
French (fr)
Chinese (zh)
Inventor
内山寛之
刘锴
Original Assignee
Oppo广东移动通信有限公司
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 Oppo广东移动通信有限公司 filed Critical Oppo广东移动通信有限公司
Priority to PCT/CN2021/100148 priority Critical patent/WO2022261828A1/en
Publication of WO2022261828A1 publication Critical patent/WO2022261828A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis

Definitions

  • the present application relates to the field of image technology, in particular to an image processing method, device, electronic equipment, and computer-readable storage medium.
  • the embodiment of the present application discloses an image processing method, device, electronic equipment, and computer-readable storage medium, which can obtain an accurate hair mask corresponding to a character image, so that the hair mask can be used to accurately locate the hair region in the character image , which improves the image processing effect.
  • the embodiment of the present application discloses an image processing method, including: preprocessing the original person image, obtaining the ROI image of the original person image, and the region segmentation image corresponding to the ROI image, the The region segmentation image includes portrait area information of the region of interest image; generating a first hair mask according to the region of interest image and the region segmentation image; optimizing the first hair mask to obtain the The target hair mask corresponding to the original character image.
  • the embodiment of the present application discloses an image processing device, including: a preprocessing module, configured to preprocess the original character image, obtain the ROI image of the original character image, and the ROI image corresponding to the ROI image Region segmentation image, the region segmentation image includes portrait area information of the region of interest image; mask generation module, used to generate a first hair mask according to the region of interest image and the region segmentation image; optimization module , for optimizing the first hair mask to obtain a target hair mask corresponding to the original person image.
  • a preprocessing module configured to preprocess the original character image, obtain the ROI image of the original character image, and the ROI image corresponding to the ROI image Region segmentation image, the region segmentation image includes portrait area information of the region of interest image
  • mask generation module used to generate a first hair mask according to the region of interest image and the region segmentation image
  • optimization module for optimizing the first hair mask to obtain a target hair mask corresponding to the original person image.
  • the embodiment of the present application discloses an electronic device, including a memory and a processor, the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the following steps: The image is preprocessed to obtain the ROI image of the original person image, and the region segmentation image corresponding to the ROI image, and the region segmentation image includes the portrait region information of the ROI image; according to the The region of interest image and the region segmentation image are used to generate a first hair mask; and the first hair mask is optimized to obtain a target hair mask corresponding to the original person image.
  • the embodiment of the present application discloses a computer-readable storage medium, on which a computer program is stored.
  • the processor When the computer program is executed by a processor, the processor performs the following steps: preprocessing the original character image to obtain the The region of interest image of the original person image, and the region segmentation image corresponding to the region of interest image, the region segmentation image includes portrait region information of the region of interest image; according to the region of interest image and the region of interest image Generate a first hair mask from the region segmentation image; and optimize the first hair mask to obtain a target hair mask corresponding to the original person image.
  • Fig. 1 is a block diagram of an image processing circuit in an embodiment
  • Fig. 2 is a flowchart of an image processing method in an embodiment
  • Fig. 3 is a schematic diagram of preprocessing the original character image in one embodiment
  • Fig. 4 is a flow chart of preprocessing the original character image in one embodiment
  • FIG. 5A is a schematic diagram of a portrait segmentation image in an embodiment
  • Fig. 5B is a schematic diagram of calculating hair contour lines in one embodiment
  • FIG. 5C is a schematic diagram of determining a region of interest in matting in an embodiment
  • Fig. 5D is a schematic diagram of correcting the original character image and the segmented portrait image in one embodiment
  • Fig. 6 is the flowchart of image processing method in another embodiment
  • Fig. 7 is a schematic diagram of generating a first hair mask through an image processing model in an embodiment
  • Fig. 8 is a flow chart of calculating the background complexity image in one embodiment
  • FIG. 9A is a schematic diagram of calculating background complexity in an embodiment
  • Fig. 9B is a schematic diagram of merging the first hair mask before corrosion treatment and the first hair mask after corrosion treatment in one embodiment
  • Figure 10 is a schematic diagram of filling holes in the first hair mask in one embodiment
  • Fig. 11 is a schematic diagram of enhancing the hair region of the first hair mask in one embodiment
  • Fig. 12 is a schematic diagram of softening the first hair mask in one embodiment
  • Fig. 13 is a schematic diagram of performing upsampling and filtering on a second hair mask through a guided filter in an embodiment
  • Figure 14 is a block diagram of an image processing device in an embodiment
  • Fig. 15 is a structural block diagram of an electronic device in one embodiment.
  • first, second and the like used in this application may be used to describe various elements herein, but these elements are not limited by these terms. These terms are only used to distinguish one element from another element.
  • a first hair mask could be termed a second hair mask, and, similarly, a second hair mask could be termed a first hair mask, without departing from the scope of the present application.
  • Both the first hair mask and the second hair mask are hair masks, but they are not the same hair mask.
  • An embodiment of the present application provides an electronic device.
  • the electronic device includes an image processing circuit, and the image processing circuit may be implemented by hardware and/or software components, and may include various processing units defining an ISP (Image Signal Processing, image signal processing) pipeline.
  • Figure 1 is a block diagram of an image processing circuit in one embodiment. For ease of description, FIG. 1 only shows various aspects of the image processing technology related to the embodiment of the present application.
  • the image processing circuit includes an ISP processor 140 and a control logic 150 .
  • Image data captured by imaging device 110 is first processed by ISP processor 140 , which analyzes the image data to capture image statistics that can be used to determine one or more control parameters of imaging device 110 .
  • Imaging device 110 may include one or more lenses 112 and image sensor 114 .
  • the image sensor 114 may include a color filter array (such as a Bayer filter), and the image sensor 114 may obtain light intensity and wavelength information captured by each imaging pixel and provide a set of raw image data that may be processed by the ISP processor 140 .
  • the attitude sensor 120 (such as a three-axis gyroscope, Hall sensor, accelerometer, etc.) can provide the collected image processing parameters (such as anti-shake parameters) to the ISP processor 140 based on the interface type of the attitude sensor 120 .
  • the attitude sensor 120 interface may adopt a SMIA (Standard Mobile Imaging Architecture, Standard Mobile Imaging Architecture) interface, other serial or parallel camera interfaces, or a combination of the above interfaces.
  • SMIA Standard Mobile Imaging Architecture
  • each imaging device 110 may correspond to an image sensor 114 respectively, or may Multiple imaging devices 110 correspond to one image sensor 114 , which is not limited here.
  • the working process of each imaging device 110 may refer to the content described above.
  • the image sensor 114 can also send the original image data to the attitude sensor 120, and the attitude sensor 120 can provide the original image data to the ISP processor 140 based on the attitude sensor 120 interface type, or the attitude sensor 120 can store the original image data in the image memory 130 in.
  • the ISP processor 140 processes raw image data on a pixel-by-pixel basis in various formats.
  • each image pixel may have a bit depth of 8, 10, 12, or 14 bits, and the ISP processor 140 may perform one or more image processing operations on the raw image data, gather statistical information about the image data.
  • image processing operations can be performed with the same or different bit depth precision.
  • the ISP processor 140 may also receive image data from image memory 130 .
  • the attitude sensor 120 interface sends raw image data to the image storage 130, and the raw image data in the image storage 130 is provided to the ISP processor 140 for processing.
  • the image memory 130 may be a part of a memory device, a storage device, or an independent dedicated memory in an electronic device, and may include a DMA (Direct Memory Access) feature.
  • DMA Direct Memory Access
  • the ISP processor 140 may perform one or more image processing operations, such as temporal filtering.
  • the processed image data may be sent to image memory 130 for additional processing before being displayed.
  • the ISP processor 140 receives processed data from the image memory 130 and subjects the processed data to image data processing in the original domain and in the RGB and YCbCr color spaces.
  • the image data processed by the ISP processor 140 may be output to the display 160 for viewing by the user and/or for further processing by a graphics engine or a GPU (Graphics Processing Unit, graphics processor).
  • the output of the ISP processor 140 can also be sent to the image memory 130 , and the display 160 can read image data from the image memory 130 .
  • image memory 130 may be configured to implement one or more frame buffers.
  • Statistics determined by ISP processor 140 may be sent to control logic 150 .
  • the statistical data may include the vibration frequency of the gyroscope, automatic exposure, automatic white balance, automatic focus, flicker detection, black level compensation, lens 112 shading correction and other image sensor 114 statistical information.
  • Control logic 150 may include a processor and/or a microcontroller that executes one or more routines (e.g., firmware) that determine control parameters of imaging device 110 and ISP processing based on received statistical data. The control parameters of the device 140.
  • control parameters of the imaging device 110 may include attitude sensor 120 control parameters (such as gain, integration time of exposure control, anti-shake parameters, etc.), camera flash control parameters, camera anti-shake displacement parameters, lens 112 control parameters (such as focus or focal length for zooming) or a combination of these parameters.
  • ISP control parameters may include gain levels and color correction matrices for automatic white balance and color adjustment (eg, during RGB processing), as well as lens 112 shading correction parameters.
  • the ISP processor 140 can acquire the original character image from the imaging device 110 or the image memory 130, and can perform preprocessing on the original character image to obtain the ROI image of the original character image and the region corresponding to the ROI image Split the image.
  • the ISP processor 140 may generate a first hair mask according to the ROI image and the region segmentation image, and optimize the first hair mask to obtain a target hair mask corresponding to the original person image.
  • the ISP processor 140 can accurately determine the hair region in the original character image according to the target hair mask, and use the target hair mask to analyze the hair area of the original character.
  • the image is separated from foreground and background regions.
  • image processing can also be performed on the separated background area or foreground area, such as blurring the background area and beautifying the foreground area (such as increasing brightness, whitening portraits, defogging, etc.), etc. , but not limited to this.
  • the ISP processor 140 can send the processed image to the image memory 130 for storage, and can also send the processed image to the display 160 for display, so that the user can observe the processed image through the display 160 conveniently.
  • an image processing method is provided, which can be applied to the above-mentioned electronic equipment, which may include but not limited to mobile phones, smart wearable devices, tablet computers, PC (Personal Computer, personal computer), vehicle-mounted terminal, digital camera, etc., which are not limited in this embodiment of the present application.
  • the image processing method may include the following steps:
  • Step 210 preprocessing the original person image to obtain the ROI image of the original person image and the region segmentation image corresponding to the ROI image.
  • the original character image can refer to an image containing a character, and the original character image can be a color image, such as an image in RGB (Red Green Blue, red green blue) format or YUV (Y represents brightness, U and V represent chroma) format images, etc.
  • the original person image may be an image in which a foreground portrait area needs to be separated from a background area.
  • the original person image may be an image pre-stored in the memory of the electronic device, or an image collected in real time by the electronic device through a camera.
  • the depth information corresponding to the foreground portrait area and the background area in the original person image is quite different, and the depth information can be used to represent the distance between the photographed object and the camera, and the greater the depth information, the greater the distance. Therefore, the depth information corresponding to each pixel in the original person image can be used to divide the foreground area and the background area in the original person image, for example, the background area can be an area composed of pixels whose depth information is greater than the first threshold, the The foreground area may be an area composed of pixels whose depth information is less than the second threshold.
  • face recognition may also be used to divide the foreground area and the background area of the original person image.
  • the electronic device can perform face recognition on the original person image, determine the face area in the original person image, and then determine the portrait area according to the face area.
  • the portrait area refers to the image area where the entire human body is located
  • the face area refers to the is the image area where the face of the person is located
  • the portrait area includes the face area.
  • Other image areas in the original person image except the portrait area can be determined as the background area.
  • the electronic device can preprocess the original person image to determine a region of interest (Region of Interest, ROI) in the original person image.
  • ROI region of interest
  • the matting area of interest may include the face area.
  • An accurate hair mask corresponding to the original character image can be obtained through hair matting, so as to accurately locate the hair region of the original character image through the precise hair mask.
  • the electronic device can extract the matting region of interest from the original person image to obtain an image of the region of interest, and at the same time obtain a region segmentation image corresponding to the region of interest image
  • the region segmentation image may include portrait region information of the region of interest image, and the region segmentation image may be understood as an image obtained by extracting a portrait from the region of interest image.
  • Fig. 3 is a schematic diagram of preprocessing an original person image in an embodiment.
  • the electronic device can preprocess the original character image 310, determine the matting region of interest 312 in the original character image 310, and extract the matting region of interest 312 from the original character image 310 to obtain a sense
  • the region of interest image 320, and the region segmentation image 330 corresponding to the region of interest image 320 can be obtained at the same time.
  • the region segmentation image 330 matches the ROI image 320, and the region segmentation image 330 can be used to represent the portrait area in the ROI image 320 (ie, the black region in the region segmentation image 330).
  • Step 220 generating a first hair mask according to the ROI image and the region segmentation image.
  • the first hair mask can be used to characterize the hair region in the region of interest image
  • the electronic device can first deduce the hair region in the region of interest image according to the region of interest image and the corresponding region segmentation image, and generate the first hair mask .
  • the electronic device can use machine learning to generate the first hair mask, and can input the image of the region of interest and the corresponding region segmentation image into the pre-trained image processing model, and use the image processing model to generate the hair mask of interest
  • the region image and the region segmentation image are processed to obtain the first hair mask.
  • the image processing model can be obtained by training according to multiple sets of sample training images, and each set of sample training images can include a sample person image, a sample portrait segmentation image corresponding to the sample person image, and a sample hair mask, and the sample hair Masks can be used to label hair regions in sample person images.
  • the electronic device can also use other methods to generate the first hair mask. For example, the electronic device can determine the profile of the portrait in the image of the region of interest according to the region segmentation image, and determine the portrait area according to the profile of the portrait, and then Perform image recognition on the portrait area, extract image features in the portrait area, and analyze the image features to determine the hair area.
  • the image features may include but not limited to edge features, color features, position features, etc., for example, the color of the hair region is usually black, has more edge information, and is located above the face (especially the eyes located in the face) area above), etc.
  • Step 230 optimize the first hair mask to obtain a target hair mask corresponding to the original person image.
  • the first hair mask is a hair mask initially obtained from the region-of-interest image and the region-segmented image.
  • the optimization process adjusts and corrects the first hair mask, so that a more detailed and precise target hair mask can be obtained, and the target hair mask can be used to accurately locate the hair region in the original person image.
  • the optimization processing may include but not limited to enhancement processing, erosion processing, filling processing, etc., to optimize the edges of the hair region in the first hair mask, and alleviate the lack of hairline edges or It is the case that contains the edge of non-hair content, etc., to get an accurate target hair mask.
  • the electronic device After the electronic device obtains the target hair mask, it can separate the foreground portrait area and the background area in the original character image according to the target hair mask. Since the hair area of the original character image is accurately positioned in the target hair mask, it can be accurately Separate the hair area of the portrait from the background area to achieve hair-level image separation.
  • the separated portrait area and/or background area may be further processed.
  • the background area can be blurred
  • the brightness of the portrait area can be adjusted
  • the white balance parameters of the portrait area can be adjusted.
  • the embodiment of the present application does not limit the image processing after separation.
  • the ROI image of the original person image and the region segmentation image corresponding to the ROI image are obtained, and the ROI image and the region segmentation image are generated according to the ROI image and the region segmentation image.
  • the first hair mask, and optimize the first hair mask to obtain the target hair mask corresponding to the original character image after generating the first hair mask, optimize and correct the first hair mask, In this way, a finer and more accurate target hair mask can be obtained, and the hair region in the original character image can be accurately located by using the target hair mask, thereby improving the image processing of the subsequent image processing such as foreground and background separation of the original character image Effect.
  • the step of preprocessing the original person image to obtain the region of interest image of the original person image and the region segmentation image corresponding to the region of interest image may include the following steps:
  • Step 402 Determine the matting region of interest in the original person image according to the original person image and the person segmentation image corresponding to the original person image.
  • a segmented portrait image is an image obtained by extracting a portrait from an original person image
  • the segmented portrait image may include portrait area information of the original person image.
  • the electronic device may directly acquire an original character image and a segmented portrait image corresponding to the original character image, and perform preprocessing on the original character image according to the segmented portrait image.
  • the segmented portrait image may be an image pre-stored in the memory, and the electronic device may perform portrait extraction on the original person image in advance to obtain the segmented portrait image, and store the segmented portrait image in the memory. That is, the preprocessing process of the original person image does not include the step of extracting the portrait from the original person image.
  • the preprocessing process of the original person image may include the step of extracting the portrait of the original person image.
  • the electronic device preprocesses the original person image, it may first perform portrait extraction on the original person image to obtain A segmented image of a portrait, and then based on the segmented image of a portrait, a matting region of interest in the original person image is determined.
  • the electronic device can extract the image features of the original person image through the first segmentation model, identify the portrait region in the original person image based on the image features, and perform portrait extraction on the original person image according to the portrait region to obtain the portrait Split the image.
  • the first segmentation model may be obtained by training according to a first set of segmented sample images, which may include a plurality of sample person images, and a sample portrait segmentation image corresponding to each sample person image.
  • the first segmented sample image set may only contain multiple sample person images, and each sample person image may be marked with person area information.
  • Fig. 5A is a schematic diagram of a segmented portrait image in an embodiment.
  • the original person image 310 corresponds to the portrait segmented image 304, which is obtained after portrait extraction is performed on the original person image 310, and the portrait segmented image 304 can be used to represent the portrait area in the original person image 310 .
  • the step of determining the matting region of interest in the original character image according to the original character image and the segmented portrait image corresponding to the original character image may include: acquiring the hair segmentation image corresponding to the original character image, according to the The hair contour line is calculated from the hair segmentation image and the portrait segmentation image, and the matting region of interest in the original person image is determined according to the hair contour line.
  • the hair segmentation image is an image obtained by performing hair segmentation on the original person image.
  • the hair segmentation image may include hair region information of the original person image, and the hair region in the original person image may be identified and extracted to obtain the hair segmentation image.
  • the electronic device can identify the hair region in the original person image through the second segmentation model, and the second segmentation model can extract the image features of the original person image, and identify the hair region in the original person image based on the image features , and extract the hair region in the original person image to obtain the hair segmentation image.
  • the second segmentation model may be obtained by training according to a second set of segmented sample images, which may include a plurality of sample person images and a sample hair segment image corresponding to each sample person image .
  • the second set of segmented sample images may only include multiple sample person images marked with hair region information.
  • a segmentation model can also be used to identify the portrait region and hair region of the original person image at the same time, and output the portrait segmentation image and hair segmentation image, and the sample person image and the sample portrait corresponding to the sample person image can be simultaneously Segmented images and sample hair segmented images are used as a training set to train the segmentation model, so that it has the ability to simultaneously output portrait segmented images and hair segmented images.
  • the above segmentation model can use deeplab semantic segmentation algorithm, U-Net network structure, FCN (Fully Convolutional Networks, fully convolutional neural network) and other methods to perform portrait segmentation, which is not limited in the embodiment of the present application.
  • the hair contour line may be used to describe the contour of the hair region, and the hair contour line may include each pixel point on the outer edge of the hair region, and the outer edge refers to an edge adjacent to the background region.
  • the electronic device can compare the hair segmentation image with the portrait segmentation image, determine the same pixel points on the outer edge of the hair region, and determine the hair contour line according to the same pixel points.
  • the electronic device can use the portrait segmentation image to corrode the hair region in the hair segmentation image, so that the hair region of the hair segmentation image is reduced, and only the edges in the hair segmentation image that coincide with the edges of the portrait segmentation image are retained Pixels, the remaining edge pixels constitute the hair contour.
  • Fig. 5B is a schematic diagram of calculating hair contour in one embodiment.
  • the electronic device can compare the segmented portrait image 510 with the segmented hair image 520 , determine the same pixel points on the outer edge of the hair region, and obtain the hair contour line 530 .
  • the calculation formula of the hair contour line 530 can be formula (1):
  • hair_outline hair_seg-erode(seg) formula (1)
  • hair_outline represents the hair contour line 530
  • hair_seg represents the hair segmentation image 520
  • seg represents the portrait segmentation image 510 .
  • the matting region of interest in the original person image can be determined according to the hair contour line.
  • the face area in the original person image can be determined first, and the initial interest area can be obtained according to the face area. area.
  • face recognition can be performed on the original person image to determine the face area.
  • the face area only contains the image content of the face part of the person.
  • the shape of the face area can be a fixed shape, such as a fixed square, rectangle etc.
  • the hair segmented image can also be used to determine the face area in the original person image, the hair segmented image can include edge information that the hair area is around the face, and the hair area can be determined by using the edge information that the hair area is around the face face area.
  • the initial area of interest can be obtained based on the determined face area according to the preset area division rules.
  • the position and area size of the initial ROI can be determined according to the determined face area.
  • the region division rule may include that the face region is located in the middle of the initial region of interest, and the size of the initial region of interest is twice the size of the face region; or the lower border of the face region coincides with the lower border of the initial region of interest , and the size of the initial region of interest is 1.5 times that of the face region, etc.
  • the determined face region can also be directly used as the initial region of interest, but not limited thereto, and the region division rules can be set according to actual needs. For different original person images, the determined face regions may occupy different image areas, and the region division rules may also be adjusted accordingly.
  • the electronic device may respectively project the hair contour line on the abscissa axis and the ordinate axis of the original character image to obtain a first projection distribution of the hair contour line on the abscissa axis and a second projection distribution on the ordinate axis.
  • the axis of abscissa and the axis of ordinate belong to the same plane coordinate system, and the plane coordinate system may include an image coordinate system, a pixel coordinate system, and the like.
  • the first projection distribution can reflect the position of the hair contour line on the abscissa axis
  • the second projection distribution can reflect the position of the hair contour line on the ordinate axis.
  • the electronic device may correct the initial region of interest according to the first projection distribution and the second projection distribution to obtain the matting region of interest.
  • the correction may include using the first projection distribution and the second projection distribution to modify the size and and/or position adjustments.
  • the horizontal range of the matting region of interest can be fixed according to the first projection distribution of the hair contour line on the abscissa axis, and the vertical range of the matting region of interest can be fixed according to the second projection distribution of the hair contour line on the ordinate axis.
  • the horizontal range and vertical range determine the region of interest for matting.
  • the horizontal range may refer to the coordinate range of the matting region of interest on the abscissa axis of the original character image
  • the vertical range may refer to the coordinate range of the matting region of interest on the ordinate axis of the original character image, for example , the horizontal range is the abscissa Xa ⁇ Xb, and the vertical range is the ordinate Ym ⁇ Yn.
  • the electronic device may adjust the horizontal range of the initial region of interest according to the first projection distribution, so as to fix the horizontal range of the region of interest in the cutout.
  • the horizontal range of the initial region of interest is adjusted so that the horizontal range includes the first projection distribution, and the first projection distribution is located in the middle of the horizontal range.
  • the electronic device can adjust the vertical range of the initial region of interest according to the second projection distribution, so as to fix the vertical range of the region of interest in the matting.
  • the vertical range of the initial region of interest can be adjusted so that the vertical range includes the second projection distribution, and the minimum ordinate of the vertical range can be set to be smaller than the minimum ordinate of the second projection distribution, and the minimum ordinate of the vertical range is the same as the second projection distribution
  • the distance between the minimum ordinates of the two projection distributions is the first pixel distance
  • the maximum ordinate of the vertical range is greater than the maximum ordinate of the second projection distribution
  • the maximum ordinate of the second projection distribution is the same as the maximum ordinate of the second projection distribution
  • the distance between the coordinates is the second pixel distance.
  • the shape and size of the cutout region of interest can be set according to actual needs, for example, the shape can include rectangle, square, etc., and the above-mentioned first pixel distance, second pixel distance, etc. can be set according to actual needs.
  • the matting region of interest may be entirely within the original person image, or part of it may not be within the original person image.
  • Correcting the initial region of interest by using the hair contour line can ensure that the obtained matting region of interest contains a complete face region and includes a complete hair region, making the obtained matting region of interest more accurate, including more complete, Rich detail, which improves the accuracy of the subsequent calculation of the hair mask.
  • Fig. 5C is a schematic diagram of determining a region of interest in matting in an embodiment.
  • to calculate the hair contour line 540 of the original person image 550 first determine the face area 552 in the original person image 550 , and use the face area 552 to obtain an initial region of interest (not shown).
  • the hair contour line 540 can be projected on the abscissa axis and the ordinate axis of the original character image respectively to obtain the first projection distribution 542 on the abscissa axis and the second projection distribution 544 on the ordinate axis, and according to the first A projection distribution 542 and a second projection distribution 544 adjust the initial ROI to obtain a matted ROI 554 . It can be guaranteed that the matting region of interest 554 includes the complete human face region 552 and includes the complete hair region.
  • the original character image and the segmented portrait image corresponding to the original character image can be respectively Correction. If the original character image is a rotated image, the portrait area in the original character image is not vertical to the horizontal, that is, the portrait area is not positive, then the original character image and the portrait segmented image can be corrected first, so that the original character The portrait area in the image is perpendicular to the horizontal (keeps positive).
  • the original person image is a rotated image, which may be caused by the rotation of the original person image after post-image processing, or the rotation of the camera currently collecting the original person image.
  • the electronic device can determine a corrected matting region of interest according to the corrected original person image and the corrected segmented portrait image.
  • the process of determining the corrected region of interest in matting may be similar to the process of determining the region of interest in matting described in the above embodiments, and will not be repeated here.
  • the corrected matting region of interest can be rotated according to the rotation direction of the uncorrected original person image to obtain the uncorrected Matting regions of interest in raw person images.
  • the rotation direction may refer to the relative horizontal rotation direction of the portrait area in the uncorrected original person image.
  • Fig. 5D is a schematic diagram of correcting the original person image and the segmented image of the person in an embodiment.
  • the original character image 562 and the segmented portrait image 564 are rotated images, and the original character image 562 and the segmented portrait image 564 can be corrected first to obtain the corrected original character image 572 and the corrected portrait
  • the segmented image 574, the corrected original person image 572 and the corrected portrait segmented image 574 have a front orientation.
  • the corrected matting region of interest 582 can be determined according to the corrected original character image 572 and the corrected portrait segmentation image 574, and then the corrected matting region of interest 582 is rotated according to the rotation direction of the original character image 562, A matted region of interest 584 in the original person image 562 is obtained.
  • the original person image and the segmented portrait image are corrected first, which can make the recognized matting region of interest more accurate.
  • Step 404 respectively cropping the original person image and the segmented portrait image according to the cutout region of interest, to obtain the region of interest image and the region segmentation image corresponding to the region of interest image.
  • the area of interest in matting can be used as the cropping area of the original person image and the portrait segmentation image, the original person image is cropped to obtain the region of interest image, the portrait segmentation image is cropped to obtain the region segmentation image, the region segmentation image and the Region of interest image matching.
  • the matting region of interest of the original person image is firstly determined, and based on the matting region of interest, the original person image and the segmented portrait image are cropped to obtain the subsequent
  • the image of the region of interest and the region segmentation image used to generate the hair mask can improve the accuracy of the subsequently generated hair mask, and does not require the entire image to refer to the process of generating the hair mask, which can reduce the amount of calculation and improve image processing efficiency.
  • another image processing method is provided, which can be applied to the above-mentioned electronic device.
  • the method may include the steps of:
  • Step 602 preprocessing the original person image to obtain the ROI image of the original person image and the region segmentation image corresponding to the ROI image.
  • step 602 may participate in the relevant descriptions about preprocessing in the foregoing embodiments, and will not be repeated here.
  • Step 604 Input the image of the region of interest and the region segmentation image into the image processing model, and process the region of interest image and the region segmentation image through the image processing model to obtain a first hair mask.
  • the image processing model before inputting the region-of-interest image and the region-segmented image into the image processing model, it may be determined whether the image size of the region-of-interest image and the region-segmented image matches the corresponding input image size of the image processing model. If the image size of the region of interest image and the region segmentation image does not match the input image size corresponding to the image processing model, the image of the region of interest and the region segmentation image can be rotated and scaled first to obtain the image corresponding to the image processing model The input image size matches the ROI image and the region segmentation image.
  • the input image size corresponding to the image processing model is a vertical input size (the length of the image is smaller than the width), if the ROI image and the region segmentation image are horizontal images (the length of the image is larger than the width), the ROI image and After the region segmentation image is rotated 90 degrees clockwise or counterclockwise, it is then input into the image processing model, so as to ensure that the image size of the input region of interest image and region segmentation image is adapted to the image processing model, and the processing of the image processing model is improved. Accuracy.
  • Image processing models may include neural network models such as CNN (Convolutional Neural Networks, Convolutional Neural Networks).
  • the image processing model can be a neural network architecture of U-NET, which can connect the image of the region of interest and the image of the region segmentation, and input the image processing model.
  • the image processing model can include multiple down-sampling layers and multiple up-sampling layers.
  • the image processing model can perform multiple down-sampling and convolution processing on the image of the region of interest and the region segmentation image through multiple down-sampling layers, and then through multiple down-sampling layers. Upsampling layers perform multiple upsampling processes to obtain the first hair mask that is smaller than the input image or has the same resolution as the input image.
  • skip connections can be realized between the downsampling layer and upsampling layer between the same resolutions, and the features of the downsampling layer and upsampling layer between the same resolutions are fused to make the upsampling process more accurate .
  • Fig. 7 is a schematic diagram of generating a first hair mask through an image processing model in an embodiment.
  • the region-of-interest image 712 and the corresponding region segmentation image 714 can be input into the image processing model 720, and the image processing model 720 can process the region-of-interest image 712 and the region segmentation image 714, and output the first hair mask 732 .
  • the image processing model can be obtained by training according to multiple sets of sample training images.
  • Each set of sample training images can include a sample character image, a sample portrait segmentation image corresponding to the sample character image, and a sample hair mask.
  • each The set of sample training images may also include sample person images carrying hair region information and corresponding sample person segmentation images.
  • the sample character image and the sample segmented portrait image may be cropped or scaled images according to a set size, which can ensure that the sizes of the images input to the image processing model remain consistent.
  • a set of sample training images can be input into the image processing model to be trained, and the image processing model to be trained can process the input sample person images and sample portrait segmentation images to obtain the predicted hair mask , the predicted hair mask can be compared with the sample hair mask, and the loss of the predicted hair mask relative to the sample hair mask can be calculated through the loss function, and then the parameters of the image processing model can be adjusted according to the loss until the calculated If the loss is less than the preset loss threshold, or the number of parameter adjustments reaches the number threshold, etc., the convergence condition of the image processing model is satisfied.
  • the above loss function may include at least one of L1 loss function and L2 loss function, etc.
  • the L1 loss function is the sum of the absolute value of the difference between the predicted hair mask and the sample hair mask
  • L2 The loss function is calculated by computing the sum of the squares of the difference between the predicted hair mask and the sample hair mask.
  • the background area is misjudged as the foreground area and not blurred when performing blurring processing on the person image, it will be more difficult than the situation where the foreground area is misjudged as the background area and blurred. Conspicuous, therefore, when calculating the loss of the predicted hair mask relative to the sample hair mask, you can focus on the situation where the background area is misjudged as the foreground area.
  • the background area is misjudged as the loss coefficient corresponding to the foreground area It can be greater than the loss coefficient corresponding to the foreground area being misjudged as the background area.
  • the loss function can be formula (2):
  • L(y, t) represents the loss of the predicted hair mask relative to the sample hair mask
  • can be the threshold value set
  • can be a judgment function, which is used to judge whether t is less than ⁇ , if it is less than 1, output 1, If not less than, output 0, y may refer to the predicted hair mask
  • t may be the sample hair mask.
  • the hair region in the sample character image may have some translucency (such as less hair strands or the effect of hair strands flying up), if in the corresponding sample hair mask Marking the translucent hair area may lead to poor image processing effect after the foreground portrait area and background image are separated. For example, when blurring the background area, if the generated hair mask marks all the semi-transparent hair areas in the foreground portrait area, the background area will pass through the semi-transparent hair area, resulting in ineffective blur effect. nature. Therefore, in the embodiment of the present application, the sample hair mask can be enhanced.
  • the sample hair mask may be obtained by performing erosion processing on the background complexity image corresponding to the sample character image.
  • the complex background area can be determined by using the background complexity map of the sample person image, and the hair area around the complex background area in the first hair mask is eroded to reduce the mask area around the complex background area.
  • the image processing model is trained through the enhanced sample hair mask, so that the trained image processing model can reduce the labeling of translucent hair, so as to improve the subsequent image processing effect.
  • the image resolution of the first hair mask generated by the electronic device based on the region-of-interest image and the region-segmented image may be relatively small. Therefore, the step optimizes the first hair mask to obtain the original person image
  • the corresponding target hair mask may include steps 606 and 608 .
  • Step 606 optimize the first hair mask to obtain a second hair mask.
  • the first hair mask generated by the image processing model is not accurate enough, the first hair mask can be optimized to correct the first hair mask generated by the image processing model to obtain a more accurate and detailed second hair mask. membrane.
  • the first The hair mask is rotated so that the direction of the first hair mask is consistent with that of the portrait area in the original person image, and then the rotated first hair mask is optimized.
  • the electronic device optimizes the first hair mask to obtain the second hair mask, which may include but not limited to any of the following processing methods, or any of the following processing methods Any combination of processing methods:
  • Method 1 Calculate the background complexity image corresponding to the ROI image, and perform erosion processing on the first hair mask according to the background complexity image to obtain the second hair mask.
  • the background complexity image corresponding to the ROI image can include the background complexity of the ROI image, which can be used to describe the complexity of the background area in the ROI image. The more image features the background area contains, the corresponding The complexity can be higher. Because in the image with high background complexity, it is easy for the background area to be mistaken for the foreground area, therefore, the background complexity of the image of the region of interest can be calculated, and the first hair mask can be eroded using the background complexity , to reduce the situation where background regions are mistaken for foreground regions.
  • the step of calculating the background complexity image corresponding to the ROI image may include steps 802 - 808 .
  • Step 802 acquiring a grayscale image of the ROI image.
  • a grayscale image is an image with only one sampled color per pixel, which appears as a gray scale from black to white.
  • the memory of the electronic device may pre-store the grayscale image corresponding to the original person image, and the grayscale image corresponding to the original person image may be cropped according to the determined region of interest in matting to obtain the grayscale image of the region of interest image.
  • the electronic device may convert the image of the region of interest from RGB format or YUV format to a grayscale image.
  • Step 804 performing edge detection on the grayscale image to obtain a first edge image.
  • the electronic device can use Canny edge detection operator, Laplacian detection operator, DoG detection operator, Sophier detection operator, etc. to perform edge detection on the grayscale image, and obtain the first edge image including all edge information in the grayscale image. It should be noted that the embodiment of the present application does not limit a specific edge detection algorithm.
  • Step 806 Remove hair edges in the first edge image according to the first hair mask to obtain a second edge image.
  • the hair region in the first edge image can be determined according to the first hair mask, and the hair edges in the hair region in the first edge image are removed to obtain a second edge image that retains edges other than the hair region. Removing the hair edge in the first edge image can prevent the inaccurate calculation of the background complexity due to the influence of the hair edge on the edge of the background region. Since this application is aimed at the accurate positioning of the hair region, using the first hair mask to remove the hair edge in the first edge image can make the calculated background complexity more accurate and more suitable for the accuracy of the hair region. Positioning scheme.
  • Step 808 perform dilation and blur processing on the second edge image to obtain a background complexity image.
  • the electronic device can expand and blur the edges in the second edge image, so as to enlarge the edges in the second edge image, make edge features more obvious, and improve the accuracy of background complexity calculation.
  • the dilation process is a local maximization operation
  • the kernel can be used to perform convolution with the edge in the second edge image, and the pixels covered by the kernel can be calculated to make the edge grow.
  • the blurring processing may adopt Gaussian blurring, mean blurring, median blurring and other processing methods, and the specific dilation processing method and blurring processing method are not limited in the embodiment of the present application.
  • the background complexity can be calculated according to the dilated and blurred second edge image to obtain a corresponding background complexity image.
  • the background complexity can be calculated according to the edges in the background area in the second edge image after dilation and blur processing, and the background area that contains more edges corresponds to a higher background complexity, and contains fewer edges The background region corresponding to the lower background complexity.
  • a complexity threshold can be set, and in the entire background area, the area whose background complexity is greater than the complexity threshold can be defined as the background complex area, and the area whose background complexity is less than or equal to the complexity threshold can be defined as A simple area for the background.
  • Different values (such as brightness value, gray value or color value, etc.) can be used to represent the complex background area and the simple background area respectively, so as to obtain the background complexity image.
  • FIG. 9A is a schematic diagram of calculating background complexity in an embodiment.
  • the grayscale image 910 of the image of the region of interest can be obtained first, and edge detection is performed on the grayscale image 910 to obtain the first edge image 920, and then the first hair mask 912 matched with the grayscale image 910
  • the hair edge in the first edge image 920 is removed to obtain the second edge image 930, and the edge except the hair area is reserved in the second edge image 930.
  • the second edge image 930 may be expanded and blurred to obtain an edge image 940, and then the background complexity is calculated based on the edge image 940 to obtain a background complexity image.
  • Using the edge feature to calculate the background complexity can improve the accuracy of the background complexity, and can further improve the accuracy of the subsequent optimization of the first hair mask by using the background complexity.
  • the electronic device can perform erosion processing on the first hair mask according to the background complexity image to obtain the second hair mask.
  • different values can be used to represent the background complex area and the background simple area. For example, it can be represented by different gray values.
  • the area with a gray value of 255 represents a simple background area
  • the area with a gray value of 0 represents Areas with complex backgrounds can also be represented by different color values, white indicates areas with simple backgrounds, and black indicates areas with complex backgrounds, but not limited thereto.
  • Erosion processing can be performed on the hair area around the complex background area in the first hair mask, so as to reduce the mask around the complex background area and improve the situation that the background area is mistaken for the foreground area.
  • erosion processing is a local minimum operation, which can be calculated by using the mask around the complex background area in the kernel and the first hair mask, and retaining the pixels covering the kernel, that is, using the complex background area to realize The effect of etching around the mask.
  • the first hair mask after corrosion treatment can be directly used as the second hair mask.
  • the first hair mask before the corrosion treatment (that is, the initially obtained first hair mask) can be combined with the first hair mask after the corrosion treatment.
  • the films are fused to obtain a second hair mask.
  • the merging manner may include but not limited to taking an average value for merging, allocating different weight coefficients for merging, and the like.
  • the first hair mask before the corrosion treatment and the first hair mask after the corrosion treatment can be subjected to Alpha fusion processing, and the Alpha fusion treatment can be the first hair mask before the corrosion treatment and the first hair mask after the corrosion treatment.
  • Each pixel in the hair mask is assigned an Alpha value, so that the first hair mask before the erosion process and the first hair mask after the erosion process have different transparency.
  • the background complexity image can be used as the Alpha value of the first hair mask after corrosion processing, and the first hair mask before corrosion processing and the first hair mask after corrosion processing can be compared according to the background complexity image. Each pair of matching pixels in the mask is fused to obtain the second hair mask.
  • Fig. 9B is a schematic diagram of fusing the first hair mask before the etching treatment and the first hair mask after the etching treatment in one embodiment.
  • the first hair mask before the corrosion treatment and the first hair mask after the corrosion treatment can be subjected to Alpha fusion processing, and the formula of Alpha fusion processing can be as shown in formula (3):
  • I 1 represents the first hair mask 954 after the corrosion process
  • I 2 represents the first hair mask 952 before the corrosion process
  • represents the Alpha value of the first hair mask 954 after the corrosion process
  • I represents the result of fusion 958 for the second hair mask.
  • the background complexity image 956 can be used as the Alpha value ⁇ of the first hair mask 954 after corrosion processing, and Alpha fusion processing is performed on the first hair mask 954 after corrosion processing and the first hair mask 952 before corrosion processing , to obtain the second hair mask 958 .
  • Fusing the first hair mask before corrosion processing with the first hair mask after corrosion processing, and using the background complexity image as the Alpha value for fusion can improve the accuracy of the obtained second hair mask and improve the background
  • the situation where the area is mistaken for the foreground area improves the effect of subsequent image processing.
  • Method 2 Fill holes in the hair region of the first hair mask to obtain a second hair mask.
  • holes in the hair region of the first hair mask may be filled.
  • the confidence degree of the hair region of the first hair mask may be calculated, and holes in the hair region may be filled according to the confidence degree.
  • the first hair mask can be used to determine the hair region in the region of interest, and the first hair mask can be calculated according to the image characteristics (such as edge characteristics, color characteristics, brightness characteristics, etc.) of the hair region in the region of interest. Confidence of the hair region of the membrane. A hair mask region with a higher confidence indicates a higher possibility of belonging to a real hair region and a higher accuracy. It should be noted that other methods may also be used to calculate the confidence level, which is not limited here.
  • the hair region of the first hair mask can be divided according to the preset confidence threshold, and the hair mask region whose confidence is higher than the confidence threshold is extracted, and the hair mask region is expanded, and further, Erosion processing may also be performed on the hair mask region whose confidence level is not higher than the confidence threshold, so as to achieve the effect of filling holes in the hair region of the first hair mask.
  • the first hair mask after the filling treatment can be directly used as the second hair mask.
  • the first hair mask after the filling process can also be fused with the first hair mask before the filling process to obtain the second hair mask
  • the fusion method can include but not limited to mean fusion, Allocation of different weights for fusion, etc., can also be Alpha fusion, and Alpha fusion is performed on the first hair mask after filling processing and the first hair mask before filling processing according to the set Alpha value.
  • the specific fusion method may be similar to the method of fusing the first hair mask before the corrosion treatment and the first hair mask after the corrosion treatment in the above embodiment, and reference may be made to the relevant description above, which will not be repeated here.
  • Figure 10 is a schematic diagram of filling holes in the first hair mask in one embodiment.
  • the holes in the first hair mask 1010 can be filled to obtain a second hair mask with the holes filled, which can improve the subsequent blurring of the hair area when blurring the background area of the original character image.
  • the background inside is also blurred, resulting in blurred portraits, which improves the effect of subsequent image processing.
  • Mode 3 Enhance the edge of the hair region of the first hair mask to obtain the second hair mask.
  • the enhancement processing may include but not limited to histogram equalization-based enhancement processing, Laplacian-based enhancement processing, logarithmic-Log transformation-based enhancement processing, etc., which is not limited in this embodiment of the present application.
  • the sigmoid function can be used to enhance the edge of the hair region of the first hair mask, and the sigmoid function is used to calculate the pixels on the edge of the hair region of the first hair mask to obtain the second Hair mask.
  • Fig. 11 is a schematic diagram of enhancing the hair region of the first hair mask in an embodiment.
  • the edge of the hair region of the first hair mask 1110 may be enhanced to obtain a second hair mask 1120 with clearer edges.
  • the subsequently obtained foreground portrait region can be made clearer and the image processing effect can be improved.
  • Method 4 If the image scene corresponding to the original person image is the target scene, soften the edges of the hair region of the first hair mask to obtain a second hair mask.
  • the target scene is a scene with a scene brightness value lower than a brightness threshold, such as a night scene, a dark indoor scene, and the like.
  • a brightness threshold such as a night scene, a dark indoor scene, and the like.
  • the edge definition of the foreground character image is high, it may cause the blurred edge to look unnatural and affect the image processing effect . Therefore, in the embodiment of the present application, it can first be judged whether the image scene corresponding to the original person image is the target scene, and if it is the target scene, the edge of the hair region of the first hair mask can be softened so that the first The edges of the hair area of the hair mask are blurred to improve the image after subsequent bokeh processing.
  • the softening process may use Gaussian filtering, mean filtering, median filtering and other processing manners, which are not limited herein.
  • the scene classification model can be obtained by training according to a large number of sample images of the target scene.
  • the scene classification model can extract the original character image image features, and judge whether the original character image belongs to the target scene according to the image features.
  • the electronic device can acquire the sensitivity value (ISO) corresponding to the original character image, and the sensitivity value can be used to measure the sensitivity of the film to light. If the original person image is an image captured by the electronic device in real time through the camera, the current photosensitive value of the camera can be obtained directly; if the original person image is an image stored in the memory, the shooting parameters related to the original person image can be read from the memory , so as to obtain the sensitivity value.
  • ISO sensitivity value
  • the photosensitivity threshold may be an empirical value obtained through multiple experiments and tests.
  • Fig. 12 is a schematic diagram of softening the first hair mask in one embodiment.
  • the edge of the hair region of the first hair mask 1210 can be softened to obtain a second hair mask 1220 with blurred edges .
  • By softening the edge of the hair area of the first hair mask it is possible to make the edge transition of the portrait more natural and improve the blur effect when the background area of the original character image in the target scene is subsequently blurred. .
  • the background complexity image corresponding to the image of the region of interest can be calculated first, and the first hair mask is corroded according to the background complexity image, and then Holes in the hair region of the first hair mask after the erosion treatment are filled to obtain a second hair mask.
  • the background complexity image corresponding to the region-of-interest image can be calculated first, and the first hair mask is eroded according to the background complexity image, and then the holes in the hair region of the eroded first hair mask are Carry out filling, then carry out enhancement processing to the edge of the hair region of the first hair mask after filling, if the image scene corresponding to the original character image is the target scene, then the hair region of the first hair mask after the enhancement processing can be The edge of the image is softened to obtain a second hair mask. If the image scene corresponding to the original person image is not the target scene, the enhanced first hair mask can be used as the second hair mask.
  • a more detailed and accurate second hair mask can be obtained, which can improve the subsequent image processing of the original person image such as foreground and background separation. image processing effects.
  • Step 608 Perform upsampling and filtering on the second hair mask to obtain a target hair mask corresponding to the original person image.
  • the resolution of the first hair mask output by the image processing model is small, the resolution of the second hair mask obtained after optimizing the first hair mask is also low, and the second hair mask can be Perform upsampling and filtering processing, enlarge the second hair mask, and obtain the target hair mask matching the original character image, so as to use the target hair mask to accurately locate the hair area in the original character image.
  • the grayscale image of the region-of-interest image may be used as a guide image of the guide filter, and the guide filter is used to perform upsampling filtering on the second hair mask to obtain the target hair mask.
  • the guide filter performs upsampling filtering on the second hair mask, it can refer to the image information of the grayscale image of the region of interest image, so that the texture and edge characteristics of the output target hair mask are similar to the grayscale image .
  • Fig. 13 is a schematic diagram of performing upsampling filtering on the second hair mask through a guided filter in an embodiment.
  • the size of the second hair mask 1310 can be enlarged first to obtain the enlarged second hair mask 1320, and then the grayscale image 1330 is used as the guide image, and the enlarged second hair mask 1320 can be obtained through the guide filter.
  • the hair mask 1320 undergoes guided filtering to obtain a target hair mask 1330 .
  • the electronic device may also perform upsampling filtering on the second hair mask according to the background complexity of the image of the region of interest.
  • the background complexity of the region of interest image is low, it means that the background of the region of interest image is relatively simple, then the guided filter can be used to perform upsampling filtering on the second hair mask; in the background of the region of interest image
  • the bilinear interpolation algorithm can be directly used to perform upsampling and filtering on the second hair mask. This can prevent the problem that the background area is mistaken for the hair area when the background of the image of the region of interest is relatively complex, and improve the accuracy of the target hair mask.
  • the electronic device can first divide the second hair mask into regions according to the background complexity image corresponding to the region of interest image, and obtain the simple background region and the complex background region.
  • the background area equal to the complexity threshold
  • the background complex area is the background area whose complexity is higher than the complexity threshold.
  • different filtering methods can be used for upsampling filtering processing.
  • guided filtering can be used for upsampling filtering.
  • the grayscale image of the region of interest image can be used as the guiding image of the guiding filter, and the hair area around the simple background area in the second hair mask is subjected to upsampling filtering through the guiding filter to obtain the first filtering result.
  • a bilinear interpolation algorithm can be used for upsampling filtering.
  • a bilinear interpolation algorithm may be used to perform upsampling and filtering on the hair region around the complex background region in the second hair mask to obtain a second filtering result.
  • the bilinear interpolation algorithm is a linear interpolation extension of the interpolation function with two variables. Its core idea is to perform a linear interpolation in two directions respectively.
  • the bilinear interpolation algorithm uses the known pixels in the second hair mask Interpolation is performed on the enlarged unknown pixels, and for each pixel that needs to be interpolated, it can be calculated based on four known pixels.
  • the electronic device can fuse the first filtering result and the second filtering result to obtain the target hair mask.
  • the first filtering result and the second filtering result can be subjected to Alpha fusion processing
  • the background complexity image can be used as the Alpha value of the second filtering result
  • the background complexity image can be used to analyze the first filtering result and the second filtering result.
  • Alpha fusion processing is performed on the filtering results to obtain the target mask image.
  • upsampling filtering methods can be used respectively, which can reduce the situation where the background area is mistaken for the hair area and improve the accuracy of the target hair mask .
  • upsampling filtering processing methods may also be used, such as a bi-cubic interpolation algorithm, a nearest neighbor interpolation algorithm, etc., which are not limited in this embodiment of the present application.
  • the electronic device may blur the background area of the original person image according to the target hair mask to obtain the target person image.
  • the hair area of the original person image can be determined according to the target hair mask, so that the image area can be accurately determined and the separation of the image area and the background area can be realized.
  • the separated background area can be blurred, and then the blurred background area and the portrait area can be spliced to obtain the target person image. After the background area is blurred, the portrait area can be highlighted.
  • the target hair mask carefully and accurately locates the hair area, it can realize the separation of the hair-level portrait area and the background area, improve the accuracy of the separation of the foreground and the background, and make the image of the target person obtained after the blurring process more natural , which improves the bokeh effect of the image.
  • the first hair mask after obtaining the image of the region of interest and the corresponding region segmentation image, can be generated through the image processing model, and the first hair mask output by the image processing model can be optimized and corrected. Obtain a more refined and accurate second hair mask, and then perform upsampling filtering on the second hair mask to obtain a higher-resolution target hair mask, so that the fineness and accuracy of the target hair mask are higher.
  • the target hair mask can be used to accurately locate the hair region in the original person image, thereby improving the image processing effect of subsequent image processing such as foreground and background separation on the original person image.
  • an image processing apparatus 1400 is provided, which can be applied to the above-mentioned electronic equipment.
  • the image processing device 1400 may include a preprocessing module 1410 , a mask generation module 1420 and an optimization module 1430 .
  • the preprocessing module 1410 is configured to preprocess the original person image to obtain an ROI image of the original person image and a region segmentation image corresponding to the ROI image, where the region segmentation image includes portrait region information of the ROI image.
  • the mask generation module 1420 is configured to generate a first hair mask according to the ROI image and the region segmentation image.
  • the optimization module 1430 is configured to optimize the first hair mask to obtain a target hair mask corresponding to the original character image.
  • the ROI image of the original person image and the region segmentation image corresponding to the ROI image are obtained, and the ROI image and the region segmentation image are generated according to the ROI image and the region segmentation image.
  • the first hair mask, and optimize the first hair mask to obtain the target hair mask corresponding to the original character image after generating the first hair mask, optimize and correct the first hair mask, A finer and more accurate target hair mask is obtained, which can be used to accurately locate the hair region in the original person image, thereby improving the image processing effect of subsequent image processing such as foreground and background separation on the original person image .
  • the preprocessing module 1410 includes a determining unit and a cropping unit.
  • the determination unit is configured to determine the matting region of interest in the original person image according to the original person image and the portrait segmentation image corresponding to the original person image, the portrait segmentation image is an image obtained after portrait extraction from the original person image, and the portrait The segmented image includes portrait region information of the original person image.
  • the determination unit is further configured to obtain the hair segmentation image corresponding to the original person image, calculate the hair contour line according to the hair segmentation image and the portrait segmentation image, and determine the cutout in the original person image according to the hair contour line area of interest.
  • the hair segmentation image is an image obtained by performing hair segmentation on the original person image, and the hair segmentation image includes hair region information of the original person image.
  • the determining unit is further configured to determine the face area in the original person image, and obtain an initial region of interest according to the face area, and place the hair contour line on the abscissa axis and the ordinate axis of the original person image respectively. Perform projection to obtain the first projection distribution of the hair contour on the abscissa axis and the second projection distribution on the ordinate axis, and correct the initial region of interest according to the first projection distribution and the second projection distribution to obtain a sense of matting area of interest.
  • the preprocessing module 1410 further includes a correction unit.
  • the correcting unit is configured to correct the original character image and the segmented portrait image corresponding to the original character image if the original character image is a rotated image.
  • the determination unit is also used to determine the corrected matting region of interest according to the corrected original character image and the corrected portrait segmentation image, and to adjust the corrected matting sense according to the rotation direction of the uncorrected original character image.
  • the region of interest is rotated to obtain the matted region of interest in the uncorrected original person image.
  • the cropping unit is configured to respectively crop the original person image and the segmented portrait image according to the region of interest in the cutout, to obtain the region of interest image and the region segmentation image corresponding to the region of interest image.
  • the matting region of interest of the original person image is firstly determined, and based on the matting region of interest, the original person image and the segmented portrait image are cropped to obtain the subsequent
  • the image of the region of interest and the region segmentation image used to generate the hair mask can improve the accuracy of the subsequently generated hair mask, and does not require the entire image to refer to the process of generating the hair mask, which can reduce the amount of calculation and improve image processing efficiency.
  • the mask generation module 1420 is further configured to input the region-of-interest image and the region-segmented image into the image processing model, and process the region-of-interest image and the region-segmented image through the image processing model to obtain the first hair mask
  • the image processing model is obtained by training according to multiple sets of sample training images, and each set of sample training images includes a sample person image, a sample portrait segmentation image corresponding to the sample person image, and a sample hair mask.
  • the sample hair mask is obtained by performing erosion processing on the background complexity image corresponding to the sample person image.
  • the optimization module 1430 includes an optimization sub-module and a filtering sub-module.
  • the optimization sub-module is used to optimize the first hair mask to obtain the second hair mask.
  • the filtering sub-module is configured to perform upsampling and filtering on the second hair mask to obtain a target hair mask corresponding to the original person image.
  • the optimization sub-module may include one or more of an erosion unit, a filling unit, an enhancement unit, and a softening unit.
  • the erosion unit is configured to calculate a background complexity image corresponding to the region of interest image, and perform erosion processing on the first hair mask according to the background complexity image to obtain a second hair mask.
  • the erosion unit is further configured to acquire a grayscale image of the region of interest image, perform edge detection on the grayscale image to obtain a first edge image, and remove the grayscale image in the first edge image according to the first hair mask
  • the hair edge is obtained by obtaining a second edge image, and the second edge image is expanded and blurred to obtain a background complexity image.
  • the corrosion unit is further configured to determine, according to the background complexity image, a complex background area in the first hair mask whose complexity is greater than a complexity threshold, and to perform a calculation on the hairs around the complex background area in the first hair mask. Erosion processing is performed on the region, and the first hair mask before the etching processing is fused with the first hair mask after the etching processing to obtain a second hair mask.
  • the filling unit is configured to fill holes in the hair region of the first hair mask to obtain a second hair mask.
  • the enhancement unit is configured to perform enhancement processing on edges of the hair region of the first hair mask to obtain a second hair mask.
  • the softening unit is used to soften the edge of the hair region of the first hair mask if the image scene corresponding to the original character image is the target scene to obtain the second hair mask.
  • the target scene is that the scene brightness value is lower than The brightness threshold of the scene.
  • the softening unit is further configured to acquire the photosensitive value corresponding to the original person image, and if the photosensitive value is greater than the photosensitive threshold, then determine that the image scene corresponding to the original person image is the target scene, and apply the first hair mask The edges of the hair area are softened to get the second hair mask.
  • the optimization module 1430 is also used to calculate the background complexity image corresponding to the image of the region of interest through the erosion unit, and perform erosion processing on the first hair mask according to the background complexity image, and then perform erosion processing on the first hair mask through the filling unit.
  • the holes in the hair region of the processed first hair mask are filled, and then the edge of the hair region of the filled first hair mask is enhanced by increasing the unit, and used to determine the original character if the original character is determined by the softening unit
  • the image scene corresponding to the image is the target scene, then the edge of the hair region of the enhanced first hair mask is softened to obtain the second hair mask, if the image scene corresponding to the original person image is not the target scene , the enhanced first hair mask is used as the second hair mask.
  • the filtering sub-module is further configured to use the grayscale image of the region of interest image as the guiding image of the guiding filter, and perform upsampling and filtering processing on the second hair mask through the guiding filter to obtain the original person image The corresponding target hair mask.
  • the filtering sub-module is further configured to divide the second hair mask according to the background complexity image corresponding to the region of interest image to obtain simple background regions and complex background regions, and convert the gray area of the region of interest image to The degree image is used as the guide image of the guide filter, and the hair region around the simple background area in the second hair mask is upsampled and filtered by the guide filter to obtain the first filtering result, and the second hair mask is processed by bilinear interpolation algorithm In the second hair mask, the hair region around the complex background region is subjected to upsampling and filtering processing to obtain a second filtering result, and then the first filtering result and the second filtering result are fused to obtain a target hair mask.
  • the background simple area is the background area whose complexity is lower than or equal to the complexity threshold
  • the background complex area is the background area whose complexity is higher than the complexity threshold.
  • the above-mentioned image processing apparatus 1400 includes a blurring module in addition to the preprocessing module 1410 , the mask generation module 1420 and the optimization module 1430 .
  • the blurring module is configured to blur the background area of the original character image according to the target hair mask to obtain the target character image.
  • the first hair mask after obtaining the image of the region of interest and the corresponding region segmentation image, can be generated through the image processing model, and the first hair mask output by the image processing model can be optimized and corrected. Obtain a more refined and accurate second hair mask, and then perform upsampling filtering on the second hair mask to obtain a higher-resolution target hair mask, so that the fineness and accuracy of the target hair mask are higher.
  • the target hair mask can be used to accurately locate the hair region in the original person image, thereby improving the image processing effect of subsequent image processing such as foreground and background separation on the original person image.
  • Fig. 15 is a structural block diagram of an electronic device in one embodiment.
  • an electronic device 1500 may include one or more of the following components: a processor 1510, a memory 1520 coupled to the processor 1510, wherein the memory 1520 may store one or more computer programs, one or more computer programs It may be configured to implement the methods described in the foregoing embodiments when executed by one or more processors 1510 .
  • Processor 1510 may include one or more processing cores.
  • the processor 1510 uses various interfaces and circuits to connect various parts of the entire electronic device 1500, and executes or executes instructions, programs, code sets or instruction sets stored in the memory 1520, and calls data stored in the memory 1520 to execute Various functions of the electronic device 1500 and processing data.
  • the processor 1510 may adopt at least one of Digital Signal Processing (Digital Signal Processing, DSP), Field-Programmable Gate Array (Field-Programmable Gate Array, FPGA), and Programmable Logic Array (Programmable Logic Array, PLA). implemented in the form of hardware.
  • DSP Digital Signal Processing
  • FPGA Field-Programmable Gate Array
  • PLA Programmable Logic Array
  • the processor 1510 may integrate one or a combination of a central processing unit (Central Processing Unit, CPU), an image processor (Graphics Processing Unit, GPU) and a modem.
  • CPU Central Processing Unit
  • GPU Graphics Processing Unit
  • the CPU mainly handles the operating system, user interface and application programs, etc.
  • the GPU is used to render and draw the displayed content
  • the modem is used to handle wireless communication. It can be understood that, the above-mentioned modem may not be integrated into the processor 1510, but may be realized by a communication chip alone.
  • the memory 1520 may include random access memory (Random Access Memory, RAM), and may also include read-only memory (Read-Only Memory, ROM).
  • the memory 1520 may be used to store instructions, programs, codes, sets of codes or sets of instructions.
  • the memory 1520 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system and instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.) , instructions for implementing the foregoing method embodiments, and the like.
  • the storage data area can also store data created by the electronic device 1500 during use, and the like.
  • the electronic device 1500 may include more or fewer structural elements than those in the above structural block diagram, for example, including a power module, a physical button, a WiFi (Wireless Fidelity, wireless fidelity) module, a speaker, a Bluetooth module, a sensor, etc. , and may not be limited here.
  • the embodiment of the present application discloses a computer-readable storage medium, which stores a computer program, wherein, when the computer program is executed by a processor, the methods described in the above-mentioned embodiments are implemented.
  • the embodiment of the present application discloses a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program can be executed by a processor to implement the methods described in the foregoing embodiments.
  • the processes in the methods of the above embodiments can be realized through computer programs to instruct related hardware, and the programs can be stored in a non-volatile computer-readable storage medium When the program is executed, it may include the processes of the embodiments of the above-mentioned methods.
  • the storage medium may be a magnetic disk, an optical disk, a ROM, or the like.
  • Non-volatile memory may include ROM, Programmable ROM (PROM), Erasable PROM (Erasable PROM, EPROM), Electrically Erasable PROM (Electrically Erasable PROM, EEPROM) or flash memory.
  • Volatile memory can include random access memory (RAM), which acts as external cache memory.
  • RAM can take many forms, such as static RAM (Static RAM, SRAM), dynamic RAM (Dynamic Random Access Memory, DRAM), synchronous DRAM (synchronous DRAM, SDRAM), double data rate SDRAM (Double Data Rate) Data Rate SDRAM, DDR SDRAM), enhanced SDRAM (Enhanced Synchronous DRAM, ESDRAM), synchronous link DRAM (Synchlink DRAM, SLDRAM), memory bus direct RAM (Rambus DRAM, RDRAM) and direct memory bus dynamic RAM (Direct Rambus DRAM) , DRDRAM).
  • the units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, located in one place, or distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
  • each functional unit in each embodiment of the present application may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit.
  • the above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.

Landscapes

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

Abstract

Embodiments of the present application disclose an image processing method and apparatus, an electronic device, and a computer-readable storage medium. The method comprises: preprocessing an original person image to obtain a region of interest image of the original person image and a region segmentation image corresponding to the region of interest image, the region segmentation image comprising portrait region information of the region of interest image; generating a first hair mask according to the region of interest image and the region segmentation image; and optimizing the first hair mask so as to obtain a target hair mask corresponding to the original person image. According to the image processing method and apparatus, the electronic device, and the computer-readable storage medium, an accurate hair mask corresponding to a person image can be obtained, so that the hair mask can be used to accurately position a hair region in the person image, thereby improving the image processing effect.

Description

图像处理方法、装置、电子设备及计算机可读存储介质Image processing method, device, electronic device, and computer-readable storage medium 技术领域technical field
本申请涉及影像技术领域,具体涉及一种图像处理方法、装置、电子设备及计算机可读存储介质。The present application relates to the field of image technology, in particular to an image processing method, device, electronic equipment, and computer-readable storage medium.
背景技术Background technique
在影像技术领域中,对于图像中的前景区域及背景区域进行分离是比较常见的一种图像处理过程。对于包含有人物的人物图像,在进行前景的人像区域与背景区域分离时,由于人的头发细节较多,人像的头发区域很难准确地进行分离,影响人物图像的前景及背景的分离效果。In the field of image technology, it is a relatively common image processing process to separate the foreground area and the background area in the image. For a person image containing a person, when separating the foreground portrait area from the background area, it is difficult to accurately separate the hair area of the portrait due to the many details of human hair, which affects the separation effect of the foreground and background of the person image.
发明内容Contents of the invention
本申请实施例公开了一种图像处理方法、装置、电子设备及计算机可读存储介质,能够得到人物图像对应的准确的头发掩膜,从而可利用该头发掩膜准确定位人物图像中的头发区域,提高了图像处理效果。The embodiment of the present application discloses an image processing method, device, electronic equipment, and computer-readable storage medium, which can obtain an accurate hair mask corresponding to a character image, so that the hair mask can be used to accurately locate the hair region in the character image , which improves the image processing effect.
本申请实施例公开了一种图像处理方法,包括:对原始人物图像进行预处理,得到所述原始人物图像的感兴趣区域图像,以及与所述感兴趣区域图像对应的区域分割图像,所述区域分割图像包括所述感兴趣区域图像的人像区域信息;根据所述感兴趣区域图像及所述区域分割图像生成第一头发掩膜;对所述第一头发掩膜进行优化处理,以得到所述原始人物图像对应的目标头发掩膜。The embodiment of the present application discloses an image processing method, including: preprocessing the original person image, obtaining the ROI image of the original person image, and the region segmentation image corresponding to the ROI image, the The region segmentation image includes portrait area information of the region of interest image; generating a first hair mask according to the region of interest image and the region segmentation image; optimizing the first hair mask to obtain the The target hair mask corresponding to the original character image.
本申请实施例公开了一种图像处理装置,包括:预处理模块,用于对原始人物图像进行预处理,得到所述原始人物图像的感兴趣区域图像,以及与所述感兴趣区域图像对应的区域分割图像,所述区域分割图像包括所述感兴趣区域图像的人像区域信息;掩膜生成模块,用于根据所述感兴趣区域图像及所述区域分割图像生成第一头发掩膜;优化模块,用于对所述第一头发掩膜进行优化处理,以得到所述原始人物图像对应的目标头发掩膜。The embodiment of the present application discloses an image processing device, including: a preprocessing module, configured to preprocess the original character image, obtain the ROI image of the original character image, and the ROI image corresponding to the ROI image Region segmentation image, the region segmentation image includes portrait area information of the region of interest image; mask generation module, used to generate a first hair mask according to the region of interest image and the region segmentation image; optimization module , for optimizing the first hair mask to obtain a target hair mask corresponding to the original person image.
本申请实施例公开了一种电子设备,包括存储器及处理器,所述存储器中存储有计算机程序,所述计算机程序被所述处理器执行时,使得所述处理器执行如下步骤:对原始人物图像进行预处理,得到所述原始人物图像的感兴趣区域图像,以及与所述感兴趣区域图像对应的区域分割图像,所述区域分割图像包括所述感兴趣区域图像的人像区域信息;根据所述感兴趣区域图像及所述区域分割图像生成第一头发掩膜;对所述第一头发掩膜进行优化处理,以得到所述原始人物图像对应的目标头发掩膜。The embodiment of the present application discloses an electronic device, including a memory and a processor, the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the following steps: The image is preprocessed to obtain the ROI image of the original person image, and the region segmentation image corresponding to the ROI image, and the region segmentation image includes the portrait region information of the ROI image; according to the The region of interest image and the region segmentation image are used to generate a first hair mask; and the first hair mask is optimized to obtain a target hair mask corresponding to the original person image.
本申请实施例公开了一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时,使得所述处理器执行如下步骤:对原始人物图像进行预处理,得到所述原始人物图像的感兴趣区域图像,以及与所述感兴趣区域图像对应的区域分割图像,所述区域分割图像包括所述感兴趣区域图像的人像区域信息;根据所述感兴趣区域图像及所述区域分割图像生成第一头发掩膜;对所述第一头发掩膜进行优化处理,以得到所述原始人物图像对应的目标头发掩膜。The embodiment of the present application discloses a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the processor performs the following steps: preprocessing the original character image to obtain the The region of interest image of the original person image, and the region segmentation image corresponding to the region of interest image, the region segmentation image includes portrait region information of the region of interest image; according to the region of interest image and the region of interest image Generate a first hair mask from the region segmentation image; and optimize the first hair mask to obtain a target hair mask corresponding to the original person image.
本申请的一个或多个实施例的细节在下面的附图和描述中提出。本申请的其它特征和有益效果将从说明书、附图以及权利要求书中体现。The details of one or more embodiments of the application are set forth in the accompanying drawings and the description below. Other features and beneficial effects of the present application will appear from the description, drawings and claims.
附图说明Description of drawings
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the accompanying drawings that need to be used in the embodiments. Obviously, the accompanying drawings in the following description are only some embodiments of the present application. For Those of ordinary skill in the art can also obtain other drawings based on these drawings without making creative efforts.
图1为一个实施例中图像处理电路的框图;Fig. 1 is a block diagram of an image processing circuit in an embodiment;
图2为一个实施例中图像处理方法的流程图;Fig. 2 is a flowchart of an image processing method in an embodiment;
图3为一个实施例中对原始人物图像进行预处理的示意图;Fig. 3 is a schematic diagram of preprocessing the original character image in one embodiment;
图4为一个实施例中对原始人物图像进行预处理的流程图;Fig. 4 is a flow chart of preprocessing the original character image in one embodiment;
图5A为一个实施例中人像分割图像的示意图;FIG. 5A is a schematic diagram of a portrait segmentation image in an embodiment;
图5B为一个实施例中计算头发轮廓线的示意图;Fig. 5B is a schematic diagram of calculating hair contour lines in one embodiment;
图5C为一个实施例中确定抠图感兴趣区域的示意图;FIG. 5C is a schematic diagram of determining a region of interest in matting in an embodiment;
图5D为一个实施例中对原始人物图像及人像分割图像进行校正的示意图;Fig. 5D is a schematic diagram of correcting the original character image and the segmented portrait image in one embodiment;
图6为另一个实施例中图像处理方法的流程图;Fig. 6 is the flowchart of image processing method in another embodiment;
图7为一个实施例中通过图像处理模型生成第一头发掩膜的示意图;Fig. 7 is a schematic diagram of generating a first hair mask through an image processing model in an embodiment;
图8为一个实施例中计算背景复杂度图像的流程图;Fig. 8 is a flow chart of calculating the background complexity image in one embodiment;
图9A为一个实施例中计算背景复杂度的示意图;FIG. 9A is a schematic diagram of calculating background complexity in an embodiment;
图9B为一个实施例中将腐蚀处理前的第一头发掩膜与腐蚀处理后的第一头发掩膜进行融合的示意图;Fig. 9B is a schematic diagram of merging the first hair mask before corrosion treatment and the first hair mask after corrosion treatment in one embodiment;
图10为一个实施例中对第一头发掩膜中的孔洞进行填充的示意图;Figure 10 is a schematic diagram of filling holes in the first hair mask in one embodiment;
图11为一个实施例中对第一头发掩膜的头发区域进行增强处理的示意图;Fig. 11 is a schematic diagram of enhancing the hair region of the first hair mask in one embodiment;
图12为一个实施例中对第一头发掩膜进行柔化处理的示意图;Fig. 12 is a schematic diagram of softening the first hair mask in one embodiment;
图13为一个实施例中通过引导滤波器对第二头发掩膜进行上采样滤波处理的示意图;Fig. 13 is a schematic diagram of performing upsampling and filtering on a second hair mask through a guided filter in an embodiment;
图14为一个实施例中图像处理装置的框图;Figure 14 is a block diagram of an image processing device in an embodiment;
图15为一个实施例中电子设备的结构框图。Fig. 15 is a structural block diagram of an electronic device in one embodiment.
具体实施方式detailed description
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The following will clearly and completely describe the technical solutions in the embodiments of the application with reference to the drawings in the embodiments of the application. Apparently, the described embodiments are only some, not all, embodiments of the application. Based on the embodiments in this application, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the scope of protection of this application.
需要说明的是,本申请实施例及附图中的术语“包括”和“具有”以及它们任何变形,意图在于覆盖不排他的包含。例如包含了一系列步骤或单元的过程、方法、系统、产品或设备没有限定于已列出的步骤或单元,而是可选地还包括没有列出的步骤或单元,或可选地还包括对于这些过程、方法、产品或设备固有的其它步骤或单元。It should be noted that the terms "comprising" and "having" and any variations thereof in the embodiments of the present application and the drawings are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but optionally also includes unlisted steps or units, or optionally further includes For other steps or units inherent in these processes, methods, products or apparatuses.
可以理解,本申请所使用的术语“第一”、“第二”等可在本文中用于描述各种元件,但这些元件不受这些术语限制。这些术语仅用于将第一个元件与另一个元件区分。举例来说,在不脱离本申请的范围的情况下,可以将第一头发掩膜称为第二头发掩膜,且类似地,可将第二头发掩膜称为第一头发掩膜。第一头发掩膜和第二头发掩膜两者都是头发掩膜,但其不是同一头发掩膜。It can be understood that the terms "first", "second" and the like used in this application may be used to describe various elements herein, but these elements are not limited by these terms. These terms are only used to distinguish one element from another element. For example, a first hair mask could be termed a second hair mask, and, similarly, a second hair mask could be termed a first hair mask, without departing from the scope of the present application. Both the first hair mask and the second hair mask are hair masks, but they are not the same hair mask.
本申请实施例提供一种电子设备。该电子设备中包括图像处理电路,图像处理电路可以利用硬件和/或软件组件实现,可包括定义ISP(Image Signal Processing,图像信号处理)管线的各种处理单元。图1为一个实施例中图像处理电路的框图。为便于说明,图1仅示出与本申请实施例相关的图像处理技术的各个方面。An embodiment of the present application provides an electronic device. The electronic device includes an image processing circuit, and the image processing circuit may be implemented by hardware and/or software components, and may include various processing units defining an ISP (Image Signal Processing, image signal processing) pipeline. Figure 1 is a block diagram of an image processing circuit in one embodiment. For ease of description, FIG. 1 only shows various aspects of the image processing technology related to the embodiment of the present application.
如图1所示,图像处理电路包括ISP处理器140和控制逻辑器150。成像设备110捕捉的图像数据首先由ISP处理器140处理,ISP处理器140对图像数据进行分析以捕捉可用于确定成像设备110的一个或多个控制参数的图像统计信息。成像设备110可包括一个或多个透镜112和图像传感器114。图像传感器114可包括色彩滤镜阵列(如Bayer滤镜),图像传感器114可获取每个成像像素捕捉的光强度和波长信息,并提供可由ISP处理器140处理的一组原始图像数据。姿态传感器120(如三轴陀螺仪、霍尔传感器、加速度计等)可基于姿态传感器120接口类型把采集的图像处理的参数(如防抖参数)提供给ISP处理器140。姿态传感器120接口可以采用SMIA(Standard Mobile Imaging Architecture,标准移动成像架构)接口、其它串行或并行摄像头接口或上述接口的组合。As shown in FIG. 1 , the image processing circuit includes an ISP processor 140 and a control logic 150 . Image data captured by imaging device 110 is first processed by ISP processor 140 , which analyzes the image data to capture image statistics that can be used to determine one or more control parameters of imaging device 110 . Imaging device 110 may include one or more lenses 112 and image sensor 114 . The image sensor 114 may include a color filter array (such as a Bayer filter), and the image sensor 114 may obtain light intensity and wavelength information captured by each imaging pixel and provide a set of raw image data that may be processed by the ISP processor 140 . The attitude sensor 120 (such as a three-axis gyroscope, Hall sensor, accelerometer, etc.) can provide the collected image processing parameters (such as anti-shake parameters) to the ISP processor 140 based on the interface type of the attitude sensor 120 . The attitude sensor 120 interface may adopt a SMIA (Standard Mobile Imaging Architecture, Standard Mobile Imaging Architecture) interface, other serial or parallel camera interfaces, or a combination of the above interfaces.
需要说明的是,虽然图1中仅示出了一个成像设备110,但是在本申请实施例中,可包括至少两个成像设备110,每个成像设备110可分别对应一个图像传感器114,也可多个成像设备110对应一个图像传感器114,在此不作限定。每个成像设备110的工作过程可参照上述所描述的内容。It should be noted that although only one imaging device 110 is shown in FIG. 1 , at least two imaging devices 110 may be included in this embodiment of the application, and each imaging device 110 may correspond to an image sensor 114 respectively, or may Multiple imaging devices 110 correspond to one image sensor 114 , which is not limited here. The working process of each imaging device 110 may refer to the content described above.
此外,图像传感器114也可将原始图像数据发送给姿态传感器120,姿态传感器120可基于姿态传感器120接口类型把原始图像数据提供给ISP处理器140,或者姿态传感器120将原始图像数据存储到图像存储器130中。In addition, the image sensor 114 can also send the original image data to the attitude sensor 120, and the attitude sensor 120 can provide the original image data to the ISP processor 140 based on the attitude sensor 120 interface type, or the attitude sensor 120 can store the original image data in the image memory 130 in.
ISP处理器140按多种格式逐个像素地处理原始图像数据。例如,每个图像像素可具有8、10、12或14比特的位深度,ISP处理器140可对原始图像数据进行一个或多个图像处理操作、收集关于图像数据的统计信息。其中,图像处理操作可按相同或不同的位深度精度进行。The ISP processor 140 processes raw image data on a pixel-by-pixel basis in various formats. For example, each image pixel may have a bit depth of 8, 10, 12, or 14 bits, and the ISP processor 140 may perform one or more image processing operations on the raw image data, gather statistical information about the image data. Among other things, image processing operations can be performed with the same or different bit depth precision.
ISP处理器140还可从图像存储器130接收图像数据。例如,姿态传感器120接口将原始图像数据发送给图像存储器130,图像存储器130中的原始图像数据再提供给ISP处理器140以供处理。图像存储器130可为存储器装置的一部分、存储设备、或电子设备内的独立的专用存储器,并可包括DMA(Direct Memory Access,直接直接存储器存取)特征。ISP processor 140 may also receive image data from image memory 130 . For example, the attitude sensor 120 interface sends raw image data to the image storage 130, and the raw image data in the image storage 130 is provided to the ISP processor 140 for processing. The image memory 130 may be a part of a memory device, a storage device, or an independent dedicated memory in an electronic device, and may include a DMA (Direct Memory Access) feature.
当接收到来自图像传感器114接口或来自姿态传感器120接口或来自图像存储器130的原始图像数 据时,ISP处理器140可进行一个或多个图像处理操作,如时域滤波。处理后的图像数据可发送给图像存储器130,以便在被显示之前进行另外的处理。ISP处理器140从图像存储器130接收处理数据,并对该处理数据进行原始域中以及RGB和YCbCr颜色空间中的图像数据处理。ISP处理器140处理后的图像数据可输出给显示器160,以供用户观看和/或由图形引擎或GPU(Graphics Processing Unit,图形处理器)进一步处理。此外,ISP处理器140的输出还可发送给图像存储器130,且显示器160可从图像存储器130读取图像数据。在一个实施例中,图像存储器130可被配置为实现一个或多个帧缓冲器。When receiving raw image data from the image sensor 114 interface or from the attitude sensor 120 interface or from the image memory 130, the ISP processor 140 may perform one or more image processing operations, such as temporal filtering. The processed image data may be sent to image memory 130 for additional processing before being displayed. The ISP processor 140 receives processed data from the image memory 130 and subjects the processed data to image data processing in the original domain and in the RGB and YCbCr color spaces. The image data processed by the ISP processor 140 may be output to the display 160 for viewing by the user and/or for further processing by a graphics engine or a GPU (Graphics Processing Unit, graphics processor). In addition, the output of the ISP processor 140 can also be sent to the image memory 130 , and the display 160 can read image data from the image memory 130 . In one embodiment, image memory 130 may be configured to implement one or more frame buffers.
ISP处理器140确定的统计数据可发送给控制逻辑器150。例如,统计数据可包括陀螺仪的振动频率、自动曝光、自动白平衡、自动聚焦、闪烁检测、黑电平补偿、透镜112阴影校正等图像传感器114统计信息。控制逻辑器150可包括执行一个或多个例程(如固件)的处理器和/或微控制器,一个或多个例程可根据接收的统计数据,确定成像设备110的控制参数及ISP处理器140的控制参数。例如,成像设备110的控制参数可包括姿态传感器120控制参数(例如增益、曝光控制的积分时间、防抖参数等)、照相机闪光控制参数、照相机防抖位移参数、透镜112控制参数(例如聚焦或变焦用焦距)或这些参数的组合。ISP控制参数可包括用于自动白平衡和颜色调整(例如,在RGB处理期间)的增益水平和色彩校正矩阵,以及透镜112阴影校正参数。Statistics determined by ISP processor 140 may be sent to control logic 150 . For example, the statistical data may include the vibration frequency of the gyroscope, automatic exposure, automatic white balance, automatic focus, flicker detection, black level compensation, lens 112 shading correction and other image sensor 114 statistical information. Control logic 150 may include a processor and/or a microcontroller that executes one or more routines (e.g., firmware) that determine control parameters of imaging device 110 and ISP processing based on received statistical data. The control parameters of the device 140. For example, the control parameters of the imaging device 110 may include attitude sensor 120 control parameters (such as gain, integration time of exposure control, anti-shake parameters, etc.), camera flash control parameters, camera anti-shake displacement parameters, lens 112 control parameters (such as focus or focal length for zooming) or a combination of these parameters. ISP control parameters may include gain levels and color correction matrices for automatic white balance and color adjustment (eg, during RGB processing), as well as lens 112 shading correction parameters.
示例性地,结合图1的图像处理电路,对本申请实施例所提供的图像处理方法进行说明。ISP处理器140可从成像设备110或图像存储器130中获取原始人物图像,可对该原始人物图像进行预处理,得到该原始人物图像的感兴趣区域图像,以及与该感兴趣区域图像对应的区域分割图像。ISP处理器140可根据该感兴趣区域图像及区域分割图像生成第一头发掩膜,并对该第一头发掩膜进行优化处理,以得到原始人物图像对应的目标头发掩膜。By way of example, the image processing method provided by the embodiment of the present application will be described with reference to the image processing circuit in FIG. 1 . The ISP processor 140 can acquire the original character image from the imaging device 110 or the image memory 130, and can perform preprocessing on the original character image to obtain the ROI image of the original character image and the region corresponding to the ROI image Split the image. The ISP processor 140 may generate a first hair mask according to the ROI image and the region segmentation image, and optimize the first hair mask to obtain a target hair mask corresponding to the original person image.
在一些实施例中,ISP处理器140得到原始人物图像对应的目标头发掩膜后,可根据该目标头发掩膜精准地确定原始人物图像中的头发区域,并利用该目标头发掩膜对原始人物图像进行前景区域及背景区域的分离。可选地,还可分别对分离后的背景区域或前景区域等进行图像处理,例如对背景区域进行虚化处理,对前景区域进行美化处理(如提高亮度、人像美白、去雾处理等)等,但不限于此。ISP处理器140可将处理后的图像发送到图像存储器130进行存储,也可将处理后的图像发送到显示器160进行显示,以方便用户通过显示器160观察处理后的图像。In some embodiments, after the ISP processor 140 obtains the target hair mask corresponding to the original character image, it can accurately determine the hair region in the original character image according to the target hair mask, and use the target hair mask to analyze the hair area of the original character. The image is separated from foreground and background regions. Optionally, image processing can also be performed on the separated background area or foreground area, such as blurring the background area and beautifying the foreground area (such as increasing brightness, whitening portraits, defogging, etc.), etc. , but not limited to this. The ISP processor 140 can send the processed image to the image memory 130 for storage, and can also send the processed image to the display 160 for display, so that the user can observe the processed image through the display 160 conveniently.
如图2所示,在一个实施例中,提供一种图像处理方法,可应用于上述的电子设备,该电子设备可包括但不限于手机、智能可穿戴设备、平板电脑、PC(Personal Computer,个人计算机)、车载终端、数码相机等,本申请实施例对此不作限定。该图像处理方法可包括以下步骤:As shown in Figure 2, in one embodiment, an image processing method is provided, which can be applied to the above-mentioned electronic equipment, which may include but not limited to mobile phones, smart wearable devices, tablet computers, PC (Personal Computer, personal computer), vehicle-mounted terminal, digital camera, etc., which are not limited in this embodiment of the present application. The image processing method may include the following steps:
步骤210,对原始人物图像进行预处理,得到原始人物图像的感兴趣区域图像,以及与感兴趣区域图像对应的区域分割图像。 Step 210, preprocessing the original person image to obtain the ROI image of the original person image and the region segmentation image corresponding to the ROI image.
原始人物图像可指的是包含有人物的图像,该原始人物图像可为彩色图像,例如可以是RGB(Red Green Blue,红绿蓝)格式的图像或YUV(Y表示明亮度,U和V表示色度)格式的图像等。原始人物图像可以是需要进行前景的人像区域与背景区域分离的图像。原始人物图像可以是预先存储在电子设备的存储器中的图像,也可以是电子设备通过摄像头实时采集到的图像。The original character image can refer to an image containing a character, and the original character image can be a color image, such as an image in RGB (Red Green Blue, red green blue) format or YUV (Y represents brightness, U and V represent chroma) format images, etc. The original person image may be an image in which a foreground portrait area needs to be separated from a background area. The original person image may be an image pre-stored in the memory of the electronic device, or an image collected in real time by the electronic device through a camera.
作为一种实施方式,原始人物图像中前景的人像区域与背景区域对应的深度信息差别较大,深度信息可用于表征被拍摄物体与摄像头之间的距离,深度信息越大可表示距离越远。因此,可利用原始人物图像中各个像素点对应的深度信息对原始人物图像中的前景区域及背景区域进行划分,例如,该背景区域可以是深度信息大于第一阈值的像素点组成的区域,该前景区域可以是深度信息小于第二阈值的像素点组成的区域等。As an implementation, the depth information corresponding to the foreground portrait area and the background area in the original person image is quite different, and the depth information can be used to represent the distance between the photographed object and the camera, and the greater the depth information, the greater the distance. Therefore, the depth information corresponding to each pixel in the original person image can be used to divide the foreground area and the background area in the original person image, for example, the background area can be an area composed of pixels whose depth information is greater than the first threshold, the The foreground area may be an area composed of pixels whose depth information is less than the second threshold.
作为另一种实施方式,也可利用人脸识别对原始人物图像的前景区域及背景区域进行划分。电子设备可对原始人物图像进行人脸识别,确定原始人物图像中的人脸区域,再根据该人脸区域确定人像区域,人像区域指的是整个人体所在的图像区域,而人脸区域指的是人的脸部所在的图像区域,该人像区域包括该人脸区域。原始人物图像中除人像区域外的其它图像区域则可被确定为背景区域。As another implementation manner, face recognition may also be used to divide the foreground area and the background area of the original person image. The electronic device can perform face recognition on the original person image, determine the face area in the original person image, and then determine the portrait area according to the face area. The portrait area refers to the image area where the entire human body is located, and the face area refers to the is the image area where the face of the person is located, and the portrait area includes the face area. Other image areas in the original person image except the portrait area can be determined as the background area.
电子设备可对原始人物图像进行预处理,以确定原始人物图像中的抠图感兴趣区域(Region of Interest,ROI),该抠图感兴趣区域可指的是原始人物图像中需要进行头发抠图(hair matting)的图像区域,该抠图感兴趣区域可包括人脸区域。通过头发抠图可得到原始人物图像对应的精确的头发掩膜,以通过该精确的头发掩膜对原始人物图像的头发区域进行精准定位。电子设备在确定原始人物图像中的抠图感兴趣区域后,可从原始人物图像中提取该抠图感兴趣区域,得到感兴趣区域图像,同时可获取该感兴趣区域图像对应的区域分割图像,该区域分割图像可包括感兴趣区域图像的人像区域信息,该区域分 割图像可理解为对感兴趣区域图像进行人像提取后得到的图像。The electronic device can preprocess the original person image to determine a region of interest (Region of Interest, ROI) in the original person image. (hair matting) image area, the matting area of interest may include the face area. An accurate hair mask corresponding to the original character image can be obtained through hair matting, so as to accurately locate the hair region of the original character image through the precise hair mask. After determining the matting region of interest in the original person image, the electronic device can extract the matting region of interest from the original person image to obtain an image of the region of interest, and at the same time obtain a region segmentation image corresponding to the region of interest image, The region segmentation image may include portrait region information of the region of interest image, and the region segmentation image may be understood as an image obtained by extracting a portrait from the region of interest image.
图3为一个实施例中对原始人物图像进行预处理的示意图。如图3所示,电子设备可对原始人物图像310进行预处理,确定原始人物图像310中的抠图感兴趣区域312,并从原始人物图像310中提取该抠图感兴趣区域312,得到感兴趣区域图像320,同时可得到该感兴趣区域图像320对应的区域分割图像330。区域分割图像330与感兴趣区域图像320匹配,区域分割图像330可用于表示感兴趣区域图像320中的人像区域(即区域分割图像330中的黑色区域)。Fig. 3 is a schematic diagram of preprocessing an original person image in an embodiment. As shown in FIG. 3 , the electronic device can preprocess the original character image 310, determine the matting region of interest 312 in the original character image 310, and extract the matting region of interest 312 from the original character image 310 to obtain a sense The region of interest image 320, and the region segmentation image 330 corresponding to the region of interest image 320 can be obtained at the same time. The region segmentation image 330 matches the ROI image 320, and the region segmentation image 330 can be used to represent the portrait area in the ROI image 320 (ie, the black region in the region segmentation image 330).
步骤220,根据感兴趣区域图像及区域分割图像生成第一头发掩膜。 Step 220, generating a first hair mask according to the ROI image and the region segmentation image.
第一头发掩膜可用于表征感兴趣区域图像中的头发区域,电子设备可先根据感兴趣区域图像及对应的区域分割图像推导出感兴趣区域图像中的头发区域,并生成第一头发掩膜。作为一种实施方式,电子设备可采用机器学习的方式生成第一头发掩膜,可将感兴趣区域图像及对应的区域分割图像输入预先训练得到的图像处理模型,通过该图像处理模型对感兴趣区域图像及区域分割图像进行处理,得到第一头发掩膜。其中,该图像处理模型可以是根据多组样本训练图像进行训练得到的,每一组样本训练图像可包括样本人物图像、与该样本人物图像对应的样本人像分割图像及样本头发掩膜,样本头发掩膜可用于对样本人物图像中的头发区域进行标注。The first hair mask can be used to characterize the hair region in the region of interest image, the electronic device can first deduce the hair region in the region of interest image according to the region of interest image and the corresponding region segmentation image, and generate the first hair mask . As an implementation, the electronic device can use machine learning to generate the first hair mask, and can input the image of the region of interest and the corresponding region segmentation image into the pre-trained image processing model, and use the image processing model to generate the hair mask of interest The region image and the region segmentation image are processed to obtain the first hair mask. Wherein, the image processing model can be obtained by training according to multiple sets of sample training images, and each set of sample training images can include a sample person image, a sample portrait segmentation image corresponding to the sample person image, and a sample hair mask, and the sample hair Masks can be used to label hair regions in sample person images.
在其它的实施例中,电子设备也可采用其它方式生成第一头发掩膜,例如,电子设备可根据区域分割图像确定感兴趣区域图像中的人像轮廓,根据该人像轮廓可确定人像区域,再对人像区域进行图像识别,提取人像区域中的图像特征,并对该图像特征进行分析,以确定头发区域。可选地,该图像特征可包括但不限于边缘特征、颜色特征、位置特征等,如头发区域的颜色通常为黑色、具备较多的边缘信息,位于人脸上方(具体位于人脸中的眼睛区域的上方)等。In other embodiments, the electronic device can also use other methods to generate the first hair mask. For example, the electronic device can determine the profile of the portrait in the image of the region of interest according to the region segmentation image, and determine the portrait area according to the profile of the portrait, and then Perform image recognition on the portrait area, extract image features in the portrait area, and analyze the image features to determine the hair area. Optionally, the image features may include but not limited to edge features, color features, position features, etc., for example, the color of the hair region is usually black, has more edge information, and is located above the face (especially the eyes located in the face) area above), etc.
步骤230,对第一头发掩膜进行优化处理,以得到原始人物图像对应的目标头发掩膜。 Step 230, optimize the first hair mask to obtain a target hair mask corresponding to the original person image.
第一头发掩膜为根据感兴趣区域图像及区域分割图像初步得到的头发掩膜,较为粗糙,可能存在不准确的问题,因此,在本申请实施例中,可进一步对第一头发掩膜进行优化处理,对第一头发掩膜进行调整、修正,从而可得到更加细致、精确的目标头发掩膜,该目标头发掩膜可用于准确定位原始人物图像中的头发区域。可选地,该优化处理可包括但不限于增强处理、腐蚀处理、填充处理等,对第一头发掩膜中头发区域的边缘进行优化,减轻第一头发掩膜中出现的缺少发丝边缘或是包含了非头发内容的边缘等情况,得到准确的目标头发掩膜。The first hair mask is a hair mask initially obtained from the region-of-interest image and the region-segmented image. The optimization process adjusts and corrects the first hair mask, so that a more detailed and precise target hair mask can be obtained, and the target hair mask can be used to accurately locate the hair region in the original person image. Optionally, the optimization processing may include but not limited to enhancement processing, erosion processing, filling processing, etc., to optimize the edges of the hair region in the first hair mask, and alleviate the lack of hairline edges or It is the case that contains the edge of non-hair content, etc., to get an accurate target hair mask.
在电子设备得到目标头发掩膜后,可根据该目标头发掩膜对原始人物图像中前景的人像区域及背景区域进行分离,由于目标头发掩膜中准确定位原始人物图像的头发区域,因此可以准确将人像的头发区域与背景区域进行分离,实现发丝级别的图像分离。After the electronic device obtains the target hair mask, it can separate the foreground portrait area and the background area in the original character image according to the target hair mask. Since the hair area of the original character image is accurately positioned in the target hair mask, it can be accurately Separate the hair area of the portrait from the background area to achieve hair-level image separation.
在将原始人物图像中前景的人像区域及背景区域进行分离后,可进一步对分离的人像区域和/或背景区域进行处理。例如,可对背景区域进行虚化处理,调节人像区域的亮度、调节人像区域的白平衡参数等,本申请实施例对分离后进行的图像处理不作限定。After the foreground portrait area and background area in the original person image are separated, the separated portrait area and/or background area may be further processed. For example, the background area can be blurred, the brightness of the portrait area can be adjusted, and the white balance parameters of the portrait area can be adjusted. The embodiment of the present application does not limit the image processing after separation.
在本申请实施例中,通过对原始人物图像进行预处理,得到原始人物图像的感兴趣区域图像,以及与该感兴趣区域图像对应的区域分割图像,根据该感兴趣区域图像及区域分割图像生成第一头发掩膜,并对第一头发掩膜进行优化处理,以得到原始人物图像对应的目标头发掩膜,在生成第一头发掩膜后,还对第一头发掩膜进行优化、修正,从而可得到更加精细、准确的目标头发掩膜,利用该目标头发掩膜可准确定位原始人物图像中的头发区域,从而可提高后续对原始人物图像进行前景、背景分离等图像处理时的图像处理效果。In the embodiment of the present application, by preprocessing the original person image, the ROI image of the original person image and the region segmentation image corresponding to the ROI image are obtained, and the ROI image and the region segmentation image are generated according to the ROI image and the region segmentation image. the first hair mask, and optimize the first hair mask to obtain the target hair mask corresponding to the original character image, after generating the first hair mask, optimize and correct the first hair mask, In this way, a finer and more accurate target hair mask can be obtained, and the hair region in the original character image can be accurately located by using the target hair mask, thereby improving the image processing of the subsequent image processing such as foreground and background separation of the original character image Effect.
如图4所示,在一个实施例中,步骤对原始人物图像进行预处理,得到原始人物图像的感兴趣区域图像,以及与感兴趣区域图像对应的区域分割图像,可包括以下步骤:As shown in Figure 4, in one embodiment, the step of preprocessing the original person image to obtain the region of interest image of the original person image and the region segmentation image corresponding to the region of interest image may include the following steps:
步骤402,根据原始人物图像,以及与原始人物图像对应的人像分割图像,确定原始人物图像中的抠图感兴趣区域。Step 402: Determine the matting region of interest in the original person image according to the original person image and the person segmentation image corresponding to the original person image.
人像分割图像为对原始人物图像进行人像提取后得到的图像,该人像分割图像可包括原始人物图像的人像区域信息。作为一种实施方式,电子设备可直接获取原始人物图像及与该原始人物图像对应的人像分割图像,并根据该人像分割图像对原始人物图像进行预处理。该人像分割图像可以是预先存储在存储器中的图像,电子设备可预先对原始人物图像进行人像提取,得到人像分割图像,并将人像分割图像存储在存储器中。也即,对原始人物图像的预处理过程不包括对原始人物图像进行人像提取的步骤。A segmented portrait image is an image obtained by extracting a portrait from an original person image, and the segmented portrait image may include portrait area information of the original person image. As an implementation manner, the electronic device may directly acquire an original character image and a segmented portrait image corresponding to the original character image, and perform preprocessing on the original character image according to the segmented portrait image. The segmented portrait image may be an image pre-stored in the memory, and the electronic device may perform portrait extraction on the original person image in advance to obtain the segmented portrait image, and store the segmented portrait image in the memory. That is, the preprocessing process of the original person image does not include the step of extracting the portrait from the original person image.
作为另一种实施方式,对原始人物图像的预处理过程可包括对原始人物图像进行人像提取的步骤,在电子设备对原始人物图像进行预处理时,可先对原始人物图像进行人像提取,得到人像分割图像,再基于该人像分割图像确定原始人物图像中的抠图感兴趣区域。As another implementation, the preprocessing process of the original person image may include the step of extracting the portrait of the original person image. When the electronic device preprocesses the original person image, it may first perform portrait extraction on the original person image to obtain A segmented image of a portrait, and then based on the segmented image of a portrait, a matting region of interest in the original person image is determined.
在一些实施例中,电子设备可通过第一分割模型提取原始人物图像的图像特征,基于该图像特征识别原始人物图像中的人像区域,并根据该人像区域对原始人物图像进行人像提取,得到人像分割图像。该第一分割模型可以是根据第一分割样本图像集合训练得到的,该第一分割样本图像集合中可包括多张样本人物图像,以及与每张样本人物图像对应的样本人像分割图像。可选地,第一分割样本图像集合中也可仅包含有多张样本人物图像,每张样本人物图像可标注有人物区域信息。In some embodiments, the electronic device can extract the image features of the original person image through the first segmentation model, identify the portrait region in the original person image based on the image features, and perform portrait extraction on the original person image according to the portrait region to obtain the portrait Split the image. The first segmentation model may be obtained by training according to a first set of segmented sample images, which may include a plurality of sample person images, and a sample portrait segmentation image corresponding to each sample person image. Optionally, the first segmented sample image set may only contain multiple sample person images, and each sample person image may be marked with person area information.
图5A为一个实施例中人像分割图像的示意图。如图5A所示,原始人物图像310与人像分割图像304对应,该人像分割图像304为对原始人物图像310进行人像提取后得到的,人像分割图像304可用于表征原始人物图像310中的人像区域。Fig. 5A is a schematic diagram of a segmented portrait image in an embodiment. As shown in FIG. 5A , the original person image 310 corresponds to the portrait segmented image 304, which is obtained after portrait extraction is performed on the original person image 310, and the portrait segmented image 304 can be used to represent the portrait area in the original person image 310 .
在一些实施例中,步骤根据原始人物图像,以及与原始人物图像对应的人像分割图像,确定原始人物图像中的抠图感兴趣区域,可包括:获取原始人物图像对应的头发分割图像,根据该头发分割图像及人像分割图像计算得到头发轮廓线,并根据头发轮廓线确定原始人物图像中的抠图感兴趣区域。In some embodiments, the step of determining the matting region of interest in the original character image according to the original character image and the segmented portrait image corresponding to the original character image may include: acquiring the hair segmentation image corresponding to the original character image, according to the The hair contour line is calculated from the hair segmentation image and the portrait segmentation image, and the matting region of interest in the original person image is determined according to the hair contour line.
头发分割图像为对原始人物图像进行头发分割后得到的图像,头发分割图像可包括原始人物图像的头发区域信息,可识别并提取原始人物图像中的头发区域,得到该头发分割图像。在一些实施例中,电子设备可通过第二分割模型对原始人物图像中的头发区域进行识别,第二分割模型可提取原始人物图像的图像特征,基于该图像特征识别原始人物图像中的头发区域,并提取该原始人物图像中的头发区域,得到头发分割图像。可选地,第二分割模型可以是根据第二分割样本图像集合训练得到的,该第二分割样本图像集合中可包括多张样本人物图像,以及与每张样本人物图像对应的样本头发分割图像。可选地,第二分割样本图像集合中也可仅包含有多张标注有头发区域信息的样本人物图像。The hair segmentation image is an image obtained by performing hair segmentation on the original person image. The hair segmentation image may include hair region information of the original person image, and the hair region in the original person image may be identified and extracted to obtain the hair segmentation image. In some embodiments, the electronic device can identify the hair region in the original person image through the second segmentation model, and the second segmentation model can extract the image features of the original person image, and identify the hair region in the original person image based on the image features , and extract the hair region in the original person image to obtain the hair segmentation image. Optionally, the second segmentation model may be obtained by training according to a second set of segmented sample images, which may include a plurality of sample person images and a sample hair segment image corresponding to each sample person image . Optionally, the second set of segmented sample images may only include multiple sample person images marked with hair region information.
在一些实施例中,也可通过一个分割模型同时对原始人物图像进行人像区域及头发区域的识别,并输出人像分割图像及头发分割图像,可同时将样本人物图像、样本人物图像对应的样本人像分割图像、样本头发分割图像共同作为训练集对该分割模型进行训练,使其具备同时输出人像分割图像及头发分割图像的能力。In some embodiments, a segmentation model can also be used to identify the portrait region and hair region of the original person image at the same time, and output the portrait segmentation image and hair segmentation image, and the sample person image and the sample portrait corresponding to the sample person image can be simultaneously Segmented images and sample hair segmented images are used as a training set to train the segmentation model, so that it has the ability to simultaneously output portrait segmented images and hair segmented images.
上述的分割模型可采用deeplab语义分割算法、U-Net网络结构、FCN(Fully Convolutional Networks,全卷积神经网络)等方式进行人像分割,本申请实施例对此不作限定。The above segmentation model can use deeplab semantic segmentation algorithm, U-Net network structure, FCN (Fully Convolutional Networks, fully convolutional neural network) and other methods to perform portrait segmentation, which is not limited in the embodiment of the present application.
头发轮廓线可用于描述头发区域的轮廓,该头发轮廓线可包括头发区域外边缘上的各个像素点,该外边缘指的是与背景区域相邻的边缘。在一些实施例中,电子设备可将头发分割图像与人像分割图像进行比对,确定二者在头发区域外边缘上的相同像素点,并根据该相同像素点确定头发轮廓线。作为一种具体实施方式,电子设备可利用人像分割图像对头发分割图像中的头发区域进行腐蚀处理,使得头发分割图像的头发区域缩减,仅保留头发分割图像中与人像分割图像的边缘重合的边缘像素点,该保留下来的边缘像素点即组成了头发轮廓线。The hair contour line may be used to describe the contour of the hair region, and the hair contour line may include each pixel point on the outer edge of the hair region, and the outer edge refers to an edge adjacent to the background region. In some embodiments, the electronic device can compare the hair segmentation image with the portrait segmentation image, determine the same pixel points on the outer edge of the hair region, and determine the hair contour line according to the same pixel points. As a specific implementation, the electronic device can use the portrait segmentation image to corrode the hair region in the hair segmentation image, so that the hair region of the hair segmentation image is reduced, and only the edges in the hair segmentation image that coincide with the edges of the portrait segmentation image are retained Pixels, the remaining edge pixels constitute the hair contour.
图5B为一个实施例中计算头发轮廓线的示意图。如图5B所示,电子设备可将人像分割图像510与头发分割图像520进行比对,确定二者在头发区域外边缘上的相同像素点,得到头发轮廓线530。头发轮廓线530的计算公式可为式(1):Fig. 5B is a schematic diagram of calculating hair contour in one embodiment. As shown in FIG. 5B , the electronic device can compare the segmented portrait image 510 with the segmented hair image 520 , determine the same pixel points on the outer edge of the hair region, and obtain the hair contour line 530 . The calculation formula of the hair contour line 530 can be formula (1):
hair_outline=hair_seg-erode(seg)   式(1);hair_outline=hair_seg-erode(seg) formula (1);
其中,hair_outline表示头发轮廓线530,hair_seg表示头发分割图像520,seg表示人像分割图像510。Among them, hair_outline represents the hair contour line 530 , hair_seg represents the hair segmentation image 520 , and seg represents the portrait segmentation image 510 .
在电子设备计算得到头发轮廓线后,可根据该头发轮廓线确定原始人物图像中的抠图感兴趣区域。在一些实施例中,可先确定原始人物图像中的人脸区域,并根据该人脸区域得到初始感兴趣区域,该初始感兴趣区域可指的是利用人脸区域初步得到的抠图感兴趣区域。可选地,可对原始人物图像进行人脸识别,确定人脸区域,人脸区域仅包含人物的人脸部分的图像内容,该人脸区域的形状可为固定的形状,例如固定的正方形、矩形等。After the hair contour line is calculated by the electronic device, the matting region of interest in the original person image can be determined according to the hair contour line. In some embodiments, the face area in the original person image can be determined first, and the initial interest area can be obtained according to the face area. area. Optionally, face recognition can be performed on the original person image to determine the face area. The face area only contains the image content of the face part of the person. The shape of the face area can be a fixed shape, such as a fixed square, rectangle etc.
可选地,也可利用头发分割图像确定原始人物图像中的人脸区域,该头发分割图像中可包括头发区域处于人脸周围的边缘信息,利用该头发区域处于人脸周围的边缘信息可确定人脸区域。Optionally, the hair segmented image can also be used to determine the face area in the original person image, the hair segmented image can include edge information that the hair area is around the face, and the hair area can be determined by using the edge information that the hair area is around the face face area.
由于人脸区域小于抠图感兴趣区域,且人脸区域需位于抠图感兴趣区域内部,因此,可按照预设的区域划分规则,基于确定的人脸区域得到初始感兴趣区域。可根据确定人脸区域确定初始感兴趣区域的位置及区域尺寸。例如,区域划分规则可包括人脸区域位于初始感兴趣区域的中间位置,且初始感兴趣区域的尺寸为人脸区域的2倍;或是人脸区域的下边框与初始感兴趣区域的下边框重合,且初始感兴趣区域的尺寸为人脸区域的1.5倍等,也可以直接将确定的人脸区域作为初始感兴趣区域,但不限于此,区域划分规则可根据实际需求进行设置。针对不同的原始人物图像,可能确定的人脸区域所占的图像面积不同,也可相应调整区域划分规则。Since the face area is smaller than the matting area of interest, and the face area needs to be located inside the matting area of interest, the initial area of interest can be obtained based on the determined face area according to the preset area division rules. The position and area size of the initial ROI can be determined according to the determined face area. For example, the region division rule may include that the face region is located in the middle of the initial region of interest, and the size of the initial region of interest is twice the size of the face region; or the lower border of the face region coincides with the lower border of the initial region of interest , and the size of the initial region of interest is 1.5 times that of the face region, etc., the determined face region can also be directly used as the initial region of interest, but not limited thereto, and the region division rules can be set according to actual needs. For different original person images, the determined face regions may occupy different image areas, and the region division rules may also be adjusted accordingly.
由于初始感兴趣区域仅是一个大致的抠图感兴趣区域,因此,还需要利用头发轮廓线对初始感兴趣 区域进行修正,以得到准确的抠图感兴趣区域。电子设备可将头发轮廓线分别在原始人物图像的横坐标轴及纵坐标轴进行投影,得到头发轮廓线在横坐标轴的第一投影分布及在纵坐标轴的第二投影分布。其中,横坐标轴与纵坐标轴属于同一平面坐标系,该平面坐标系可包括图像坐标系、像素坐标系等。第一投影分布能够反映头发轮廓线在横坐标轴上的位置情况,第二投影分布能够反映头发轮廓线在纵坐标轴上的位置情况。Since the initial region of interest is only a rough matting region of interest, it is also necessary to use the hair contour to correct the initial region of interest in order to obtain an accurate matting region of interest. The electronic device may respectively project the hair contour line on the abscissa axis and the ordinate axis of the original character image to obtain a first projection distribution of the hair contour line on the abscissa axis and a second projection distribution on the ordinate axis. Wherein, the axis of abscissa and the axis of ordinate belong to the same plane coordinate system, and the plane coordinate system may include an image coordinate system, a pixel coordinate system, and the like. The first projection distribution can reflect the position of the hair contour line on the abscissa axis, and the second projection distribution can reflect the position of the hair contour line on the ordinate axis.
电子设备可根据第一投影分布及第二投影分布对初始感兴趣区域进行修正,得到抠图感兴趣区域,该修正可包括利用第一投影分布及第二投影分布对初始感兴趣区域的尺寸和/或位置进行调整。可根据头发轮廓线在横坐标轴的第一投影分布固定抠图感兴趣区域的水平范围,根据头发轮廓线在纵坐标轴的第二投影分布固定抠图感兴趣区域的垂直范围,从而可根据该水平范围及垂直范围确定抠图感兴趣区域。该水平范围可指的是抠图感兴趣区域在原始人物图像的横坐标轴上的坐标范围,垂直范围可指的是抠图感兴趣区域在原始人物图像的纵坐标轴上的坐标范围,例如,水平范围为横坐标Xa~Xb,垂直范围为纵坐标Ym~Yn。The electronic device may correct the initial region of interest according to the first projection distribution and the second projection distribution to obtain the matting region of interest. The correction may include using the first projection distribution and the second projection distribution to modify the size and and/or position adjustments. The horizontal range of the matting region of interest can be fixed according to the first projection distribution of the hair contour line on the abscissa axis, and the vertical range of the matting region of interest can be fixed according to the second projection distribution of the hair contour line on the ordinate axis. The horizontal range and vertical range determine the region of interest for matting. The horizontal range may refer to the coordinate range of the matting region of interest on the abscissa axis of the original character image, and the vertical range may refer to the coordinate range of the matting region of interest on the ordinate axis of the original character image, for example , the horizontal range is the abscissa Xa~Xb, and the vertical range is the ordinate Ym~Yn.
电子设备可根据第一投影分布调整初始感兴趣区域的水平范围,以固定抠图感兴趣区域的水平范围。例如,调整初始感兴趣区域的水平范围使得该水平范围包含该第一投影分布,且第一投影分布位于水平范围的中间位置。电子设备可根据第二投影分布调整初始感兴趣区域的垂直范围,以固定抠图感兴趣区域的垂直范围。例如,可调整初始感兴趣区域的垂直范围使得该垂直范围包含该第二投影分布,且可设置垂直范围的最小纵坐标小于第二投影分布的最小纵坐标,且垂直范围的最小纵坐标与第二投影分布的最小纵坐标之间的距离为第一像素距离,垂直范围的最大纵坐标大于第二投影分布的最大纵坐标,且第二投影分布的最大纵坐标与第二投影分布的最大纵坐标之间的距离为第二像素距离。The electronic device may adjust the horizontal range of the initial region of interest according to the first projection distribution, so as to fix the horizontal range of the region of interest in the cutout. For example, the horizontal range of the initial region of interest is adjusted so that the horizontal range includes the first projection distribution, and the first projection distribution is located in the middle of the horizontal range. The electronic device can adjust the vertical range of the initial region of interest according to the second projection distribution, so as to fix the vertical range of the region of interest in the matting. For example, the vertical range of the initial region of interest can be adjusted so that the vertical range includes the second projection distribution, and the minimum ordinate of the vertical range can be set to be smaller than the minimum ordinate of the second projection distribution, and the minimum ordinate of the vertical range is the same as the second projection distribution The distance between the minimum ordinates of the two projection distributions is the first pixel distance, the maximum ordinate of the vertical range is greater than the maximum ordinate of the second projection distribution, and the maximum ordinate of the second projection distribution is the same as the maximum ordinate of the second projection distribution The distance between the coordinates is the second pixel distance.
需要说明的是,抠图感兴趣区域的形状及尺寸可根据实际需求进行设置,例如形状可包括矩形、正方形等,上述的第一像素距离、第二像素距离等可根据实际需求进行设置。抠图感兴趣区域可完整地处于原始人物图像内,也可有部分不处于原始人物图像内。It should be noted that the shape and size of the cutout region of interest can be set according to actual needs, for example, the shape can include rectangle, square, etc., and the above-mentioned first pixel distance, second pixel distance, etc. can be set according to actual needs. The matting region of interest may be entirely within the original person image, or part of it may not be within the original person image.
利用头发轮廓线对初始感兴趣区域进行修正,可保证得到的抠图感兴趣区域包含完整的人脸区域,且包含完整的头发区域,使得到的抠图感兴趣区域更加准确,包含更加完整、丰富的细节,可提高后续计算头发掩膜的准确性。Correcting the initial region of interest by using the hair contour line can ensure that the obtained matting region of interest contains a complete face region and includes a complete hair region, making the obtained matting region of interest more accurate, including more complete, Rich detail, which improves the accuracy of the subsequent calculation of the hair mask.
图5C为一个实施例中确定抠图感兴趣区域的示意图。如图5C所示,计算得到原始人物图像550的头发轮廓线540,可先确定原人物图像550中的人脸区域552,并利用人脸区域552先得到初始感兴趣区域(图未示)。可将头发轮廓线540分别在原始人物图像的横坐标轴及纵坐标轴进行投影,得到在横坐标轴的第一投影分布542,以及在纵坐标轴上的第二投影分布544,并根据第一投影分布542及第二投影分布544调整初始感兴趣区域,得到抠图感兴趣区域554。能够保证抠图感兴趣区域554包含完整的人脸区域552,且包含完整的头发区域。Fig. 5C is a schematic diagram of determining a region of interest in matting in an embodiment. As shown in FIG. 5C , to calculate the hair contour line 540 of the original person image 550 , first determine the face area 552 in the original person image 550 , and use the face area 552 to obtain an initial region of interest (not shown). The hair contour line 540 can be projected on the abscissa axis and the ordinate axis of the original character image respectively to obtain the first projection distribution 542 on the abscissa axis and the second projection distribution 544 on the ordinate axis, and according to the first A projection distribution 542 and a second projection distribution 544 adjust the initial ROI to obtain a matted ROI 554 . It can be guaranteed that the matting region of interest 554 includes the complete human face region 552 and includes the complete hair region.
在一个实施例中,电子设备在确定原始人物图像中的抠图感兴趣区域之前,若原始人物图像为经过旋转的图像,则可分别对原始人物图像及与原始人物图像对应的人像分割图像进行校正。若原始人物图像为经过旋转的图像,则原始人物图像中的人像区域不是垂直于水平的,即该人像区域不是正向的,则可先对原始人物图像及人像分割图像进行校正,使原始人物图像中的人像区域垂直于水平(保持正向)。可选地,原始人物图像为经过旋转的图像,可以是原始人物图像经过后期的图像处理发生的旋转,也可以是当前采集该原始人物图像的摄像头发生旋转等情况造成的。In one embodiment, before the electronic device determines the matting region of interest in the original character image, if the original character image is a rotated image, the original character image and the segmented portrait image corresponding to the original character image can be respectively Correction. If the original character image is a rotated image, the portrait area in the original character image is not vertical to the horizontal, that is, the portrait area is not positive, then the original character image and the portrait segmented image can be corrected first, so that the original character The portrait area in the image is perpendicular to the horizontal (keeps positive). Optionally, the original person image is a rotated image, which may be caused by the rotation of the original person image after post-image processing, or the rotation of the camera currently collecting the original person image.
电子设备在对原始人物图像及人像分割图像进行校正后,可再根据校正后的原始人物图像及校正后的人像分割图像,确定校正后的抠图感兴趣区域。确定校正后的抠图感兴趣区域的过程可与上述各实施例中描述的确定抠图感兴趣区域的过程相类似,在此不再重复赘述。After correcting the original person image and the segmented portrait image, the electronic device can determine a corrected matting region of interest according to the corrected original person image and the corrected segmented portrait image. The process of determining the corrected region of interest in matting may be similar to the process of determining the region of interest in matting described in the above embodiments, and will not be repeated here.
由于该校正后的抠图感兴趣区域与未校正的原始人物图像不匹配,则可再按照未校正的原始人物图像的旋转方向,对校正后的抠图感兴趣区域进行旋转,得到未校正的原始人物图像中的抠图感兴趣区域。该旋转方向可指的是未校正的原始人物图像中人像区域相对水平的旋转方向。Since the corrected matting region of interest does not match the uncorrected original person image, the corrected matting region of interest can be rotated according to the rotation direction of the uncorrected original person image to obtain the uncorrected Matting regions of interest in raw person images. The rotation direction may refer to the relative horizontal rotation direction of the portrait area in the uncorrected original person image.
图5D为一个实施例中对原始人物图像及人像分割图像进行校正的示意图。如图5D所示,原始人物图像562及人像分割图像564为经过旋转的图像,则可先对原始人物图像562及人像分割图像564进行校正,得到校正后的原始人物图像572及校正后的人像分割图像574,校正后的原始人物图像572及校正后的人像分割图像574中的人像区域为正向。可根据校正后的原始人物图像572及校正后的人像分割图像574确定校正后的抠图感兴趣区域582,再按照原始人物图像562的旋转方向对校正后的抠图感兴趣区域582进行旋转,得到原始人物图像562中的抠图感兴趣区域584。在本申请实施例中,在确定抠图感兴趣区域前,先对原始人物图像及人像分割图像进行校正,能够使得识别到的抠图感兴趣区域更 加准确。Fig. 5D is a schematic diagram of correcting the original person image and the segmented image of the person in an embodiment. As shown in Figure 5D, the original character image 562 and the segmented portrait image 564 are rotated images, and the original character image 562 and the segmented portrait image 564 can be corrected first to obtain the corrected original character image 572 and the corrected portrait The segmented image 574, the corrected original person image 572 and the corrected portrait segmented image 574 have a front orientation. The corrected matting region of interest 582 can be determined according to the corrected original character image 572 and the corrected portrait segmentation image 574, and then the corrected matting region of interest 582 is rotated according to the rotation direction of the original character image 562, A matted region of interest 584 in the original person image 562 is obtained. In the embodiment of the present application, before determining the matting region of interest, the original person image and the segmented portrait image are corrected first, which can make the recognized matting region of interest more accurate.
步骤404,根据抠图感兴趣区域分别对原始人物图像及人像分割图像进行裁剪,得到感兴趣区域图像以及与感兴趣区域图像对应的区域分割图像。 Step 404 , respectively cropping the original person image and the segmented portrait image according to the cutout region of interest, to obtain the region of interest image and the region segmentation image corresponding to the region of interest image.
可将抠图感兴趣区域作为原始人物图像及人像分割图像的裁剪区域,对原始人物图像进行裁剪以得到感兴趣区域图像,对人像分割图像进行裁剪以得到区域分割图像,该区域分割图像与该感兴趣区域图像匹配。The area of interest in matting can be used as the cropping area of the original person image and the portrait segmentation image, the original person image is cropped to obtain the region of interest image, the portrait segmentation image is cropped to obtain the region segmentation image, the region segmentation image and the Region of interest image matching.
在本申请实施例中,在原始人物图像的预处理阶段,先确定原始人物图像的抠图感兴趣区域,并基于该抠图感兴趣区域对原始人物图像及人像分割图像进行裁剪,以得到后续用于生成头发掩膜的感兴趣区域图像及区域分割图像,可提高后续生成的头发掩膜的准确性,且不需要整张图像参考生成头发掩膜的过程,可减少计算量,提高图像处理效率。In the embodiment of the present application, in the preprocessing stage of the original person image, the matting region of interest of the original person image is firstly determined, and based on the matting region of interest, the original person image and the segmented portrait image are cropped to obtain the subsequent The image of the region of interest and the region segmentation image used to generate the hair mask can improve the accuracy of the subsequently generated hair mask, and does not require the entire image to refer to the process of generating the hair mask, which can reduce the amount of calculation and improve image processing efficiency.
如图6所示,在一个实施例中,提供另一种图像处理方法,可应用于上述的电子设备。该方法可包括以下步骤:As shown in FIG. 6 , in one embodiment, another image processing method is provided, which can be applied to the above-mentioned electronic device. The method may include the steps of:
步骤602,对原始人物图像进行预处理,得到原始人物图像的感兴趣区域图像,以及与感兴趣区域图像对应的区域分割图像。 Step 602, preprocessing the original person image to obtain the ROI image of the original person image and the region segmentation image corresponding to the ROI image.
步骤602的描述可参与上述各实施例中关于预处理的相关描述,在此不再一一赘述。The description of step 602 may participate in the relevant descriptions about preprocessing in the foregoing embodiments, and will not be repeated here.
步骤604,将感兴趣区域图像及区域分割图像输入图像处理模型,通过图像处理模型对感兴趣区域图像及区域分割图像进行处理,得到第一头发掩膜。Step 604: Input the image of the region of interest and the region segmentation image into the image processing model, and process the region of interest image and the region segmentation image through the image processing model to obtain a first hair mask.
在一些实施例中,在将感兴趣区域图像及区域分割图像输入图像处理模型之前,可先判断感兴趣区域图像及区域分割图像的图像尺寸是否与图像处理模型对应的输入图像尺寸匹配。若感兴趣区域图像及区域分割图像的图像尺寸不与图像处理模型对应的输入图像尺寸匹配,则可先对感兴趣区域图像及区域分割图像进行旋转及缩放处理,以得到与图像处理模型对应的输入图像尺寸匹配的感兴趣区域图像及区域分割图像。In some embodiments, before inputting the region-of-interest image and the region-segmented image into the image processing model, it may be determined whether the image size of the region-of-interest image and the region-segmented image matches the corresponding input image size of the image processing model. If the image size of the region of interest image and the region segmentation image does not match the input image size corresponding to the image processing model, the image of the region of interest and the region segmentation image can be rotated and scaled first to obtain the image corresponding to the image processing model The input image size matches the ROI image and the region segmentation image.
例如,图像处理模型对应的输入图像尺寸为纵向输入尺寸(图像的长小于宽),若感兴趣区域图像及区域分割图像为横向图像(图像的长大于宽),则可将感兴趣区域图像及区域分割图像顺时针或逆时针旋转90度后,再输入到图像处理模型中,从而可保证输入的感兴趣区域图像及区域分割图像的图像尺寸与图像处理模型适配,提高图像处理模型的处理准确度。For example, the input image size corresponding to the image processing model is a vertical input size (the length of the image is smaller than the width), if the ROI image and the region segmentation image are horizontal images (the length of the image is larger than the width), the ROI image and After the region segmentation image is rotated 90 degrees clockwise or counterclockwise, it is then input into the image processing model, so as to ensure that the image size of the input region of interest image and region segmentation image is adapted to the image processing model, and the processing of the image processing model is improved. Accuracy.
图像处理模型可包括CNN(Convolutional Neural Networks,卷积神经网络)等神经网络模型。作为一种具体实施方式,图像处理模型可以是U-NET的神经网络架构,可将感兴趣区域图像及区域分割图像进行连接,并输入图像处理模型。图像处理模型可包括多个下采样层及多个上采样层,图像处理模型可通过多个下采样层先对感兴趣区域图像及区域分割图像进行多次的下采样卷积处理,再通过多个上采样层进行多次的上采样处理,得到小于输入的图像或与输入的图像具有相同分辨率的第一头发掩膜。图像处理模型中,相同分辨率之间的下采样层及上采样层之间可实现跳跃连接,将相同分辨率之间的下采样层与上采样层的特征进行融合,使得上采样过程更加准确。Image processing models may include neural network models such as CNN (Convolutional Neural Networks, Convolutional Neural Networks). As a specific implementation, the image processing model can be a neural network architecture of U-NET, which can connect the image of the region of interest and the image of the region segmentation, and input the image processing model. The image processing model can include multiple down-sampling layers and multiple up-sampling layers. The image processing model can perform multiple down-sampling and convolution processing on the image of the region of interest and the region segmentation image through multiple down-sampling layers, and then through multiple down-sampling layers. Upsampling layers perform multiple upsampling processes to obtain the first hair mask that is smaller than the input image or has the same resolution as the input image. In the image processing model, skip connections can be realized between the downsampling layer and upsampling layer between the same resolutions, and the features of the downsampling layer and upsampling layer between the same resolutions are fused to make the upsampling process more accurate .
图7为一个实施例中通过图像处理模型生成第一头发掩膜的示意图。如图7所示,可将感兴趣区域图像712及对应的区域分割图像714输入图像处理模型720,图像处理模型720可对感兴趣区域图像712及区域分割图像714进行处理,并输出第一头发掩膜732。Fig. 7 is a schematic diagram of generating a first hair mask through an image processing model in an embodiment. As shown in FIG. 7 , the region-of-interest image 712 and the corresponding region segmentation image 714 can be input into the image processing model 720, and the image processing model 720 can process the region-of-interest image 712 and the region segmentation image 714, and output the first hair mask 732 .
图像处理模型可以是根据多组样本训练图像进行训练得到的,每一组样本训练图像可包括样本人物图像、与样本人物图像对应的样本人像分割图像及样本头发掩膜,可选地,每一组样本训练图像也可包括携带有头发区域信息的样本人物图像及对应的样本人像分割图像。进一步地,样本人物图像及样本人像分割图像可以是按照设定尺寸进行裁剪或缩放后的图像,可保证输入到图像处理模型的图像的尺寸保持一致。The image processing model can be obtained by training according to multiple sets of sample training images. Each set of sample training images can include a sample character image, a sample portrait segmentation image corresponding to the sample character image, and a sample hair mask. Optionally, each The set of sample training images may also include sample person images carrying hair region information and corresponding sample person segmentation images. Furthermore, the sample character image and the sample segmented portrait image may be cropped or scaled images according to a set size, which can ensure that the sizes of the images input to the image processing model remain consistent.
在对图像处理模型进行训练时,可将一组样本训练图像输入待训练的图像处理模型,待训练的图像处理模型可对输入的样本人物图像及样本人像分割图像进行处理,得到预测头发掩膜,可将预测头发掩膜与样本头发掩膜进行比对,并通过损失函数计算预测头发掩膜相对样本头发掩膜的损失,再根据该损失对图像处理模型的参数进行调整,直至计算得到的损失小于预设的损失阈值,或参数调整的次数达到次数阈值等,满足图像处理模型的收敛条件。When training the image processing model, a set of sample training images can be input into the image processing model to be trained, and the image processing model to be trained can process the input sample person images and sample portrait segmentation images to obtain the predicted hair mask , the predicted hair mask can be compared with the sample hair mask, and the loss of the predicted hair mask relative to the sample hair mask can be calculated through the loss function, and then the parameters of the image processing model can be adjusted according to the loss until the calculated If the loss is less than the preset loss threshold, or the number of parameter adjustments reaches the number threshold, etc., the convergence condition of the image processing model is satisfied.
可选地,上述的损失函数可包括L1损失函数及L2损失函数等中的至少一种,L1损失函数是通过计算预测头发掩膜和样本头发掩膜之间差值的绝对值的和,L2损失函数是通过计算计算预测头发掩膜和样本头发掩膜之间差值的平方的和。Optionally, the above loss function may include at least one of L1 loss function and L2 loss function, etc., the L1 loss function is the sum of the absolute value of the difference between the predicted hair mask and the sample hair mask, L2 The loss function is calculated by computing the sum of the squares of the difference between the predicted hair mask and the sample hair mask.
在一些实施例中,由于在对人物图像进行虚化处理时,将背景区域误判为前景区域而没有进行虚化 的情况,相比前景区域被误判为背景区域进行虚化的情况会更加显眼,因此,在计算预测头发掩膜相对样本头发掩膜的损失时,可重点关注背景区域被误判为前景区域的情况,在计算损失时,背景区域被误判为前景区域对应的损失系数可大于前景区域被误判为背景区域对应的损失系数。可选地,损失函数可为式(2):In some embodiments, since the background area is misjudged as the foreground area and not blurred when performing blurring processing on the person image, it will be more difficult than the situation where the foreground area is misjudged as the background area and blurred. Conspicuous, therefore, when calculating the loss of the predicted hair mask relative to the sample hair mask, you can focus on the situation where the background area is misjudged as the foreground area. When calculating the loss, the background area is misjudged as the loss coefficient corresponding to the foreground area It can be greater than the loss coefficient corresponding to the foreground area being misjudged as the background area. Optionally, the loss function can be formula (2):
L(y,t)=δ(t<α)·max(y-t,0) 2      式(2); L(y,t)=δ(t<α) max(yt,0) 2 formula (2);
其中,L(y,t)表示预测头发掩膜相对样本头发掩膜的损失,α可为设置的门槛值,δ可为判定函数,用于判断t是否小于α,若小于,则输出1,若不小于,则输出0,y可指的是预测头发掩膜,t可为样本头发掩膜。通过该损失函数,可有效减轻背景区域被误判为前景区域的情况,能够提高图像处理模型生成第一头发掩膜的准确性,提高后续进行图像虚化处理时的处理效果。Among them, L(y, t) represents the loss of the predicted hair mask relative to the sample hair mask, α can be the threshold value set, δ can be a judgment function, which is used to judge whether t is less than α, if it is less than 1, output 1, If not less than, output 0, y may refer to the predicted hair mask, and t may be the sample hair mask. Through this loss function, the situation that the background area is misjudged as the foreground area can be effectively reduced, the accuracy of the image processing model to generate the first hair mask can be improved, and the processing effect of subsequent image blurring processing can be improved.
在一些实施例中,由于样本人物图像中的头发区域可能会出现一些半透明的情况(例如发丝较少或是发丝在飞起来时出现的效果),如果在相应的样本头发掩膜中将该半透明的头发区域标注出来,可能会导致后续在进行前景人像区域及背景图像分离后的图像处理效果较差。例如,在对背景区域进行虚化处理时,如果生成的头发掩膜将前景的人像区域中半透明的头发区域也全部标注出来,会导致背景区域透过半透明的头发区域,导致虚化效果不自然。因此,在本申请实施例中,可对样本头发掩膜进行增强。In some embodiments, since the hair region in the sample character image may have some translucency (such as less hair strands or the effect of hair strands flying up), if in the corresponding sample hair mask Marking the translucent hair area may lead to poor image processing effect after the foreground portrait area and background image are separated. For example, when blurring the background area, if the generated hair mask marks all the semi-transparent hair areas in the foreground portrait area, the background area will pass through the semi-transparent hair area, resulting in ineffective blur effect. nature. Therefore, in the embodiment of the present application, the sample hair mask can be enhanced.
作为一种具体实施方式,样本头发掩膜可以是根据样本人物图像对应的背景复杂度图像进行腐蚀处理后得到的。可利用样本人物图像的背景复杂度图确定背景复杂区域,并对第一头发掩膜中处于背景复杂区域周围的头发区域进行腐蚀处理,以缩小在背景复杂区域周围的掩膜区域。通过增强后的样本头发掩膜对图像处理模型进行训练,可使得训练得到的图像处理模型能够减少对半透明的头发进行标注的情况,以提高后续的图像处理效果。As a specific implementation manner, the sample hair mask may be obtained by performing erosion processing on the background complexity image corresponding to the sample character image. The complex background area can be determined by using the background complexity map of the sample person image, and the hair area around the complex background area in the first hair mask is eroded to reduce the mask area around the complex background area. The image processing model is trained through the enhanced sample hair mask, so that the trained image processing model can reduce the labeling of translucent hair, so as to improve the subsequent image processing effect.
在一些实施例中,电子设备根据感兴趣区域图像及区域分割图像生成的第一头发掩膜的图像分辨率可能较小,因此,步骤对第一头发掩膜进行优化处理,以得到原始人物图像对应的目标头发掩膜,可包括步骤606及608。In some embodiments, the image resolution of the first hair mask generated by the electronic device based on the region-of-interest image and the region-segmented image may be relatively small. Therefore, the step optimizes the first hair mask to obtain the original person image The corresponding target hair mask may include steps 606 and 608 .
步骤606,对第一头发掩膜进行优化处理,得到第二头发掩膜。 Step 606, optimize the first hair mask to obtain a second hair mask.
由于图像处理模型生成的第一头发掩膜不够准确,因此可对第一头发掩膜进进行优化处理,以修正图像处理模型生成的第一头发掩膜,得到更加准确、细致的第二头发掩膜。Since the first hair mask generated by the image processing model is not accurate enough, the first hair mask can be optimized to correct the first hair mask generated by the image processing model to obtain a more accurate and detailed second hair mask. membrane.
作为一种实施方式,若原始人物图像为经过旋转的图像,由于图像处理模型输出的第一头发掩膜的旋转方向可能与原始人物图像不一致,则可将按照原始人物图像的旋转方向对第一头发掩膜进行旋转,使得第一头发掩膜与原始人物图像中的人像区域的方向保持一致,再对旋转后的第一头发掩膜进行优化处理。As an implementation, if the original character image is a rotated image, since the rotation direction of the first hair mask output by the image processing model may be inconsistent with the original character image, the first The hair mask is rotated so that the direction of the first hair mask is consistent with that of the portrait area in the original person image, and then the rotated first hair mask is optimized.
在一些实施例中,电子设备对第一头发掩膜进行优化处理,得到第二头发掩膜,可包括但不限于以下几种处理方式中的任一种处理方式,或以下几种处理方式中任意多种处理方式的组合:In some embodiments, the electronic device optimizes the first hair mask to obtain the second hair mask, which may include but not limited to any of the following processing methods, or any of the following processing methods Any combination of processing methods:
方式一、计算感兴趣区域图像对应的背景复杂度图像,并根据背景复杂度图像对第一头发掩膜进行腐蚀处理,得到第二头发掩膜。Method 1: Calculate the background complexity image corresponding to the ROI image, and perform erosion processing on the first hair mask according to the background complexity image to obtain the second hair mask.
感兴趣区域图像对应的背景复杂度图像可包括感兴趣区域图像的背景复杂度,该背景复杂度可用于描述感兴趣区域图像中的背景区域的复杂程度,背景区域包含的图像特征越多,对应的复杂度可越高。由于在背景复杂度高的图像中,容易出现背景区域被误认为前景区域的情况,因此,可计算感兴趣区域图像的背景复杂度,并利用该背景复杂度对第一头发掩膜进行腐蚀处理,减少背景区域被误认为前景区域的情况。The background complexity image corresponding to the ROI image can include the background complexity of the ROI image, which can be used to describe the complexity of the background area in the ROI image. The more image features the background area contains, the corresponding The complexity can be higher. Because in the image with high background complexity, it is easy for the background area to be mistaken for the foreground area, therefore, the background complexity of the image of the region of interest can be calculated, and the first hair mask can be eroded using the background complexity , to reduce the situation where background regions are mistaken for foreground regions.
如图8所示,在一个实施例中,步骤计算感兴趣区域图像对应的背景复杂度图像可包括步骤802~808。As shown in FIG. 8 , in one embodiment, the step of calculating the background complexity image corresponding to the ROI image may include steps 802 - 808 .
步骤802,获取感兴趣区域图像的灰度图像。 Step 802, acquiring a grayscale image of the ROI image.
灰度图像为每个像素只有一个采样颜色的图像,该灰度图像显示为从黑色到白色的灰度。电子设备的存储器可预先存储有原始人物图像对应的灰度图像,可根据确定的抠图感兴趣区域对原始人物图像对应的灰度图像进行裁剪,得到感兴趣区域图像的灰度图像。作为另一种实施方式,电子设备也可在获取感兴趣区域图像后,将感兴趣区域图像从RGB格式或YUV格式等转换成灰度图像。A grayscale image is an image with only one sampled color per pixel, which appears as a gray scale from black to white. The memory of the electronic device may pre-store the grayscale image corresponding to the original person image, and the grayscale image corresponding to the original person image may be cropped according to the determined region of interest in matting to obtain the grayscale image of the region of interest image. As another implementation manner, after acquiring the image of the region of interest, the electronic device may convert the image of the region of interest from RGB format or YUV format to a grayscale image.
步骤804,对灰度图像进行边缘检测,得到第一边缘图像。 Step 804, performing edge detection on the grayscale image to obtain a first edge image.
电子设备可采用Canny边缘检测算子、Laplacian检测算子、DoG检测算子、索菲尔检测算子等对灰度图像进行边缘检测,得到包含灰度图像中所有边缘信息的第一边缘图像。需要说明的是,本申请实施例不对具体的边缘检测算法进行限定。The electronic device can use Canny edge detection operator, Laplacian detection operator, DoG detection operator, Sophier detection operator, etc. to perform edge detection on the grayscale image, and obtain the first edge image including all edge information in the grayscale image. It should be noted that the embodiment of the present application does not limit a specific edge detection algorithm.
步骤806,根据第一头发掩膜去除第一边缘图像中的头发边缘,得到第二边缘图像。Step 806: Remove hair edges in the first edge image according to the first hair mask to obtain a second edge image.
可根据第一头发掩膜确定第一边缘图像中的头发区域,并去除第一边缘图像中处于头发区域的头发 边缘,得到保留除头发区域以外的边缘的第二边缘图像。去除第一边缘图像中的头发边缘,可以防止因头发边缘对背景区域的边缘产生影响,导致背景复杂度计算不准确的情况。由于本申请针对的是头发区域的准确定位的方案,因此利用第一头发掩膜去除第一边缘图像中的头发边缘,可使得计算得到的背景复杂度更加准确,且更贴合头发区域的准确定位的方案。The hair region in the first edge image can be determined according to the first hair mask, and the hair edges in the hair region in the first edge image are removed to obtain a second edge image that retains edges other than the hair region. Removing the hair edge in the first edge image can prevent the inaccurate calculation of the background complexity due to the influence of the hair edge on the edge of the background region. Since this application is aimed at the accurate positioning of the hair region, using the first hair mask to remove the hair edge in the first edge image can make the calculated background complexity more accurate and more suitable for the accuracy of the hair region. Positioning scheme.
作为另一种实施方式,也可根据感兴趣区域图像对应的区域分割图像确定第一边缘图像中的人像区域,并去除第一边缘图像中处于人像区域的边缘,得到仅包含背景区域的边缘的第二边缘图像。As another implementation, it is also possible to determine the portrait area in the first edge image according to the region segmentation image corresponding to the region of interest image, and remove the edge in the portrait area in the first edge image to obtain an image that only includes the edge of the background area. Second edge image.
步骤808,对第二边缘图像进行膨胀处理及模糊处理,以得到背景复杂度图像。 Step 808, perform dilation and blur processing on the second edge image to obtain a background complexity image.
电子设备可对第二边缘图像中的边缘进行膨胀处理及模糊处理,以扩大第二边缘图中的边缘,使边缘特征更加明显,提高背景复杂度计算的准确性。其中,膨胀处理是一种局部求最大值的操作,可利用核与第二边缘图像中的边缘进行卷积,计算该核所覆盖的像素点,使得边缘增长。模糊处理可采用高斯模糊、均值模糊、中值模糊等处理方式,具体的膨胀处理方式及模糊处理方式在本申请实施例中不作限定。The electronic device can expand and blur the edges in the second edge image, so as to enlarge the edges in the second edge image, make edge features more obvious, and improve the accuracy of background complexity calculation. Wherein, the dilation process is a local maximization operation, and the kernel can be used to perform convolution with the edge in the second edge image, and the pixels covered by the kernel can be calculated to make the edge grow. The blurring processing may adopt Gaussian blurring, mean blurring, median blurring and other processing methods, and the specific dilation processing method and blurring processing method are not limited in the embodiment of the present application.
可根据膨胀处理及模糊处理后的第二边缘图像计算背景复杂度,得到相应的背景复杂度图像。作为一种具体实施方式,可根据膨胀处理及模糊处理后的第二边缘图像中处于背景区域的边缘计算背景复杂度,包含更多边缘的背景区域对应的背景复杂度较高,包含较少边缘的背景区域对应的背景复杂度较低。The background complexity can be calculated according to the dilated and blurred second edge image to obtain a corresponding background complexity image. As a specific implementation, the background complexity can be calculated according to the edges in the background area in the second edge image after dilation and blur processing, and the background area that contains more edges corresponds to a higher background complexity, and contains fewer edges The background region corresponding to the lower background complexity.
在一些实施例中,可设置有复杂度阈值,可将整个背景区域中,背景复杂度大于该复杂度阈值的区域定义为背景复杂区域,将背景复杂度小于或等于该复杂度阈值的区域定义为背景简单区域。可分别用不同的值(例如亮度值、灰度值或颜色值等)表示背景复杂区域和背景简单区域,以得到背景复杂度图像。In some embodiments, a complexity threshold can be set, and in the entire background area, the area whose background complexity is greater than the complexity threshold can be defined as the background complex area, and the area whose background complexity is less than or equal to the complexity threshold can be defined as A simple area for the background. Different values (such as brightness value, gray value or color value, etc.) can be used to represent the complex background area and the simple background area respectively, so as to obtain the background complexity image.
图9A为一个实施例中计算背景复杂度的示意图。如图9A所示,可先获取感兴趣区域图像的灰度图像910,并对灰度图像910进行边缘检测,得到第一边缘图像920,再利用灰度图像910匹配的第一头发掩膜912去除第一边缘图像920中的头发边缘,得到第二边缘图像930,该第二边缘图像930中保留除头发区域以外的边缘。可对第二边缘图像930进行膨胀及模糊处理,得到边缘图像940,再基于边缘图像940计算背景复杂度,得到背景复杂度图像。利用边缘特征计算背景复杂度,可提高背景复杂度的准确性,且可进一步提后后续利用背景复杂度优化第一头发掩膜的准确性。FIG. 9A is a schematic diagram of calculating background complexity in an embodiment. As shown in Figure 9A, the grayscale image 910 of the image of the region of interest can be obtained first, and edge detection is performed on the grayscale image 910 to obtain the first edge image 920, and then the first hair mask 912 matched with the grayscale image 910 The hair edge in the first edge image 920 is removed to obtain the second edge image 930, and the edge except the hair area is reserved in the second edge image 930. The second edge image 930 may be expanded and blurred to obtain an edge image 940, and then the background complexity is calculated based on the edge image 940 to obtain a background complexity image. Using the edge feature to calculate the background complexity can improve the accuracy of the background complexity, and can further improve the accuracy of the subsequent optimization of the first hair mask by using the background complexity.
电子设备可根据背景复杂度图像对第一头发掩膜进行腐蚀处理,得到第二头发掩膜。作为一种具体实施方式,可根据背景复杂度图像,确定第一头发掩膜中复杂度大于复杂度阈值的背景复杂区域,并对第一头发掩膜中处于背景复杂区域周围的头发区域进行腐蚀处理。背景复杂度图像中可通过不同的值表示背景复杂区域及背景简单区域,例如,可利用不同的灰度值表示,灰度值为255的区域表示背景简单区域,灰度值为0的区域表示背景复杂区域,也可用不同的颜色值表示,白色表示背景简单区域,黑色表示背景复杂区域,但不限于此。The electronic device can perform erosion processing on the first hair mask according to the background complexity image to obtain the second hair mask. As a specific implementation, according to the background complexity image, determine the complex background area in the first hair mask whose complexity is greater than the complexity threshold, and erode the hair area around the complex background area in the first hair mask deal with. In the background complexity image, different values can be used to represent the background complex area and the background simple area. For example, it can be represented by different gray values. The area with a gray value of 255 represents a simple background area, and the area with a gray value of 0 represents Areas with complex backgrounds can also be represented by different color values, white indicates areas with simple backgrounds, and black indicates areas with complex backgrounds, but not limited thereto.
由于背景复杂区域包含的图像内容较为丰富,因此很容易被误认为前景区域,导致第一头发掩膜中的头发区域不准确。可对第一头发掩膜中处于背景复杂区域周围的头发区域进行腐蚀处理,以对处于背景复杂区域周围的掩膜进行缩减,改善背景区域被误认为前景区域的情况。其中,腐蚀处理是一种局部求最小值的操作,可利用核与第一头发掩膜中处于背景复杂区域周围的掩膜进行计算,保留覆盖该核的像素点,即实现利用背景复杂区域对周围的掩膜进行腐蚀的效果。可选地,可直接将腐蚀处理后的第一头发掩膜作为第二头发掩膜。Since the image content contained in the complex background area is relatively rich, it is easy to be mistaken for the foreground area, resulting in inaccurate hair area in the first hair mask. Erosion processing can be performed on the hair area around the complex background area in the first hair mask, so as to reduce the mask around the complex background area and improve the situation that the background area is mistaken for the foreground area. Among them, erosion processing is a local minimum operation, which can be calculated by using the mask around the complex background area in the kernel and the first hair mask, and retaining the pixels covering the kernel, that is, using the complex background area to realize The effect of etching around the mask. Optionally, the first hair mask after corrosion treatment can be directly used as the second hair mask.
作为另一种实施方式,在对第一头发掩膜进行腐蚀处理后,可将腐蚀处理前的第一头发掩膜(即初始得到的第一头发掩膜)与腐蚀处理后的第一头发掩膜进行融合,得到第二头发掩膜。可选地,该融合的方式可包括但不限于取均值进行融合、分配不同权重系数融合等。As another embodiment, after the first hair mask is subjected to corrosion treatment, the first hair mask before the corrosion treatment (that is, the initially obtained first hair mask) can be combined with the first hair mask after the corrosion treatment. The films are fused to obtain a second hair mask. Optionally, the merging manner may include but not limited to taking an average value for merging, allocating different weight coefficients for merging, and the like.
具体地,可将腐蚀处理前的第一头发掩膜与腐蚀处理后的第一头发掩膜进行Alpha融合处理,Alpha融合处理可为腐蚀处理前的第一头发掩膜及腐蚀处理后的第一头发掩膜中的每个像素点分别赋予一个Alpha值,使得腐蚀处理前的第一头发掩膜与腐蚀处理后的第一头发掩膜具有不同的透明度。作为一种实施方式,可将背景复杂度图像作为腐蚀处理后的第一头发掩膜的Alpha值,根据背景复杂度图像对腐蚀处理前的第一头发掩膜与腐蚀处理后的第一头发掩膜中的每对匹配像素点进行融合,得到第二头发掩膜。Specifically, the first hair mask before the corrosion treatment and the first hair mask after the corrosion treatment can be subjected to Alpha fusion processing, and the Alpha fusion treatment can be the first hair mask before the corrosion treatment and the first hair mask after the corrosion treatment. Each pixel in the hair mask is assigned an Alpha value, so that the first hair mask before the erosion process and the first hair mask after the erosion process have different transparency. As an implementation, the background complexity image can be used as the Alpha value of the first hair mask after corrosion processing, and the first hair mask before corrosion processing and the first hair mask after corrosion processing can be compared according to the background complexity image. Each pair of matching pixels in the mask is fused to obtain the second hair mask.
图9B为一个实施例中将腐蚀处理前的第一头发掩膜与腐蚀处理后的第一头发掩膜进行融合的示意图。如图9B所示,可将腐蚀处理前的第一头发掩膜与腐蚀处理后的第一头发掩膜进行Alpha融合处理,Alpha融合处理的公式可如式(3)所示:Fig. 9B is a schematic diagram of fusing the first hair mask before the etching treatment and the first hair mask after the etching treatment in one embodiment. As shown in Figure 9B, the first hair mask before the corrosion treatment and the first hair mask after the corrosion treatment can be subjected to Alpha fusion processing, and the formula of Alpha fusion processing can be as shown in formula (3):
I=αI 1+(1-α)I 2   式(3); I=αI 1+ (1-α)I 2 formula (3);
其中,I 1表示腐蚀处理后的第一头发掩膜954,I 2表示腐蚀处理前的第一头发掩膜952,α表示腐蚀处理后的第一头发掩膜954的Alpha值,I表示融合得到的第二头发掩膜958。可将背景复杂度图像956作为腐蚀处理后的第一头发掩膜954的Alpha值α,并对腐蚀处理后的第一头发掩膜954及腐蚀处理前的第一头发掩膜952进行Alpha融合处理,得到第二头发掩膜958。将腐蚀处理前的第一头发掩膜与腐蚀处理后的第一头发掩膜进行融合,且利用背景复杂度图像作为Alpha值进行融合,可提高得到的第二头发掩膜的准确性,改善背景区域被误认为前景区域的情况,提高后续的图像处理效果。 Wherein, I 1 represents the first hair mask 954 after the corrosion process, I 2 represents the first hair mask 952 before the corrosion process, α represents the Alpha value of the first hair mask 954 after the corrosion process, and I represents the result of fusion 958 for the second hair mask. The background complexity image 956 can be used as the Alpha value α of the first hair mask 954 after corrosion processing, and Alpha fusion processing is performed on the first hair mask 954 after corrosion processing and the first hair mask 952 before corrosion processing , to obtain the second hair mask 958 . Fusing the first hair mask before corrosion processing with the first hair mask after corrosion processing, and using the background complexity image as the Alpha value for fusion can improve the accuracy of the obtained second hair mask and improve the background The situation where the area is mistaken for the foreground area improves the effect of subsequent image processing.
方式二、对第一头发掩膜的头发区域中的孔洞进行填充,得到第二头发掩膜。Method 2: Fill holes in the hair region of the first hair mask to obtain a second hair mask.
由于人的头发丝很多,因此在头发区域可能会出现比较多的孔洞,若是直接将孔洞中的图像内容确定为背景区域,那在后续进行背景区域与人像区域分离及图像处理(例如背景虚拟处理等)中,可能会造成图像处理的效果较差的问题。因此,在本申请实施例中,可对第一头发掩膜的头发区域中的孔洞进行填充。Since there are many strands of human hair, there may be more holes in the hair area. If the image content in the holes is directly determined as the background area, then the background area and the portrait area will be separated and the image processing (such as background virtual processing) will be performed later. etc.), it may cause the problem that the effect of image processing is poor. Therefore, in the embodiment of the present application, holes in the hair region of the first hair mask may be filled.
作为一种具体实施方式,可计算第一头发掩膜的头发区域的置信度,并根据置信度对头发区域中的孔洞进行填充。可选地,可先利用第一头发掩膜确定感兴趣区域中的头发区域,可根据感兴趣区域中的头发区域的图像特征(如边缘特征、颜色特征、亮度特征等)计算第一头发掩膜的头发区域的置信度。置信度越高的头发掩膜区域,表示属于真实头发区域的可能性越高,准确度越高。需要说明的是,也可采用其它方式计算置信度,在此不作限定。As a specific implementation manner, the confidence degree of the hair region of the first hair mask may be calculated, and holes in the hair region may be filled according to the confidence degree. Optionally, the first hair mask can be used to determine the hair region in the region of interest, and the first hair mask can be calculated according to the image characteristics (such as edge characteristics, color characteristics, brightness characteristics, etc.) of the hair region in the region of interest. Confidence of the hair region of the membrane. A hair mask region with a higher confidence indicates a higher possibility of belonging to a real hair region and a higher accuracy. It should be noted that other methods may also be used to calculate the confidence level, which is not limited here.
可根据预设的置信度阈值对第一头发掩膜的头发区域进行划分,提取置信度高于该置信息度阈值的头发掩膜区域,并对该头发掩膜区域进行膨胀处理,进一步地,还可对置信度不高于该置信息度阈值的头发掩膜区域进行腐蚀处理,以达到填充第一头发掩膜的头发区域中的孔洞的效果。可选地,可直接将进行填充处理后的第一头发掩膜作为第二头发掩膜。The hair region of the first hair mask can be divided according to the preset confidence threshold, and the hair mask region whose confidence is higher than the confidence threshold is extracted, and the hair mask region is expanded, and further, Erosion processing may also be performed on the hair mask region whose confidence level is not higher than the confidence threshold, so as to achieve the effect of filling holes in the hair region of the first hair mask. Optionally, the first hair mask after the filling treatment can be directly used as the second hair mask.
作为另一种实施方式,也可将填充处理后的第一头发掩膜与填充处理前的第一头发掩膜进行融合,得到第二头发掩膜,其融合方式可包括但不限于均值融合、分配不同权重融合等,也可以是Alpha融合,根据设置的Alpha值对填充处理后的第一头发掩膜与填充处理前的第一头发掩膜进行Alpha融合处理。具体的融合方式可与上述实施例中将腐蚀处理前的第一头发掩膜与腐蚀处理后的第一头发掩膜进行融合的方式类似,可参考上述的相关描述,在此不再赘述。As another embodiment, the first hair mask after the filling process can also be fused with the first hair mask before the filling process to obtain the second hair mask, and the fusion method can include but not limited to mean fusion, Allocation of different weights for fusion, etc., can also be Alpha fusion, and Alpha fusion is performed on the first hair mask after filling processing and the first hair mask before filling processing according to the set Alpha value. The specific fusion method may be similar to the method of fusing the first hair mask before the corrosion treatment and the first hair mask after the corrosion treatment in the above embodiment, and reference may be made to the relevant description above, which will not be repeated here.
图10为一个实施例中对第一头发掩膜中的孔洞进行填充的示意图。如图10所示,可对第一头发掩膜1010中的孔洞进行填充,得到孔洞被填充的第二头发掩膜,能够改善后续在对原始人物图像的背景区域进行虚化时,将头发区域内的背景也一并进行虚化造成人像出现模糊的情况,提高了后续的图像处理效果。Figure 10 is a schematic diagram of filling holes in the first hair mask in one embodiment. As shown in Figure 10, the holes in the first hair mask 1010 can be filled to obtain a second hair mask with the holes filled, which can improve the subsequent blurring of the hair area when blurring the background area of the original character image. The background inside is also blurred, resulting in blurred portraits, which improves the effect of subsequent image processing.
方式三、对第一头发掩膜的头发区域的边缘进行增强处理,得到第二头发掩膜。Mode 3: Enhance the edge of the hair region of the first hair mask to obtain the second hair mask.
增强处理可包括但不限于基于直方图均衡化的增强处理、基于拉普拉斯算子的增强处理、基于对数Log变换的增强处理等,本申请实施例对此不作限定。作为一种具体实施方式,可利用sigmoid函数对第一头发掩膜的头发区域的边缘进行增强处理,利用sigmoid函数对第一头发掩膜的头发区域的边缘上的像素点进行计算,得到第二头发掩膜。The enhancement processing may include but not limited to histogram equalization-based enhancement processing, Laplacian-based enhancement processing, logarithmic-Log transformation-based enhancement processing, etc., which is not limited in this embodiment of the present application. As a specific embodiment, the sigmoid function can be used to enhance the edge of the hair region of the first hair mask, and the sigmoid function is used to calculate the pixels on the edge of the hair region of the first hair mask to obtain the second Hair mask.
图11为一个实施例中对第一头发掩膜的头发区域进行增强处理的示意图。如图11所示,可对第一头发掩膜1110的头发区域的边缘进行增强处理,得到边缘更加清晰的第二头发掩膜1120。通过对第一头发掩膜的头发区域的边缘进行增强处理,可使得后续得到的前景的人像区域更加清晰,提高图像处理效果。Fig. 11 is a schematic diagram of enhancing the hair region of the first hair mask in an embodiment. As shown in FIG. 11 , the edge of the hair region of the first hair mask 1110 may be enhanced to obtain a second hair mask 1120 with clearer edges. By performing enhancement processing on the edge of the hair region of the first hair mask, the subsequently obtained foreground portrait region can be made clearer and the image processing effect can be improved.
方式四、若原始人物图像对应的图像场景为目标场景,则对第一头发掩膜的头发区域的边缘进行柔化处理,得到第二头发掩膜。Method 4: If the image scene corresponding to the original person image is the target scene, soften the edges of the hair region of the first hair mask to obtain a second hair mask.
在本申请实施例中,目标场景为场景亮度值低于亮度阈值的场景,例如夜晚场景、亮度较暗的室内场景等。由于在较暗的目标场景下,在对原始人物图像的背景区域进行虚拟时,若前景的人物图像的边缘清晰度很高,可能会导致虚化之后的边缘看起来不够自然,影响图像处理效果。因此,在本申请实施例中,可先判断原始人物图像对应的图像场景是否为目标场景,若为目标场景,则可对第一头发掩膜的头发区域的边缘进行柔化处理,使第一头发掩膜的头发区域的边缘变得模糊,以提高后续背景虚化处理后的图像效果。In the embodiment of the present application, the target scene is a scene with a scene brightness value lower than a brightness threshold, such as a night scene, a dark indoor scene, and the like. In a darker target scene, when virtualizing the background area of the original character image, if the edge definition of the foreground character image is high, it may cause the blurred edge to look unnatural and affect the image processing effect . Therefore, in the embodiment of the present application, it can first be judged whether the image scene corresponding to the original person image is the target scene, and if it is the target scene, the edge of the hair region of the first hair mask can be softened so that the first The edges of the hair area of the hair mask are blurred to improve the image after subsequent bokeh processing.
可选地,柔化处理可采用高斯滤波、均值滤波、中值滤波等处理方式,在此不作限定。Optionally, the softening process may use Gaussian filtering, mean filtering, median filtering and other processing manners, which are not limited herein.
在一些实施例中,可通过场景分类模型判断原始人物图像对应的图像场景是否为目标场景,该场景分类模型可以是根据大量的目标场景样本图像进行训练得到的,场景分类模型可提取原始人物图像的图像特征,并根据该图像特征判断原始人物图像是否属于目标场景。In some embodiments, it can be judged whether the image scene corresponding to the original character image is the target scene through the scene classification model. The scene classification model can be obtained by training according to a large number of sample images of the target scene. The scene classification model can extract the original character image image features, and judge whether the original character image belongs to the target scene according to the image features.
在一些实施例中,电子设备可获取原始人物图像对应的感光值(ISO),该感光值可用于是衡量底片对于光的灵敏程度。若原始人物图像为电子设备通过摄像头实时采集的图像,则可直接获取摄像头当前的感光值,若原始人物图像为存储器中存储的图像,则可从存储器中读取该原始人物图像相关的拍摄参数,从而获取感光值。In some embodiments, the electronic device can acquire the sensitivity value (ISO) corresponding to the original character image, and the sensitivity value can be used to measure the sensitivity of the film to light. If the original person image is an image captured by the electronic device in real time through the camera, the current photosensitive value of the camera can be obtained directly; if the original person image is an image stored in the memory, the shooting parameters related to the original person image can be read from the memory , so as to obtain the sensitivity value.
可判断原始人物图像对应的感光值是否大于感光阈值,若感光值大于感光阈值,说明原始人物图像的感光值较高,感光值越高,底片对弱光的敏感度越高,则可捕抓到更多的弱光,适用于光线较暗的场景下使用。因此,若原始人物图像对应的感光值大于感光阈值,可确定原始人物图像对应的图像场景为目标场景,可对第一头发掩膜的头发区域的边缘进行柔化处理。该感光阈值可以是经过多次试验测试得到的经验值。It can judge whether the photosensitive value corresponding to the original character image is greater than the photosensitive threshold. If the photosensitive value is greater than the photosensitive threshold, it means that the photosensitive value of the original character image is higher. To more low light, suitable for use in low-light scenes. Therefore, if the photosensitive value corresponding to the original person image is greater than the photosensitive threshold, the image scene corresponding to the original person image can be determined as the target scene, and the edge of the hair region of the first hair mask can be softened. The photosensitivity threshold may be an empirical value obtained through multiple experiments and tests.
需要说明的是,判断原始人物图像对应的图像场景是否为目标场景也可采用其它方式,本申请实施例对此不作限定。It should be noted that other methods may also be used to determine whether the image scene corresponding to the original character image is the target scene, which is not limited in this embodiment of the present application.
图12为一个实施例中对第一头发掩膜进行柔化处理的示意图。如图12所示,在原始人物图像为光线较暗的目标场景下的图像时,可对第一头发掩膜1210的头发区域的边缘进行柔化处理,得到边缘模糊的第二头发掩膜1220。通过对第一头发掩膜的头发区域的边缘进行柔化处理,可使得后续在对目标场景下的原始人物图像进行背景区域的虚化处理时,人像的边缘过渡得更加自然,提高虚化效果。Fig. 12 is a schematic diagram of softening the first hair mask in one embodiment. As shown in FIG. 12 , when the original character image is an image in a dark target scene, the edge of the hair region of the first hair mask 1210 can be softened to obtain a second hair mask 1220 with blurred edges . By softening the edge of the hair area of the first hair mask, it is possible to make the edge transition of the portrait more natural and improve the blur effect when the background area of the original character image in the target scene is subsequently blurred. .
需要说明的是,上述的几种优化处理方式可随意进行组合,例如,可先计算感兴趣区域图像对应的背景复杂度图像,根据该背景复杂度图像对第一头发掩膜进行腐蚀处理,再对腐蚀处理后的第一头发掩膜的头发区域中的孔洞进行填充,得到第二头发掩膜。It should be noted that the above several optimization processing methods can be combined at will. For example, the background complexity image corresponding to the image of the region of interest can be calculated first, and the first hair mask is corroded according to the background complexity image, and then Holes in the hair region of the first hair mask after the erosion treatment are filled to obtain a second hair mask.
又例如,可先计算感兴趣区域图像对应的背景复杂度图像,根据该背景复杂度图像对第一头发掩膜进行腐蚀处理,再对腐蚀处理后的第一头发掩膜的头发区域中的孔洞进行填充,然后对填充后的第一头发掩膜的头发区域的边缘进行增强处理,若原始人物图像对应的图像场景为目标场景,则可再对增强处理后的第一头发掩膜的头发区域的边缘进行柔化处理,以得到第二头发掩膜,若原始人物图像对应的图像场景不为目标场景,则可将增强处理后的第一头发掩膜作为第二头发掩膜。For another example, the background complexity image corresponding to the region-of-interest image can be calculated first, and the first hair mask is eroded according to the background complexity image, and then the holes in the hair region of the eroded first hair mask are Carry out filling, then carry out enhancement processing to the edge of the hair region of the first hair mask after filling, if the image scene corresponding to the original character image is the target scene, then the hair region of the first hair mask after the enhancement processing can be The edge of the image is softened to obtain a second hair mask. If the image scene corresponding to the original person image is not the target scene, the enhanced first hair mask can be used as the second hair mask.
组合的方式可为多种,且不同处理方式的先后顺序在本申请实施例中也不作限定,各种不同组合的优化处理方式在此不一一进行列举。There may be multiple combinations, and the sequence of different processing methods is not limited in the embodiment of the present application, and the optimization processing methods of various combinations are not listed here one by one.
在本申请实施例中,通过对第一头发掩膜进行优化处理,能够得到更为细致、准确的第二头发掩膜,从而可提高后续对原始人物图像进行前景、背景分离等图像处理时的图像处理效果。In the embodiment of the present application, by optimizing the first hair mask, a more detailed and accurate second hair mask can be obtained, which can improve the subsequent image processing of the original person image such as foreground and background separation. image processing effects.
步骤608,对第二头发掩膜进行上采样滤波处理,得到原始人物图像对应的目标头发掩膜。Step 608: Perform upsampling and filtering on the second hair mask to obtain a target hair mask corresponding to the original person image.
由于图像处理模型输出的第一头发掩膜的分辨率较小,因此,对第一头发掩膜进行优化处理后得到的第二头发掩膜的分辨率也较低,可对第二头发掩膜进行上采样滤波处理,对第二头发掩膜进行放大,得到与原始人物图像匹配的目标头发掩膜,从而利用目标头发掩膜对原始人物图像中的头发区域进行精准定位。Since the resolution of the first hair mask output by the image processing model is small, the resolution of the second hair mask obtained after optimizing the first hair mask is also low, and the second hair mask can be Perform upsampling and filtering processing, enlarge the second hair mask, and obtain the target hair mask matching the original character image, so as to use the target hair mask to accurately locate the hair area in the original character image.
在一些实施例中,可将感兴趣区域图像的灰度图像作为引导滤波器的引导图像,通过引导滤波器对第二头发掩膜进行上采样滤波处理,得到目标头发掩膜。引导滤波器在对第二头发掩膜进行上采样滤波处理时,可参考感兴趣区域图像的灰度图像的图像信息,能够使得输出的目标头发掩膜的纹理及边缘等特征与灰度图像相似。In some embodiments, the grayscale image of the region-of-interest image may be used as a guide image of the guide filter, and the guide filter is used to perform upsampling filtering on the second hair mask to obtain the target hair mask. When the guide filter performs upsampling filtering on the second hair mask, it can refer to the image information of the grayscale image of the region of interest image, so that the texture and edge characteristics of the output target hair mask are similar to the grayscale image .
图13为一个实施例中通过引导滤波器对第二头发掩膜进行上采样滤波处理的示意图。如图13所示,可先将第二头发掩膜1310的尺寸放大,得到放大后的第二头发掩膜1320,再以灰度图像1330作为引导图像,通过引导滤波器对放大后的第二头发掩膜1320进行引导滤波,得到目标头发掩膜1330。Fig. 13 is a schematic diagram of performing upsampling filtering on the second hair mask through a guided filter in an embodiment. As shown in Figure 13, the size of the second hair mask 1310 can be enlarged first to obtain the enlarged second hair mask 1320, and then the grayscale image 1330 is used as the guide image, and the enlarged second hair mask 1320 can be obtained through the guide filter. The hair mask 1320 undergoes guided filtering to obtain a target hair mask 1330 .
在一个实施例中,电子设备也可根据感兴趣区域图像的背景复杂度,对第二头发掩膜进行上采样滤波处理。在感兴趣区域图像的背景复杂度较低的情况下,说明感兴趣区域图像的背景较简单,则可利用引导滤波器对第二头发掩膜进行上采样滤波处理;在感兴趣区域图像的背景复杂度较高的情况下,说明感兴趣区域图像的背景较复杂,则可直接利用双线性插值算法对第二头发掩膜进行上采样滤波处理。这样可以防止出现在感兴趣区域图像的背景比较复杂的情况下,背景区域被误认为头发区域的问题,提高目标头发掩膜的准确性。In an embodiment, the electronic device may also perform upsampling filtering on the second hair mask according to the background complexity of the image of the region of interest. In the case that the background complexity of the region of interest image is low, it means that the background of the region of interest image is relatively simple, then the guided filter can be used to perform upsampling filtering on the second hair mask; in the background of the region of interest image In the case of high complexity, it means that the background of the image of the region of interest is complex, and the bilinear interpolation algorithm can be directly used to perform upsampling and filtering on the second hair mask. This can prevent the problem that the background area is mistaken for the hair area when the background of the image of the region of interest is relatively complex, and improve the accuracy of the target hair mask.
作为一种具体实施方式,电子设备可先根据感兴趣区域图像对应的背景复杂度图像对第二头发掩膜进行区域划分,得到背景简单区域及背景复杂区域,该背景简单区域为复杂度低于或等于复杂度阈值的背景区域,背景复杂区域为复杂度高于复杂度阈值的背景区域。划分背景简单区域及背景复杂区域可参考上述实施例中对第一头发掩膜进行优化处理的方式一中的相关描述,在此不再赘述。As a specific implementation, the electronic device can first divide the second hair mask into regions according to the background complexity image corresponding to the region of interest image, and obtain the simple background region and the complex background region. Or the background area equal to the complexity threshold, the background complex area is the background area whose complexity is higher than the complexity threshold. For dividing the simple background region and the complex background region, reference may be made to the relevant description in the first method of optimizing the first hair mask in the above embodiment, and details are not repeated here.
可针对背景简单区域及背景复杂区域,分别采用不同的滤波方法进行上采样滤波处理。对于背景简 单区域,可采用引导滤波进行上采样滤波处理。可将感兴趣区域图像的灰度图像作为引导滤波器的引导图像,通过引导滤波器对第二头发掩膜中处于背景简单区域周围的头发区域进行上采样滤波处理,得到第一滤波结果。For simple background areas and complex background areas, different filtering methods can be used for upsampling filtering processing. For simple background areas, guided filtering can be used for upsampling filtering. The grayscale image of the region of interest image can be used as the guiding image of the guiding filter, and the hair area around the simple background area in the second hair mask is subjected to upsampling filtering through the guiding filter to obtain the first filtering result.
对于背景复杂区域,可采用双线性插值算法进行上采样滤波处理。可采用双线性插值算法对第二头发掩膜中处于背景复杂区域周围的头发区域进行上采样滤波处理,得到第二滤波结果。双线性插值算法是有两个变量的插值函数的线性插值扩展,其核心思想是在两个方向分别进行一次线性插值,双线性插值算法是利用第二头发掩膜中的已知像素点对放大后的未知像素点进行插值,对于每个需要插值的像素点,可根据四个已知像素点进行计算。For areas with complex backgrounds, a bilinear interpolation algorithm can be used for upsampling filtering. A bilinear interpolation algorithm may be used to perform upsampling and filtering on the hair region around the complex background region in the second hair mask to obtain a second filtering result. The bilinear interpolation algorithm is a linear interpolation extension of the interpolation function with two variables. Its core idea is to perform a linear interpolation in two directions respectively. The bilinear interpolation algorithm uses the known pixels in the second hair mask Interpolation is performed on the enlarged unknown pixels, and for each pixel that needs to be interpolated, it can be calculated based on four known pixels.
在得到第一滤波结果与第二滤波结果后,电子设备可将第一滤波结果及第二滤波结果进行融合,得到目标头发掩膜。作为一种实施方式,可将第一滤波结果及第二滤波结果进行Alpha融合处理,可将背景复杂度图像作为第二滤波结果的Alpha值,利用背景复杂度图像对第一滤波结果及第二滤波结果进行Alpha融合处理,得到目标掩膜图像。After obtaining the first filtering result and the second filtering result, the electronic device can fuse the first filtering result and the second filtering result to obtain the target hair mask. As an implementation, the first filtering result and the second filtering result can be subjected to Alpha fusion processing, and the background complexity image can be used as the Alpha value of the second filtering result, and the background complexity image can be used to analyze the first filtering result and the second filtering result. Alpha fusion processing is performed on the filtering results to obtain the target mask image.
针对第二头发掩膜在不同复杂度的背景区域周围的掩膜区域,可分别采用不同的上采样滤波方式,可减少出现背景区域被误认为头发区域的情况,提高目标头发掩膜的准确性。需要说明的是,也可采用其它上采样滤波处理方式,例如双立方插值算法、最近邻插值算法等,本申请实施例对此不作限定。For the mask area of the second hair mask around the background area of different complexity, different upsampling filtering methods can be used respectively, which can reduce the situation where the background area is mistaken for the hair area and improve the accuracy of the target hair mask . It should be noted that other upsampling filtering processing methods may also be used, such as a bi-cubic interpolation algorithm, a nearest neighbor interpolation algorithm, etc., which are not limited in this embodiment of the present application.
在一些实施例中,电子设备在得到目标头发掩膜后,可根据目标头发掩膜对原始人物图像的背景区域进行虚化处理,得到目标人物图像。可根据目标头发掩膜确定原始人物图像的头发区域,从而可准确确定人像区域,并实现人像区域与背景区域的分离。可对分离后的背景区域进行虚化处理,再将虚化处理后的背景区域与人像区域进行拼接,得到目标人物图像,对背景区域进行虚化处理后,人像区域可得到突出。由于目标头发掩膜细致、准确地定位了头发区域,能够实现发丝级的人像区域与背景区域的分离,提高了前景与背景分离的准确性,使得虚化处理后得到的目标人物图像更加自然,提高了图像的背景虚化效果。In some embodiments, after obtaining the target hair mask, the electronic device may blur the background area of the original person image according to the target hair mask to obtain the target person image. The hair area of the original person image can be determined according to the target hair mask, so that the image area can be accurately determined and the separation of the image area and the background area can be realized. The separated background area can be blurred, and then the blurred background area and the portrait area can be spliced to obtain the target person image. After the background area is blurred, the portrait area can be highlighted. Because the target hair mask carefully and accurately locates the hair area, it can realize the separation of the hair-level portrait area and the background area, improve the accuracy of the separation of the foreground and the background, and make the image of the target person obtained after the blurring process more natural , which improves the bokeh effect of the image.
在本申请实施例中,在得到感兴趣区域图像及对应的区域分割图像后,可通过图像处理模型生成第一头发掩膜,并对图像处理模型输出的第一头发掩膜进行优化、修正,得到更加精细、准确的第二头发掩膜,再对第二头发掩膜进行上采样滤波,以得到更高分辨率的目标头发掩膜,使得目标头发掩膜的精细度及准确度更高。利用该目标头发掩膜可准确定位原始人物图像中的头发区域,从而可提高后续对原始人物图像进行前景、背景分离等图像处理时的图像处理效果。In the embodiment of the present application, after obtaining the image of the region of interest and the corresponding region segmentation image, the first hair mask can be generated through the image processing model, and the first hair mask output by the image processing model can be optimized and corrected. Obtain a more refined and accurate second hair mask, and then perform upsampling filtering on the second hair mask to obtain a higher-resolution target hair mask, so that the fineness and accuracy of the target hair mask are higher. The target hair mask can be used to accurately locate the hair region in the original person image, thereby improving the image processing effect of subsequent image processing such as foreground and background separation on the original person image.
如图14所示,在一个实施例中,提供一种图像处理装置1400,可应用于上述的电子设备。该图像处理装置1400可包括预处理模块1410、掩膜生成模块1420及优化模块1430。As shown in FIG. 14 , in one embodiment, an image processing apparatus 1400 is provided, which can be applied to the above-mentioned electronic equipment. The image processing device 1400 may include a preprocessing module 1410 , a mask generation module 1420 and an optimization module 1430 .
预处理模块1410,用于对原始人物图像进行预处理,得到原始人物图像的感兴趣区域图像,以及与感兴趣区域图像对应的区域分割图像,区域分割图像包括感兴趣区域图像的人像区域信息。The preprocessing module 1410 is configured to preprocess the original person image to obtain an ROI image of the original person image and a region segmentation image corresponding to the ROI image, where the region segmentation image includes portrait region information of the ROI image.
掩膜生成模块1420,用于根据感兴趣区域图像及区域分割图像生成第一头发掩膜。The mask generation module 1420 is configured to generate a first hair mask according to the ROI image and the region segmentation image.
优化模块1430,用于对第一头发掩膜进行优化处理,以得到原始人物图对应的目标头发掩膜。The optimization module 1430 is configured to optimize the first hair mask to obtain a target hair mask corresponding to the original character image.
在本申请实施例中,通过对原始人物图像进行预处理,得到原始人物图像的感兴趣区域图像,以及与该感兴趣区域图像对应的区域分割图像,根据该感兴趣区域图像及区域分割图像生成第一头发掩膜,并对第一头发掩膜进行优化处理,以得到原始人物图像对应的目标头发掩膜,在生成第一头发掩膜后,还对第一头发掩膜进行优化、修正,得到了更加精细、准确的目标头发掩膜,利用该目标头发掩膜可准确定位原始人物图像中的头发区域,从而可提高后续对原始人物图像进行前景、背景分离等图像处理时的图像处理效果。In the embodiment of the present application, by preprocessing the original person image, the ROI image of the original person image and the region segmentation image corresponding to the ROI image are obtained, and the ROI image and the region segmentation image are generated according to the ROI image and the region segmentation image. the first hair mask, and optimize the first hair mask to obtain the target hair mask corresponding to the original character image, after generating the first hair mask, optimize and correct the first hair mask, A finer and more accurate target hair mask is obtained, which can be used to accurately locate the hair region in the original person image, thereby improving the image processing effect of subsequent image processing such as foreground and background separation on the original person image .
在一个实施例中,预处理模块1410,包括确定单元及裁剪单元。In one embodiment, the preprocessing module 1410 includes a determining unit and a cropping unit.
确定单元,用于根据原始人物图像,以及与原始人物图像对应的人像分割图像,确定原始人物图像中的抠图感兴趣区域,人像分割图像为对原始人物图像进行人像提取后得到的图像,人像分割图像包括原始人物图像的人像区域信息。The determination unit is configured to determine the matting region of interest in the original person image according to the original person image and the portrait segmentation image corresponding to the original person image, the portrait segmentation image is an image obtained after portrait extraction from the original person image, and the portrait The segmented image includes portrait region information of the original person image.
在一个实施例中,确定单元,还用于获取原始人物图像对应的头发分割图像,并根据头发分割图像及人像分割图像计算得到头发轮廓线,以及根据头发轮廓线确定原始人物图像中的抠图感兴趣区域。其中,头发分割图像为对原始人物图像进行头发分割后得到的图像,头发分割图像包括原始人物图像的头发区域信息。In one embodiment, the determination unit is further configured to obtain the hair segmentation image corresponding to the original person image, calculate the hair contour line according to the hair segmentation image and the portrait segmentation image, and determine the cutout in the original person image according to the hair contour line area of interest. Wherein, the hair segmentation image is an image obtained by performing hair segmentation on the original person image, and the hair segmentation image includes hair region information of the original person image.
在一个实施例中,确定单元,还用于确定原始人物图像中的人脸区域,并根据人脸区域得到初始感兴趣区域,将头发轮廓线分别在原始人物图像的横坐标轴及纵坐标轴进行投影,得到头发轮廓线在横坐 标轴的第一投影分布及在纵坐标轴的第二投影分布,以及根据第一投影分布及第二投影分布对初始感兴趣区域进行修正,得到抠图感兴趣区域。In one embodiment, the determining unit is further configured to determine the face area in the original person image, and obtain an initial region of interest according to the face area, and place the hair contour line on the abscissa axis and the ordinate axis of the original person image respectively. Perform projection to obtain the first projection distribution of the hair contour on the abscissa axis and the second projection distribution on the ordinate axis, and correct the initial region of interest according to the first projection distribution and the second projection distribution to obtain a sense of matting area of interest.
在一个实施例中,预处理模块1410,还包括校正单元。In one embodiment, the preprocessing module 1410 further includes a correction unit.
校正单元,用于若原始人物图像为经过旋转的图像,则分别对原始人物图像及与原始人物图像对应的人像分割图像进行校正。The correcting unit is configured to correct the original character image and the segmented portrait image corresponding to the original character image if the original character image is a rotated image.
确定单元,还用于根据校正后的原始人物图像及校正后的人像分割图像,确定校正后的抠图感兴趣区域,并按照未校正的原始人物图像的旋转方向,对校正后的抠图感兴趣区域进行旋转,得到未校正的原始人物图像中的抠图感兴趣区域。The determination unit is also used to determine the corrected matting region of interest according to the corrected original character image and the corrected portrait segmentation image, and to adjust the corrected matting sense according to the rotation direction of the uncorrected original character image. The region of interest is rotated to obtain the matted region of interest in the uncorrected original person image.
裁剪单元,用于根据抠图感兴趣区域分别对原始人物图像及人像分割图像进行裁剪,得到感兴趣区域图像以及与感兴趣区域图像对应的区域分割图像。The cropping unit is configured to respectively crop the original person image and the segmented portrait image according to the region of interest in the cutout, to obtain the region of interest image and the region segmentation image corresponding to the region of interest image.
在本申请实施例中,在原始人物图像的预处理阶段,先确定原始人物图像的抠图感兴趣区域,并基于该抠图感兴趣区域对原始人物图像及人像分割图像进行裁剪,以得到后续用于生成头发掩膜的感兴趣区域图像及区域分割图像,可提高后续生成的头发掩膜的准确性,且不需要整张图像参考生成头发掩膜的过程,可减少计算量,提高图像处理效率。In the embodiment of the present application, in the preprocessing stage of the original person image, the matting region of interest of the original person image is firstly determined, and based on the matting region of interest, the original person image and the segmented portrait image are cropped to obtain the subsequent The image of the region of interest and the region segmentation image used to generate the hair mask can improve the accuracy of the subsequently generated hair mask, and does not require the entire image to refer to the process of generating the hair mask, which can reduce the amount of calculation and improve image processing efficiency.
在一个实施例中,掩膜生成模块1420,还用于将感兴趣区域图像及区域分割图像输入图像处理模型,通过图像处理模型对感兴趣区域图像及区域分割图像进行处理,得到第一头发掩膜,其中,图像处理模型是根据多组样本训练图像进行训练得到的,每一组样本训练图像包括样本人物图像、与样本人物图像对应的样本人像分割图像及样本头发掩膜。In one embodiment, the mask generation module 1420 is further configured to input the region-of-interest image and the region-segmented image into the image processing model, and process the region-of-interest image and the region-segmented image through the image processing model to obtain the first hair mask The image processing model is obtained by training according to multiple sets of sample training images, and each set of sample training images includes a sample person image, a sample portrait segmentation image corresponding to the sample person image, and a sample hair mask.
在一个实施例中,样本头发掩膜是根据样本人物图像对应的背景复杂度图像进行腐蚀处理后得到的。In one embodiment, the sample hair mask is obtained by performing erosion processing on the background complexity image corresponding to the sample person image.
在一个实施例中,优化模块1430,包括优化子模块及滤波子模块。In one embodiment, the optimization module 1430 includes an optimization sub-module and a filtering sub-module.
优化子模块,用于对第一头发掩膜进行优化处理,以得到第二头发掩膜。The optimization sub-module is used to optimize the first hair mask to obtain the second hair mask.
滤波子模块,用于对第二头发掩膜进行上采样滤波处理,得到原始人物图像对应的目标头发掩膜。The filtering sub-module is configured to perform upsampling and filtering on the second hair mask to obtain a target hair mask corresponding to the original person image.
在一个实施例中,优化子模块,可包括腐蚀单元、填充单元、增强单元、柔化单元中的一种或多种。In an embodiment, the optimization sub-module may include one or more of an erosion unit, a filling unit, an enhancement unit, and a softening unit.
腐蚀单元,用于计算感兴趣区域图像对应的背景复杂度图像,并根据背景复杂度图像对第一头发掩膜进行腐蚀处理,得到第二头发掩膜。The erosion unit is configured to calculate a background complexity image corresponding to the region of interest image, and perform erosion processing on the first hair mask according to the background complexity image to obtain a second hair mask.
在一个实施例中,腐蚀单元,还用于获取感兴趣区域图像的灰度图像,对灰度图像进行边缘检测,得到第一边缘图像,并根据第一头发掩膜去除第一边缘图像中的头发边缘,得到第二边缘图像,以及对第二边缘图像进行膨胀处理及模糊处理,以得到背景复杂度图像。In one embodiment, the erosion unit is further configured to acquire a grayscale image of the region of interest image, perform edge detection on the grayscale image to obtain a first edge image, and remove the grayscale image in the first edge image according to the first hair mask The hair edge is obtained by obtaining a second edge image, and the second edge image is expanded and blurred to obtain a background complexity image.
在一个实施例中,腐蚀单元,还用于根据背景复杂度图像,确定第一头发掩膜中复杂度大于复杂度阈值的背景复杂区域,对第一头发掩膜中处于背景复杂区域周围的头发区域进行腐蚀处理,并将腐蚀处理前的第一头发掩膜与腐蚀处理后的第一头发掩膜进行融合,得到第二头发掩膜。In one embodiment, the corrosion unit is further configured to determine, according to the background complexity image, a complex background area in the first hair mask whose complexity is greater than a complexity threshold, and to perform a calculation on the hairs around the complex background area in the first hair mask. Erosion processing is performed on the region, and the first hair mask before the etching processing is fused with the first hair mask after the etching processing to obtain a second hair mask.
填充单元,用于对第一头发掩膜的头发区域中的孔洞进行填充,得到第二头发掩膜。The filling unit is configured to fill holes in the hair region of the first hair mask to obtain a second hair mask.
增强单元,用于对第一头发掩膜的头发区域的边缘进行增强处理,得到第二头发掩膜。The enhancement unit is configured to perform enhancement processing on edges of the hair region of the first hair mask to obtain a second hair mask.
柔化单元,用于若原始人物图像对应的图像场景为目标场景,则对第一头发掩膜的头发区域的边缘进行柔化处理,得到第二头发掩膜,目标场景为场景亮度值低于亮度阈值的场景。The softening unit is used to soften the edge of the hair region of the first hair mask if the image scene corresponding to the original character image is the target scene to obtain the second hair mask. The target scene is that the scene brightness value is lower than The brightness threshold of the scene.
在一个实施例中,柔化单元,还用于获取原始人物图像对应的感光值,若感光值大于感光阈值,则确定原始人物图像对应的图像场景为目标场景,并对第一头发掩膜的头发区域的边缘进行柔化处理,得到第二头发掩膜。In one embodiment, the softening unit is further configured to acquire the photosensitive value corresponding to the original person image, and if the photosensitive value is greater than the photosensitive threshold, then determine that the image scene corresponding to the original person image is the target scene, and apply the first hair mask The edges of the hair area are softened to get the second hair mask.
在一个实施例中,优化模块1430,还用于通过腐蚀单元计算感兴趣区域图像对应的背景复杂度图像,并根据背景复杂度图像对第一头发掩膜进行腐蚀处理,再通过填充单元对腐蚀处理后的第一头发掩膜的头发区域中的孔洞进行填充,然后通过增加单元对填充后的第一头发掩膜的头发区域的边缘进行增强处理,以及用于若通过柔化单元确定原始人物图像对应的图像场景为目标场景,则对增强处理后的第一头发掩膜的头发区域的边缘进行柔化处理,以得到第二头发掩膜,若原始人物图像对应的图像场景不为目标场景,则将增强处理后的第一头发掩膜作为第二头发掩膜。In one embodiment, the optimization module 1430 is also used to calculate the background complexity image corresponding to the image of the region of interest through the erosion unit, and perform erosion processing on the first hair mask according to the background complexity image, and then perform erosion processing on the first hair mask through the filling unit. The holes in the hair region of the processed first hair mask are filled, and then the edge of the hair region of the filled first hair mask is enhanced by increasing the unit, and used to determine the original character if the original character is determined by the softening unit The image scene corresponding to the image is the target scene, then the edge of the hair region of the enhanced first hair mask is softened to obtain the second hair mask, if the image scene corresponding to the original person image is not the target scene , the enhanced first hair mask is used as the second hair mask.
在一个实施例中,滤波子模块,还用于将感兴趣区域图像的灰度图像作为引导滤波器的引导图像,通过引导滤波器对第二头发掩膜进行上采样滤波处理,得到原始人物图像对应的目标头发掩膜。In one embodiment, the filtering sub-module is further configured to use the grayscale image of the region of interest image as the guiding image of the guiding filter, and perform upsampling and filtering processing on the second hair mask through the guiding filter to obtain the original person image The corresponding target hair mask.
在一个实施例中,滤波子模块,还用于根据感兴趣区域图像对应的背景复杂度图像对第二头发掩膜进行区域划分,得到背景简单区域及背景复杂区域,将感兴趣区域图像的灰度图像作为引导滤波器的引导图像,通过引导滤波器对第二头发掩膜中处于背景简单区域周围的头发区域进行上采样滤波处理,得到第一滤波结果,并采用双线性插值算法对第二头发掩膜中处于背景复杂区域周围的头发区域进行上采 样滤波处理,得到第二滤波结果,然后将第一滤波结果及第二滤波结果进行融合,得到目标头发掩膜。其中,背景简单区域为复杂度低于或等于复杂度阈值的背景区域,背景复杂区域为复杂度高于复杂度阈值的背景区域。In one embodiment, the filtering sub-module is further configured to divide the second hair mask according to the background complexity image corresponding to the region of interest image to obtain simple background regions and complex background regions, and convert the gray area of the region of interest image to The degree image is used as the guide image of the guide filter, and the hair region around the simple background area in the second hair mask is upsampled and filtered by the guide filter to obtain the first filtering result, and the second hair mask is processed by bilinear interpolation algorithm In the second hair mask, the hair region around the complex background region is subjected to upsampling and filtering processing to obtain a second filtering result, and then the first filtering result and the second filtering result are fused to obtain a target hair mask. Wherein, the background simple area is the background area whose complexity is lower than or equal to the complexity threshold, and the background complex area is the background area whose complexity is higher than the complexity threshold.
在一个实施例中,上述图像处理装置1400,除了包括预处理模块1410、掩膜生成模块1420、优化模块1430,还包括虚化模块。In one embodiment, the above-mentioned image processing apparatus 1400 includes a blurring module in addition to the preprocessing module 1410 , the mask generation module 1420 and the optimization module 1430 .
虚化模块,用于根据目标头发掩膜对原始人物图像的背景区域进行虚化处理,得到目标人物图像。The blurring module is configured to blur the background area of the original character image according to the target hair mask to obtain the target character image.
在本申请实施例中,在得到感兴趣区域图像及对应的区域分割图像后,可通过图像处理模型生成第一头发掩膜,并对图像处理模型输出的第一头发掩膜进行优化、修正,得到更加精细、准确的第二头发掩膜,再对第二头发掩膜进行上采样滤波,以得到更高分辨率的目标头发掩膜,使得目标头发掩膜的精细度及准确度更高。利用该目标头发掩膜可准确定位原始人物图像中的头发区域,从而可提高后续对原始人物图像进行前景、背景分离等图像处理时的图像处理效果。In the embodiment of the present application, after obtaining the image of the region of interest and the corresponding region segmentation image, the first hair mask can be generated through the image processing model, and the first hair mask output by the image processing model can be optimized and corrected. Obtain a more refined and accurate second hair mask, and then perform upsampling filtering on the second hair mask to obtain a higher-resolution target hair mask, so that the fineness and accuracy of the target hair mask are higher. The target hair mask can be used to accurately locate the hair region in the original person image, thereby improving the image processing effect of subsequent image processing such as foreground and background separation on the original person image.
图15为一个实施例中电子设备的结构框图。如图15所示,电子设备1500可以包括一个或多个如下部件:处理器1510、与处理器1510耦合的存储器1520,其中存储器1520可存储有一个或多个计算机程序,一个或多个计算机程序可以被配置为由一个或多个处理器1510执行时实现如上述各实施例描述的方法。Fig. 15 is a structural block diagram of an electronic device in one embodiment. As shown in FIG. 15 , an electronic device 1500 may include one or more of the following components: a processor 1510, a memory 1520 coupled to the processor 1510, wherein the memory 1520 may store one or more computer programs, one or more computer programs It may be configured to implement the methods described in the foregoing embodiments when executed by one or more processors 1510 .
处理器1510可以包括一个或者多个处理核。处理器1510利用各种接口和线路连接整个电子设备1500内的各个部分,通过运行或执行存储在存储器1520内的指令、程序、代码集或指令集,以及调用存储在存储器1520内的数据,执行电子设备1500的各种功能和处理数据。可选地,处理器1510可以采用数字信号处理(Digital Signal Processing,DSP)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)、可编程逻辑阵列(Programmable Logic Array,PLA)中的至少一种硬件形式来实现。处理器1510可集成中央处理器(Central Processing Unit,CPU)、图像处理器(Graphics Processing Unit,GPU)和调制解调器等中的一种或几种的组合。其中,CPU主要处理操作系统、用户界面和应用程序等;GPU用于负责显示内容的渲染和绘制;调制解调器用于处理无线通信。可以理解的是,上述调制解调器也可以不集成到处理器1510中,单独通过一块通信芯片进行实现。 Processor 1510 may include one or more processing cores. The processor 1510 uses various interfaces and circuits to connect various parts of the entire electronic device 1500, and executes or executes instructions, programs, code sets or instruction sets stored in the memory 1520, and calls data stored in the memory 1520 to execute Various functions of the electronic device 1500 and processing data. Optionally, the processor 1510 may adopt at least one of Digital Signal Processing (Digital Signal Processing, DSP), Field-Programmable Gate Array (Field-Programmable Gate Array, FPGA), and Programmable Logic Array (Programmable Logic Array, PLA). implemented in the form of hardware. The processor 1510 may integrate one or a combination of a central processing unit (Central Processing Unit, CPU), an image processor (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly handles the operating system, user interface and application programs, etc.; the GPU is used to render and draw the displayed content; the modem is used to handle wireless communication. It can be understood that, the above-mentioned modem may not be integrated into the processor 1510, but may be realized by a communication chip alone.
存储器1520可以包括随机存储器(Random Access Memory,RAM),也可以包括只读存储器(Read-Only Memory,ROM)。存储器1520可用于存储指令、程序、代码、代码集或指令集。存储器1520可包括存储程序区和存储数据区,其中,存储程序区可存储用于实现操作系统的指令、用于实现至少一个功能的指令(比如触控功能、声音播放功能、图像播放功能等)、用于实现上述各个方法实施例的指令等。存储数据区还可以存储电子设备1500在使用中所创建的数据等。The memory 1520 may include random access memory (Random Access Memory, RAM), and may also include read-only memory (Read-Only Memory, ROM). The memory 1520 may be used to store instructions, programs, codes, sets of codes or sets of instructions. The memory 1520 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system and instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.) , instructions for implementing the foregoing method embodiments, and the like. The storage data area can also store data created by the electronic device 1500 during use, and the like.
可以理解地,电子设备1500可包括比上述结构框图中更多或更少的结构元件,例如,包括电源模块、物理按键、WiFi(Wireless Fidelity,无线保真)模块、扬声器、蓝牙模块、传感器等,还可在此不进行限定。It can be understood that the electronic device 1500 may include more or fewer structural elements than those in the above structural block diagram, for example, including a power module, a physical button, a WiFi (Wireless Fidelity, wireless fidelity) module, a speaker, a Bluetooth module, a sensor, etc. , and may not be limited here.
本申请实施例公开一种计算机可读存储介质,其存储计算机程序,其中,该计算机程序被处理器执行时实现如上述实施例描述的方法。The embodiment of the present application discloses a computer-readable storage medium, which stores a computer program, wherein, when the computer program is executed by a processor, the methods described in the above-mentioned embodiments are implemented.
本申请实施例公开一种计算机程序产品,该计算机程序产品包括存储了计算机程序的非瞬时性计算机可读存储介质,且该计算机程序可被处理器执行时实现如上述各实施例描述的方法。The embodiment of the present application discloses a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program can be executed by a processor to implement the methods described in the foregoing embodiments.
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的程序可存储于一非易失性计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中,所述的存储介质可为磁碟、光盘、ROM等。Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be realized through computer programs to instruct related hardware, and the programs can be stored in a non-volatile computer-readable storage medium When the program is executed, it may include the processes of the embodiments of the above-mentioned methods. Wherein, the storage medium may be a magnetic disk, an optical disk, a ROM, or the like.
如此处所使用的对存储器、存储、数据库或其它介质的任何引用可包括非易失性和/或易失性存储器。合适的非易失性存储器可包括ROM、可编程ROM(Programmable ROM,PROM)、可擦除PROM(Erasable PROM,EPROM)、电可擦除PROM(Electrically Erasable PROM,EEPROM)或闪存。易失性存储器可包括随机存取存储器(random access memory,RAM),它用作外部高速缓冲存储器。作为说明而非局限,RAM可为多种形式,诸如静态RAM(Static RAM,SRAM)、动态RAM(Dynamic Random Access Memory,DRAM)、同步DRAM(synchronous DRAM,SDRAM)、双倍数据率SDRAM(Double Data Rate SDRAM,DDR SDRAM)、增强型SDRAM(Enhanced Synchronous DRAM,ESDRAM)、同步链路DRAM(Synchlink DRAM,SLDRAM)、存储器总线直接RAM(Rambus DRAM,RDRAM)及直接存储器总线动态RAM(Direct Rambus DRAM,DRDRAM)。Any reference to memory, storage, database or other medium as used herein may include non-volatile and/or volatile memory. Suitable non-volatile memory may include ROM, Programmable ROM (PROM), Erasable PROM (Erasable PROM, EPROM), Electrically Erasable PROM (Electrically Erasable PROM, EEPROM) or flash memory. Volatile memory can include random access memory (RAM), which acts as external cache memory. By way of illustration and not limitation, RAM can take many forms, such as static RAM (Static RAM, SRAM), dynamic RAM (Dynamic Random Access Memory, DRAM), synchronous DRAM (synchronous DRAM, SDRAM), double data rate SDRAM (Double Data Rate) Data Rate SDRAM, DDR SDRAM), enhanced SDRAM (Enhanced Synchronous DRAM, ESDRAM), synchronous link DRAM (Synchlink DRAM, SLDRAM), memory bus direct RAM (Rambus DRAM, RDRAM) and direct memory bus dynamic RAM (Direct Rambus DRAM) , DRDRAM).
应理解,说明书通篇中提到的“一个实施例”或“一实施例”意味着与实施例有关的特定特征、结 构或特性包括在本申请的至少一个实施例中。因此,在整个说明书各处出现的“在一个实施例中”或“在一实施例中”未必一定指相同的实施例。此外,这些特定特征、结构或特性可以以任意适合的方式结合在一个或多个实施例中。本领域技术人员也应该知悉,说明书中所描述的实施例均属于可选实施例,所涉及的动作和模块并不一定是本申请所必须的。It should be understood that reference throughout this specification to "one embodiment" or "an embodiment" means that a particular feature, structure, or characteristic related to the embodiment is included in at least one embodiment of the present application. Thus, appearances of "in one embodiment" or "in an embodiment" in various places throughout the specification are not necessarily referring to the same embodiment. Furthermore, the particular features, structures or characteristics may be combined in any suitable manner in one or more embodiments. Those skilled in the art should also know that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by this application.
在本申请的各种实施例中,应理解,上述各过程的序号的大小并不意味着执行顺序的必然先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。In various embodiments of the present application, it should be understood that the sequence numbers of the above-mentioned processes do not necessarily mean the order of execution. The implementation of the examples constitutes no limitation.
上述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可位于一个地方,或者也可以分布到多个网络单元上。可根据实际的需要选择其中的部分或全部单元来实现本实施例方案的目的。The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, located in one place, or distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
另外,在本申请各实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.
以上对本申请实施例公开的一种图像处理方法、装置、电子设备及计算机可读存储介质进行了详细介绍,本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想。同时,对于本领域的一般技术人员,依据本申请的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本申请的限制。An image processing method, device, electronic device, and computer-readable storage medium disclosed in the embodiments of the present application have been described above in detail. In this paper, specific examples are used to illustrate the principles and implementation methods of the present application. The above embodiments The description is only used to help understand the method and core idea of the present application. At the same time, for those skilled in the art, based on the idea of this application, there will be changes in the specific implementation and application scope. In summary, the content of this specification should not be construed as limiting the application.

Claims (58)

  1. 一种图像处理方法,其特征在于,包括:An image processing method, characterized in that, comprising:
    对原始人物图像进行预处理,得到所述原始人物图像的感兴趣区域图像,以及与所述感兴趣区域图像对应的区域分割图像,所述区域分割图像包括所述感兴趣区域图像的人像区域信息;Preprocessing the original person image to obtain a region of interest image of the original person image, and a region segmentation image corresponding to the region of interest image, where the region segmentation image includes portrait region information of the region of interest image ;
    根据所述感兴趣区域图像及所述区域分割图像生成第一头发掩膜;generating a first hair mask according to the region-of-interest image and the region-segmented image;
    对所述第一头发掩膜进行优化处理,以得到所述原始人物图像对应的目标头发掩膜。Optimizing the first hair mask to obtain a target hair mask corresponding to the original person image.
  2. 根据权利要求1所述的方法,其特征在于,所述对原始人物图像进行预处理,得到所述原始人物图像的感兴趣区域图像,以及与所述感兴趣区域图像对应的区域分割图像,包括:The method according to claim 1, wherein the preprocessing of the original person image to obtain the region of interest image of the original person image and the region segmentation image corresponding to the region of interest image includes :
    根据原始人物图像,以及与所述原始人物图像对应的人像分割图像,确定所述原始人物图像中的抠图感兴趣区域,所述人像分割图像为对所述原始人物图像进行人像提取后得到的图像,所述人像分割图像包括所述原始人物图像的人像区域信息;According to the original person image, and the portrait segmentation image corresponding to the original person image, determine the matting region of interest in the original person image, and the portrait segmentation image is obtained after portrait extraction is performed on the original person image image, the portrait segmentation image includes the portrait area information of the original person image;
    根据所述抠图感兴趣区域分别对所述原始人物图像及人像分割图像进行裁剪,得到感兴趣区域图像以及与所述感兴趣区域图像对应的区域分割图像。The original person image and the segmented portrait image are clipped respectively according to the cutout region of interest to obtain a region of interest image and a region segmentation image corresponding to the region of interest image.
  3. 根据权利要求2所述的方法,其特征在于,所述根据原始人物图像,以及与所述原始人物图像对应的人像分割图像,确定所述原始人物图像中的抠图感兴趣区域,包括:The method according to claim 2, characterized in that, according to the original person image, and the portrait segmentation image corresponding to the original person image, determining the matting region of interest in the original person image includes:
    获取所述原始人物图像对应的头发分割图像,所述头发分割图像为对所述原始人物图像进行头发分割后得到的图像,所述头发分割图像包括所述原始人物图像的头发区域信息;Acquiring a hair segmentation image corresponding to the original person image, the hair segmentation image is an image obtained by performing hair segmentation on the original person image, and the hair segmentation image includes hair region information of the original person image;
    根据所述头发分割图像及所述人像分割图像计算得到头发轮廓线;calculating hair contour lines according to the hair segmentation image and the portrait segmentation image;
    根据所述头发轮廓线确定所述原始人物图像中的抠图感兴趣区域。A matting region of interest in the original person image is determined according to the hair contour line.
  4. 根据权利要求3所述的方法,其特征在于,所述根据所述头发轮廓线确定所述原始人物图像中的抠图感兴趣区域,包括:The method according to claim 3, wherein said determining the matting region of interest in the original person image according to the hair contour line comprises:
    确定所述原始人物图像中的人脸区域,并根据所述人脸区域得到初始感兴趣区域;Determining the face area in the original person image, and obtaining an initial region of interest according to the face area;
    将所述头发轮廓线分别在所述原始人物图像的横坐标轴及纵坐标轴进行投影,得到所述头发轮廓线在所述横坐标轴的第一投影分布及在所述纵坐标轴的第二投影分布;Project the hair contour line on the abscissa axis and the ordinate axis of the original character image respectively, to obtain the first projection distribution of the hair contour line on the abscissa axis and the first projected distribution on the ordinate axis. Two-projection distribution;
    根据所述第一投影分布及第二投影分布对所述初始感兴趣区域进行修正,得到抠图感兴趣区域。The initial region of interest is corrected according to the first projection distribution and the second projection distribution to obtain a matted region of interest.
  5. 根据权利要求2~4任一所述的方法,其特征在于,在所述根据原始人物图像,以及与所述原始人物图像对应的人像分割图像,确定所述原始人物图像中的抠图感兴趣区域之前,所述方法还包括:The method according to any one of claims 2 to 4, characterized in that, according to the original character image and the segmented image corresponding to the original character image, it is determined that the cutout in the original character image is of interest Before the region, the method also includes:
    若原始人物图像为经过旋转的图像,则分别对所述原始人物图像及与所述原始人物图像对应的人像分割图像进行校正;If the original character image is a rotated image, correcting the original character image and the segmented portrait image corresponding to the original character image;
    所述在所述根据原始人物图像,以及与所述原始人物图像对应的人像分割图像,确定所述原始人物图像中的抠图感兴趣区域,包括:The determining the region of interest in matting in the original character image according to the original character image and the segmented portrait image corresponding to the original character image includes:
    根据校正后的原始人物图像及校正后的人像分割图像,确定校正后的抠图感兴趣区域;Determine the corrected matting region of interest according to the corrected original person image and the corrected portrait segmentation image;
    按照未校正的原始人物图像的旋转方向,对所述校正后的抠图感兴趣区域进行旋转,得到所述未校正的原始人物图像中的抠图感兴趣区域。The corrected matting region of interest is rotated according to the rotation direction of the uncorrected original person image to obtain the matting region of interest in the uncorrected original person image.
  6. 根据权利要求1所述的方法,其特征在于,所述对所述第一头发掩膜进行优化处理,以得到所述原始人物图像对应的目标头发掩膜,包括:The method according to claim 1, wherein said optimizing the first hair mask to obtain the target hair mask corresponding to the original character image comprises:
    对所述第一头发掩膜进行优化处理,得到第二头发掩膜;Optimizing the first hair mask to obtain a second hair mask;
    对所述第二头发掩膜进行上采样滤波处理,得到所述原始人物图像对应的目标头发掩膜。Perform upsampling and filtering processing on the second hair mask to obtain a target hair mask corresponding to the original person image.
  7. 根据权利要求6所述的方法,其特征在于,所述对所述第一头发掩膜进行优化处理,得到第二头发掩膜,包括:The method according to claim 6, wherein said optimizing said first hair mask to obtain a second hair mask comprises:
    计算所述感兴趣区域图像对应的背景复杂度图像;Calculating the background complexity image corresponding to the ROI image;
    根据所述背景复杂度图像对所述第一头发掩膜进行腐蚀处理,得到第二头发掩膜。Erosion processing is performed on the first hair mask according to the background complexity image to obtain a second hair mask.
  8. 根据权利要求7所述的方法,其特征在于,所述计算所述感兴趣区域图像对应的背景复杂度图像,包括:The method according to claim 7, wherein the calculating the background complexity image corresponding to the ROI image comprises:
    获取所述感兴趣区域图像的灰度图像;Acquiring a grayscale image of the image of the region of interest;
    对所述灰度图像进行边缘检测,得到第一边缘图像;performing edge detection on the grayscale image to obtain a first edge image;
    根据所述第一头发掩膜去除所述第一边缘图像中的头发边缘,得到第二边缘图像;removing hair edges in the first edge image according to the first hair mask to obtain a second edge image;
    对所述第二边缘图像进行膨胀处理及模糊处理,以得到背景复杂度图像。Dilation and blurring are performed on the second edge image to obtain a background complexity image.
  9. 根据权利要求7所述的方法,其特征在于,所述根据所述背景复杂度图像对所述第一头发掩膜进行腐蚀处理,得到第二头发掩膜,包括:The method according to claim 7, wherein said first hair mask is corroded according to said background complexity image to obtain a second hair mask, comprising:
    根据所述背景复杂度图像,确定所述第一头发掩膜中复杂度大于复杂度阈值的背景复杂区域;According to the background complexity image, determine a background complex area in the first hair mask whose complexity is greater than a complexity threshold;
    对所述第一头发掩膜中处于所述背景复杂区域周围的头发区域进行腐蚀处理;Erosion processing is performed on the hair area around the background complex area in the first hair mask;
    将腐蚀处理前的第一头发掩膜与腐蚀处理后的第一头发掩膜进行融合,得到第二头发掩膜。The first hair mask before the corrosion treatment is fused with the first hair mask after the corrosion treatment to obtain a second hair mask.
  10. 根据权利要求6所述的方法,其特征在于,所述对所述第一头发掩膜进行优化处理,得到第二头发掩膜,包括:The method according to claim 6, wherein said optimizing said first hair mask to obtain a second hair mask comprises:
    对所述第一头发掩膜的头发区域中的孔洞进行填充,得到第二头发掩膜。Filling holes in the hair region of the first hair mask to obtain a second hair mask.
  11. 根据权利要求6所述的方法,其特征在于,所述对所述第一头发掩膜进行优化处理,得到第二头发掩膜,包括:The method according to claim 6, wherein said optimizing said first hair mask to obtain a second hair mask comprises:
    对所述第一头发掩膜的头发区域的边缘进行增强处理,得到第二头发掩膜。The edge of the hair region of the first hair mask is enhanced to obtain a second hair mask.
  12. 根据权利要求6所述的方法,其特征在于,所述对所述第一头发掩膜进行优化处理,得到第二头发掩膜,包括:The method according to claim 6, wherein said optimizing said first hair mask to obtain a second hair mask comprises:
    若所述原始人物图像对应的图像场景为目标场景,则对所述第一头发掩膜的头发区域的边缘进行柔化处理,得到第二头发掩膜,所述目标场景为场景亮度值低于亮度阈值的场景。If the image scene corresponding to the original character image is the target scene, soften the edges of the hair region of the first hair mask to obtain a second hair mask, and the target scene is a scene whose brightness value is lower than The brightness threshold of the scene.
  13. 根据权利要求12所述的方法,其特征在于,在所述若所述原始人物图像对应的图像场景为目标场景,则对所述第一头发掩膜的头发区域的边缘进行模糊处理之前,所述方法还包括:The method according to claim 12, wherein if the image scene corresponding to the original person image is the target scene, before blurring the edge of the hair region of the first hair mask, the The method also includes:
    获取所述原始人物图像对应的感光值;Acquiring the photosensitive value corresponding to the original person image;
    若所述感光值大于感光阈值,则确定所述原始人物图像对应的图像场景为目标场景。If the light-sensing value is greater than the light-sensing threshold, it is determined that the image scene corresponding to the original person image is the target scene.
  14. 根据权利要求6所述的方法,其特征在于,所述对所述第一头发掩膜进行优化处理,得到第二头发掩膜,包括:The method according to claim 6, wherein said optimizing said first hair mask to obtain a second hair mask comprises:
    计算所述感兴趣区域图像对应的背景复杂度图像;Calculating the background complexity image corresponding to the ROI image;
    根据所述背景复杂度图像对所述第一头发掩膜进行腐蚀处理;performing erosion processing on the first hair mask according to the background complexity image;
    对腐蚀处理后的第一头发掩膜的头发区域中的孔洞进行填充;filling holes in the hair region of the first hair mask after the erosion process;
    对填充后的第一头发掩膜的头发区域的边缘进行增强处理;performing enhancement processing on the edges of the hair region of the filled first hair mask;
    若所述原始人物图像对应的图像场景为目标场景,则对增强处理后的第一头发掩膜的头发区域的边缘进行柔化处理,以得到第二头发掩膜;If the image scene corresponding to the original person image is the target scene, softening the edge of the hair region of the enhanced first hair mask to obtain a second hair mask;
    若所述原始人物图像对应的图像场景不为所述目标场景,则将所述增强处理后的第一头发掩膜作为第二头发掩膜。If the image scene corresponding to the original person image is not the target scene, the enhanced first hair mask is used as the second hair mask.
  15. 根据权利要求6~14任一所述的方法,其特征在于,所述对所述第二头发掩膜进行上采样滤波处理,得到所述原始人物图像对应的目标头发掩膜,包括:The method according to any one of claims 6-14, wherein the upsampling and filtering process on the second hair mask to obtain the target hair mask corresponding to the original person image comprises:
    将所述感兴趣区域图像的灰度图像作为引导滤波器的引导图像,通过所述引导滤波器对所述第二头发掩膜进行上采样滤波处理,得到所述原始人物图像对应的目标头发掩膜。Using the grayscale image of the region of interest image as the guide image of the guide filter, performing upsampling filtering on the second hair mask through the guide filter, to obtain the target hair mask corresponding to the original person image membrane.
  16. 根据权利要求15的方法,其特征在于,在所述将所述感兴趣区域图像的灰度图像作为引导滤波器的引导图像,通过所述引导滤波器对所述第二头发掩膜进行上采样滤波处理之前,所述方法还包括:The method according to claim 15, characterized in that, in the guide image using the grayscale image of the region of interest image as a guide filter, the second hair mask is up-sampled through the guide filter Before the filtering process, the method also includes:
    根据所述感兴趣区域图像对应的背景复杂度图像对所述第二头发掩膜进行区域划分,得到背景简单区域及背景复杂区域,所述背景简单区域为复杂度低于或等于复杂度阈值的背景区域,所述背景复杂区域为复杂度高于所述复杂度阈值的背景区域;According to the background complexity image corresponding to the region of interest image, the second hair mask is divided into regions to obtain a simple background region and a complex background region, and the simple background region is a complexity lower than or equal to a complexity threshold. a background area, the complex background area is a background area whose complexity is higher than the complexity threshold;
    所述将所述感兴趣区域图像的灰度图像作为引导滤波器的引导图像,通过所述引导滤波器对所述第二头发掩膜进行上采样滤波处理,得到所述原始人物图像对应的目标头发掩膜,包括:The grayscale image of the region of interest image is used as the guide image of the guide filter, and the second hair mask is subjected to upsampling filtering through the guide filter to obtain the target corresponding to the original person image Hair masks, including:
    将所述感兴趣区域图像的灰度图像作为引导滤波器的引导图像,通过所述引导滤波器对所述第二头发掩膜中处于所述背景简单区域周围的头发区域进行上采样滤波处理,得到第一滤波结果;Using the grayscale image of the region of interest image as the guide image of the guide filter, performing upsampling filter processing on the hair region around the background simple region in the second hair mask through the guide filter, Obtain the first filtering result;
    采用双线性插值算法对所述第二头发掩膜中处于所述背景复杂区域周围的头发区域进行上采样滤波处理,得到第二滤波结果;Using a bilinear interpolation algorithm to perform upsampling and filtering on the hair area around the complex background area in the second hair mask to obtain a second filtering result;
    将所述第一滤波结果及第二滤波结果进行融合,得到目标头发掩膜。The first filtering result and the second filtering result are fused to obtain a target hair mask.
  17. 根据权利要求1~4、6~14任一所述的方法,其特征在于,所述根据所述感兴趣区域图像及所述区域分割图像生成第一头发掩膜,包括:The method according to any one of claims 1-4, 6-14, wherein said generating a first hair mask according to said region of interest image and said region segmentation image comprises:
    将所述感兴趣区域图像及所述区域分割图像输入图像处理模型,通过所述图像处理模型对所述感兴趣区域图像及所述区域分割图像进行处理,得到第一头发掩膜,其中,所述图像处理模型是根据多组样本训练图像进行训练得到的,每一组样本训练图像包括样本人物图像、与所述样本人物图像对应的样本人像分割图像及样本头发掩膜。Inputting the region-of-interest image and the region-segmented image into an image processing model, and processing the region-of-interest image and the region-segmented image through the image processing model to obtain a first hair mask, wherein the The image processing model is obtained by training according to multiple sets of sample training images, and each set of sample training images includes a sample person image, a sample portrait segmentation image corresponding to the sample person image, and a sample hair mask.
  18. 根据权利要求17所述的方法,其特征在于,所述样本头发掩膜是根据所述样本人物图像对应 的背景复杂度图像进行腐蚀处理后得到的。The method according to claim 17, wherein the sample hair mask is obtained after corrosion processing on the background complexity image corresponding to the sample character image.
  19. 根据权利要求1~4、6~14任一所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 1-4, 6-14, characterized in that the method further comprises:
    根据所述目标头发掩膜对所述原始人物图像的背景区域进行虚化处理,得到目标人物图像。The background area of the original person image is blurred according to the target hair mask to obtain the target person image.
  20. 一种图像处理装置,其特征在于,包括:An image processing device, characterized in that it comprises:
    预处理模块,用于对原始人物图像进行预处理,得到所述原始人物图像的感兴趣区域图像,以及与所述感兴趣区域图像对应的区域分割图像,所述区域分割图像包括所述感兴趣区域图像的人像区域信息;A preprocessing module, configured to preprocess the original person image to obtain an image of a region of interest of the original person image, and a region segmentation image corresponding to the image of the region of interest, the region segmentation image includes the region of interest Portrait area information of the area image;
    掩膜生成模块,用于根据所述感兴趣区域图像及所述区域分割图像生成第一头发掩膜;A mask generating module, configured to generate a first hair mask according to the region-of-interest image and the region-segmented image;
    优化模块,用于对所述第一头发掩膜进行优化处理,以得到所述原始人物图像对应的目标头发掩膜。An optimization module, configured to optimize the first hair mask to obtain a target hair mask corresponding to the original person image.
  21. 一种电子设备,其特征在于,包括存储器及处理器,所述存储器中存储有计算机程序,所述计算机程序被所述处理器执行时,使得所述处理器执行如下步骤:An electronic device, characterized in that it includes a memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the processor is made to perform the following steps:
    对原始人物图像进行预处理,得到所述原始人物图像的感兴趣区域图像,以及与所述感兴趣区域图像对应的区域分割图像,所述区域分割图像包括所述感兴趣区域图像的人像区域信息;Preprocessing the original person image to obtain a region of interest image of the original person image, and a region segmentation image corresponding to the region of interest image, where the region segmentation image includes portrait region information of the region of interest image ;
    根据所述感兴趣区域图像及所述区域分割图像生成第一头发掩膜;generating a first hair mask according to the region-of-interest image and the region-segmented image;
    对所述第一头发掩膜进行优化处理,以得到所述原始人物图像对应的目标头发掩膜。Optimizing the first hair mask to obtain a target hair mask corresponding to the original person image.
  22. 根据权利要求21所述的电子设备,其特征在于,所述对原始人物图像进行预处理,得到所述原始人物图像的感兴趣区域图像,以及与所述感兴趣区域图像对应的区域分割图像,包括:The electronic device according to claim 21, wherein the preprocessing is performed on the original person image to obtain an ROI image of the original person image and a region segmentation image corresponding to the ROI image, include:
    根据原始人物图像,以及与所述原始人物图像对应的人像分割图像,确定所述原始人物图像中的抠图感兴趣区域,所述人像分割图像为对所述原始人物图像进行人像提取后得到的图像,所述人像分割图像包括所述原始人物图像的人像区域信息;According to the original person image, and the portrait segmentation image corresponding to the original person image, determine the matting region of interest in the original person image, and the portrait segmentation image is obtained after portrait extraction is performed on the original person image image, the portrait segmentation image includes the portrait area information of the original person image;
    根据所述抠图感兴趣区域分别对所述原始人物图像及人像分割图像进行裁剪,得到感兴趣区域图像以及与所述感兴趣区域图像对应的区域分割图像。The original person image and the segmented portrait image are clipped respectively according to the cutout region of interest to obtain a region of interest image and a region segmentation image corresponding to the region of interest image.
  23. 根据权利要求22所述的电子设备,其特征在于,所述根据原始人物图像,以及与所述原始人物图像对应的人像分割图像,确定所述原始人物图像中的抠图感兴趣区域,包括:The electronic device according to claim 22, characterized in that, according to the original character image and the segmented portrait image corresponding to the original character image, determining the matting region of interest in the original character image comprises:
    获取所述原始人物图像对应的头发分割图像,所述头发分割图像为对所述原始人物图像进行头发分割后得到的图像,所述头发分割图像包括所述原始人物图像的头发区域信息;Acquiring a hair segmentation image corresponding to the original person image, the hair segmentation image is an image obtained by performing hair segmentation on the original person image, and the hair segmentation image includes hair region information of the original person image;
    根据所述头发分割图像及所述人像分割图像计算得到头发轮廓线;calculating hair contour lines according to the hair segmentation image and the portrait segmentation image;
    根据所述头发轮廓线确定所述原始人物图像中的抠图感兴趣区域。A matting region of interest in the original person image is determined according to the hair contour line.
  24. 根据权利要求23所述的电子设备,其特征在于,所述根据所述头发轮廓线确定所述原始人物图像中的抠图感兴趣区域,包括:The electronic device according to claim 23, wherein the determining the matting region of interest in the original person image according to the hair contour line comprises:
    根据所述头发轮廓线确定所述原始人物图像中的人脸区域;Determining the face area in the original person image according to the hair contour line;
    根据所述人脸区域得到初始感兴趣区域;Obtaining an initial region of interest according to the face region;
    将所述头发轮廓线分别在所述原始人物图像的横坐标轴及纵坐标轴进行投影,得到所述头发轮廓线在所述横坐标轴的第一投影分布及在所述纵坐标轴的第二投影分布;Project the hair contour line on the abscissa axis and the ordinate axis of the original character image respectively, to obtain the first projection distribution of the hair contour line on the abscissa axis and the first projected distribution on the ordinate axis. Two-projection distribution;
    根据所述第一投影分布及第二投影分布对所述初始感兴趣区域进行修正,得到抠图感兴趣区域。The initial region of interest is corrected according to the first projection distribution and the second projection distribution to obtain a matted region of interest.
  25. 根据权利要求22~24任一所述的电子设备,其特征在于,所述计算机程序被所述处理器执行时,使得所述处理器在执行所述根据原始人物图像,以及与所述原始人物图像对应的人像分割图像,确定所述原始人物图像中的抠图感兴趣区域的步骤之前,还执行步骤:若原始人物图像为发生旋转的图像,则分别对所述原始人物图像及与所述原始人物图像对应的人像分割图像进行校正;The electronic device according to any one of claims 22-24, characterized in that, when the computer program is executed by the processor, the processor is executed according to the original character image, and with the original character image For the segmented portrait image corresponding to the image, before the step of determining the matting region of interest in the original character image, a step is also performed: if the original character image is a rotated image, the original character image and the The portrait segmentation image corresponding to the original person image is corrected;
    所述在所述根据原始人物图像,以及与所述原始人物图像对应的人像分割图像,确定所述原始人物图像中的抠图感兴趣区域,包括:The determining the region of interest in matting in the original character image according to the original character image and the segmented portrait image corresponding to the original character image includes:
    根据校正后的原始人物图像及校正后的人像分割图像,确定校正后的抠图感兴趣区域;Determine the corrected matting region of interest according to the corrected original person image and the corrected portrait segmentation image;
    按照未校正的原始人物图像的旋转方向,对所述校正后的抠图感兴趣区域进行旋转,得到所述未校正的原始人物图像中的抠图感兴趣区域。The corrected matting region of interest is rotated according to the rotation direction of the uncorrected original person image to obtain the matting region of interest in the uncorrected original person image.
  26. 根据权利要求20所述的电子设备,其特征在于,所述对所述第一头发掩膜进行优化处理,以得到所述原始人物图像对应的目标头发掩膜,包括:The electronic device according to claim 20, wherein said optimizing the first hair mask to obtain a target hair mask corresponding to the original character image comprises:
    对所述第一头发掩膜进行优化处理,得到第二头发掩膜;Optimizing the first hair mask to obtain a second hair mask;
    对所述第二头发掩膜进行上采样滤波处理,得到所述原始人物图像对应的目标头发掩膜。Perform upsampling and filtering processing on the second hair mask to obtain a target hair mask corresponding to the original person image.
  27. 根据权利要求26所述的电子设备,其特征在于,所述对所述第一头发掩膜进行优化处理,得到第二头发掩膜,包括:The electronic device according to claim 26, wherein said optimizing the first hair mask to obtain a second hair mask comprises:
    计算所述感兴趣区域图像对应的背景复杂度图像;Calculating the background complexity image corresponding to the ROI image;
    根据所述背景复杂度图像对所述第一头发掩膜进行腐蚀处理,得到第二头发掩膜。Erosion processing is performed on the first hair mask according to the background complexity image to obtain a second hair mask.
  28. 根据权利要求27所述的电子设备,其特征在于,所述计算所述感兴趣区域图像对应的背景复杂度图像,包括:The electronic device according to claim 27, wherein the calculating the background complexity image corresponding to the ROI image comprises:
    获取所述感兴趣区域图像的灰度图像;Acquiring a grayscale image of the image of the region of interest;
    对所述灰度图像进行边缘检测,得到第一边缘图像;performing edge detection on the grayscale image to obtain a first edge image;
    根据所述第一头发掩膜去除所述第一边缘图像中的头发边缘,得到第二边缘图像;removing hair edges in the first edge image according to the first hair mask to obtain a second edge image;
    对所述第二边缘图像进行膨胀处理及模糊处理,以得到背景复杂度图像。Dilation and blurring are performed on the second edge image to obtain a background complexity image.
  29. 根据权利要求27所述的电子设备,其特征在于,所述根据所述背景复杂度图像对所述第一头发掩膜进行腐蚀处理,得到第二头发掩膜,包括:The electronic device according to claim 27, wherein the etching process is performed on the first hair mask according to the background complexity image to obtain a second hair mask, comprising:
    根据所述背景复杂度图像,确定所述第一头发掩膜中复杂度大于复杂度阈值的背景复杂区域;According to the background complexity image, determine a background complex area in the first hair mask whose complexity is greater than a complexity threshold;
    对所述第一头发掩膜中处于所述背景复杂区域周围的头发区域进行腐蚀处理;Erosion processing is performed on the hair area around the background complex area in the first hair mask;
    将腐蚀处理前的第一头发掩膜与腐蚀处理后的第一头发掩膜进行融合,得到第二头发掩膜。The first hair mask before the corrosion treatment is fused with the first hair mask after the corrosion treatment to obtain a second hair mask.
  30. 根据权利要求26所述的电子设备,其特征在于,所述对所述第一头发掩膜进行优化处理,得到第二头发掩膜,包括:The electronic device according to claim 26, wherein said optimizing the first hair mask to obtain a second hair mask comprises:
    对所述第一头发掩膜的头发区域中的孔洞进行填充,得到第二头发掩膜。Filling holes in the hair region of the first hair mask to obtain a second hair mask.
  31. 根据权利要求26所述的电子设备,其特征在于,所述对所述第一头发掩膜进行优化处理,得到第二头发掩膜,包括:The electronic device according to claim 26, wherein said optimizing the first hair mask to obtain a second hair mask comprises:
    对所述第一头发掩膜的头发区域的边缘进行增强处理,得到第二头发掩膜。The edge of the hair region of the first hair mask is enhanced to obtain a second hair mask.
  32. 根据权利要求26所述的电子设备,其特征在于,所述对所述第一头发掩膜进行优化处理,得到第二头发掩膜,包括:The electronic device according to claim 26, wherein said optimizing the first hair mask to obtain a second hair mask comprises:
    若所述原始人物图像对应的图像场景为目标场景,则对所述第一头发掩膜的头发区域的边缘进行柔化处理,得到第二头发掩膜,所述目标场景为场景亮度值低于亮度阈值的场景。If the image scene corresponding to the original character image is the target scene, soften the edges of the hair region of the first hair mask to obtain a second hair mask, and the target scene is a scene whose brightness value is lower than The brightness threshold of the scene.
  33. 根据权利要求32所述的电子设备,其特征在于,所述计算机程序被所述处理器执行时,使得所述处理器在执行所述若所述原始人物图像对应的图像场景为目标场景,则对所述第一头发掩膜的头发区域的边缘进行模糊处理的步骤之前,还执行如下步骤:The electronic device according to claim 32, characterized in that, when the computer program is executed by the processor, the processor is executed to execute the said if the image scene corresponding to the original character image is the target scene, then Before the step of blurring the edge of the hair region of the first hair mask, the following steps are also performed:
    获取所述原始人物图像对应的感光值;Acquiring the photosensitive value corresponding to the original person image;
    若所述感光值大于感光阈值,则确定所述原始人物图像对应的图像场景为目标场景。If the light-sensing value is greater than the light-sensing threshold, it is determined that the image scene corresponding to the original person image is the target scene.
  34. 根据权利要求26所述的电子设备,其特征在于,所述对所述第一头发掩膜进行优化处理,得到第二头发掩膜,包括:The electronic device according to claim 26, wherein said optimizing the first hair mask to obtain a second hair mask comprises:
    计算所述感兴趣区域图像对应的背景复杂度图像;Calculating the background complexity image corresponding to the ROI image;
    根据所述背景复杂度图像对所述第一头发掩膜进行腐蚀处理;performing erosion processing on the first hair mask according to the background complexity image;
    对腐蚀处理后的第一头发掩膜的头发区域中的孔洞进行填充;filling holes in the hair region of the first hair mask after the erosion process;
    对填充后的第一头发掩膜的头发区域的边缘进行增强处理;performing enhancement processing on the edges of the hair region of the filled first hair mask;
    若所述原始人物图像对应的图像场景为目标场景,则对增强处理后的第一头发掩膜的头发区域的边缘进行柔化处理,以得到第二头发掩膜;If the image scene corresponding to the original person image is the target scene, softening the edge of the hair region of the enhanced first hair mask to obtain a second hair mask;
    若所述原始人物图像对应的图像场景不为所述目标场景,则将所述增强处理后的第一头发掩膜作为第二头发掩膜。If the image scene corresponding to the original person image is not the target scene, the enhanced first hair mask is used as the second hair mask.
  35. 根据权利要求26~34任一所述的电子设备,其特征在于,所述对所述第二头发掩膜进行上采样滤波处理,得到所述原始人物图像对应的目标头发掩膜,包括:The electronic device according to any one of claims 26 to 34, wherein the upsampling and filtering of the second hair mask to obtain the target hair mask corresponding to the original person image includes:
    将所述感兴趣区域图像的灰度图像作为引导滤波器的引导图像,通过所述引导滤波器对所述第二头发掩膜进行上采样滤波处理,得到所述原始人物图像对应的目标头发掩膜。Using the grayscale image of the region of interest image as the guide image of the guide filter, performing upsampling filtering on the second hair mask through the guide filter, to obtain the target hair mask corresponding to the original person image membrane.
  36. 根据权利要求35所述的电子设备,其特征在于,所述计算机程序被所述处理器执行时,使得所述处理器在执行所述将所述感兴趣区域图像的灰度图像作为引导滤波器的引导图像,通过所述引导滤波器对所述第二头发掩膜进行上采样滤波处理的步骤之前,还执行步骤:根据所述感兴趣区域图像对应的背景复杂度图像对所述第二头发掩膜进行区域划分,得到背景简单区域及背景复杂区域,所述背景简单区域为复杂度低于或等于复杂度阈值的背景区域,所述背景复杂区域为复杂度高于所述复杂度阈值的背景区域;The electronic device according to claim 35, wherein when the computer program is executed by the processor, the processor makes the grayscale image of the region-of-interest image as a guide filter when executing the Before the step of performing upsampling and filtering on the second hair mask by the guide filter, a step is also performed: according to the background complexity image corresponding to the region of interest image, the second hair mask is The mask is divided into regions to obtain a simple background region and a complex background region. The simple background region is a background region whose complexity is lower than or equal to the complexity threshold, and the complex background region is a background region whose complexity is higher than the complexity threshold. background area;
    所述将所述感兴趣区域图像的灰度图像作为引导滤波器的引导图像,通过所述引导滤波器对所述第二头发掩膜进行上采样滤波处理,得到所述原始人物图像对应的目标头发掩膜,包括:The grayscale image of the region of interest image is used as the guide image of the guide filter, and the second hair mask is subjected to upsampling filtering through the guide filter to obtain the target corresponding to the original person image Hair masks, including:
    将所述感兴趣区域图像的灰度图像作为引导滤波器的引导图像,通过所述引导滤波器对所述第二头 发掩膜中处于所述背景简单区域周围的头发区域进行上采样滤波处理,得到第一滤波结果;Using the grayscale image of the region of interest image as the guide image of the guide filter, performing upsampling filter processing on the hair region around the background simple region in the second hair mask through the guide filter, Obtain the first filtering result;
    采用双线性插值算法对所述第二头发掩膜中处于所述背景复杂区域周围的头发区域进行上采样滤波处理,得到第二滤波结果;Using a bilinear interpolation algorithm to perform upsampling and filtering on the hair area around the complex background area in the second hair mask to obtain a second filtering result;
    将所述第一滤波结果及第二滤波结果进行融合,得到目标头发掩膜。The first filtering result and the second filtering result are fused to obtain a target hair mask.
  37. 根据权利要求21~24、26~34任一所述的电子设备,其特征在于,所述根据所述感兴趣区域图像及所述区域分割图像生成第一头发掩膜,包括:The electronic device according to any one of claims 21-24, 26-34, wherein said generating a first hair mask according to said region-of-interest image and said region-segmented image comprises:
    将所述感兴趣区域图像及所述区域分割图像输入图像处理模型,通过所述图像处理模型对所述感兴趣区域图像及所述区域分割图像进行处理,得到第一头发掩膜,其中,所述图像处理模型是根据多组样本训练图像进行训练得到的,每一组样本训练图像包括样本人物图像、与所述样本人物图像对应的样本人像分割图像及样本头发掩膜。Inputting the region-of-interest image and the region-segmented image into an image processing model, and processing the region-of-interest image and the region-segmented image through the image processing model to obtain a first hair mask, wherein the The image processing model is obtained by training according to multiple sets of sample training images, and each set of sample training images includes a sample person image, a sample portrait segmentation image corresponding to the sample person image, and a sample hair mask.
  38. 根据权利要求37所述的电子设备,其特征在于,所述样本头发掩膜是根据所述样本人物图像对应的背景复杂度图像进行腐蚀处理后得到的。The electronic device according to claim 37, wherein the sample hair mask is obtained by performing corrosion processing on the background complexity image corresponding to the sample character image.
  39. 根据权利要求21~24、26~34任一所述的电子设备,其特征在于,所述计算机程序被所述处理器执行时,还使得所述处理器执行如下步骤:The electronic device according to any one of claims 21-24, 26-34, characterized in that, when the computer program is executed by the processor, it also causes the processor to perform the following steps:
    根据所述目标头发掩膜对所述原始人物图像的背景区域进行虚化处理,得到目标人物图像。The background area of the original person image is blurred according to the target hair mask to obtain the target person image.
  40. 一种计算机可读存储介质,其上存储有计算机程序,其特征在于,所述计算机程序被处理器执行时,使得所述处理器执行如下步骤:A computer-readable storage medium with a computer program stored thereon, wherein when the computer program is executed by a processor, the processor is made to perform the following steps:
    对原始人物图像进行预处理,得到所述原始人物图像的感兴趣区域图像,以及与所述感兴趣区域图像对应的区域分割图像,所述区域分割图像包括所述感兴趣区域图像的人像区域信息;Preprocessing the original person image to obtain a region-of-interest image of the original person image, and a region segmentation image corresponding to the region-of-interest image, where the region segmentation image includes portrait region information of the region-of-interest image ;
    根据所述感兴趣区域图像及所述区域分割图像生成第一头发掩膜;generating a first hair mask according to the region-of-interest image and the region-segmented image;
    对所述第一头发掩膜进行优化处理,得到第二头发掩膜;Optimizing the first hair mask to obtain a second hair mask;
    对所述第二头发掩膜进行上采样滤波处理,以得到所述原始人物图像对应的目标头发掩膜。Perform upsampling and filtering processing on the second hair mask to obtain a target hair mask corresponding to the original person image.
  41. 根据权利要求40所述的计算机可读存储介质,其特征在于,所述对原始人物图像进行预处理,得到所述原始人物图像的感兴趣区域图像,以及与所述感兴趣区域图像对应的区域分割图像,包括:The computer-readable storage medium according to claim 40, wherein the preprocessing is performed on the original character image to obtain the ROI image of the original character image and the region corresponding to the ROI image Segment images, including:
    根据原始人物图像,以及与所述原始人物图像对应的人像分割图像,确定所述原始人物图像中的抠图感兴趣区域,所述人像分割图像为对所述原始人物图像进行人像提取后得到的图像,所述人像分割图像包括所述原始人物图像的人像区域信息;According to the original person image, and the portrait segmentation image corresponding to the original person image, determine the matting region of interest in the original person image, and the portrait segmentation image is obtained after portrait extraction is performed on the original person image image, the portrait segmentation image includes the portrait area information of the original person image;
    根据所述抠图感兴趣区域分别对所述原始人物图像及人像分割图像进行裁剪,得到感兴趣区域图像以及与所述感兴趣区域图像对应的区域分割图像。The original person image and the segmented portrait image are clipped respectively according to the cutout region of interest to obtain a region of interest image and a region segmentation image corresponding to the region of interest image.
  42. 根据权利要求41所述的计算机可读存储介质,其特征在于,所述根据原始人物图像,以及与所述原始人物图像对应的人像分割图像,确定所述原始人物图像中的抠图感兴趣区域,包括:The computer-readable storage medium according to claim 41, wherein, according to the original character image and the segmented portrait image corresponding to the original character image, the matting region of interest in the original character image is determined ,include:
    获取所述原始人物图像对应的头发分割图像,所述头发分割图像为对所述原始人物图像进行头发分割后得到的图像,所述头发分割图像包括所述原始人物图像的头发区域信息;Acquiring a hair segmentation image corresponding to the original person image, the hair segmentation image is an image obtained by performing hair segmentation on the original person image, and the hair segmentation image includes hair region information of the original person image;
    根据所述头发分割图像及所述人像分割图像计算得到头发轮廓线;calculating hair contour lines according to the hair segmentation image and the portrait segmentation image;
    根据所述头发轮廓线确定所述原始人物图像中的抠图感兴趣区域。A matting region of interest in the original person image is determined according to the hair contour line.
  43. 根据权利要求42所述的计算机可读存储介质,其特征在于,所述根据所述头发轮廓线确定所述原始人物图像中的抠图感兴趣区域,包括:The computer-readable storage medium according to claim 42, wherein the determining the matting region of interest in the original person image according to the hair contour line comprises:
    根据所述头发轮廓线确定所述原始人物图像中的人脸区域;Determining the face area in the original person image according to the hair contour line;
    根据所述人脸区域得到初始感兴趣区域;Obtaining an initial region of interest according to the face region;
    将所述头发轮廓线分别在所述原始人物图像的横坐标轴及纵坐标轴进行投影,得到所述头发轮廓线在所述横坐标轴的第一投影分布及在所述纵坐标轴的第二投影分布;Project the hair contour line on the abscissa axis and the ordinate axis of the original character image respectively, to obtain the first projection distribution of the hair contour line on the abscissa axis and the first projected distribution on the ordinate axis. Two-projection distribution;
    根据所述第一投影分布及第二投影分布对所述初始感兴趣区域进行修正,得到抠图感兴趣区域。The initial region of interest is corrected according to the first projection distribution and the second projection distribution to obtain a matted region of interest.
  44. 根据权利要求41~43任一所述的计算机可读存储介质,其特征在于,所述计算机程序被处理器执行时,使得所述处理器在执行所述根据原始人物图像,以及与所述原始人物图像对应的人像分割图像,确定所述原始人物图像中的抠图感兴趣区域的步骤之前,还执行步骤:若原始人物图像为发生旋转的图像,则分别对所述原始人物图像及与所述原始人物图像对应的人像分割图像进行校正;The computer-readable storage medium according to any one of claims 41-43, wherein when the computer program is executed by a processor, the processor executes the For the portrait segmentation image corresponding to the person image, before the step of determining the matting region of interest in the original person image, a step is also performed: if the original person image is a rotated image, the original person image and the corresponding The portrait segmentation image corresponding to the original person image is corrected;
    所述在所述根据原始人物图像,以及与所述原始人物图像对应的人像分割图像,确定所述原始人物图像中的抠图感兴趣区域,包括:The determining the region of interest in matting in the original person image according to the original person image and the image segmentation image corresponding to the original person image includes:
    根据校正后的原始人物图像及校正后的人像分割图像,确定校正后的抠图感兴趣区域;Determine the corrected matting region of interest according to the corrected original person image and the corrected portrait segmentation image;
    按照未校正的原始人物图像的旋转方向,对所述校正后的抠图感兴趣区域进行旋转,得到所述未校 正的原始人物图像中的抠图感兴趣区域。According to the rotation direction of the uncorrected original person image, the corrected matting region of interest is rotated to obtain the matting region of interest in the uncorrected original person image.
  45. 根据权利要求40所述的计算机可读存储介质,其特征在于,所述对所述第一头发掩膜进行优化处理,以得到所述原始人物图像对应的目标头发掩膜,包括:The computer-readable storage medium according to claim 40, wherein said optimizing the first hair mask to obtain the target hair mask corresponding to the original character image comprises:
    对所述第一头发掩膜进行优化处理,得到第二头发掩膜;Optimizing the first hair mask to obtain a second hair mask;
    对所述第二头发掩膜进行上采样滤波处理,得到所述原始人物图像对应的目标头发掩膜。Perform upsampling and filtering processing on the second hair mask to obtain a target hair mask corresponding to the original person image.
  46. 根据权利要求45所述的计算机可读存储介质,其特征在于,所述对所述第一头发掩膜进行优化处理,得到第二头发掩膜,包括:The computer-readable storage medium according to claim 45, wherein said optimizing the first hair mask to obtain a second hair mask comprises:
    计算所述感兴趣区域图像对应的背景复杂度图像;Calculating the background complexity image corresponding to the ROI image;
    根据所述背景复杂度图像对所述第一头发掩膜进行腐蚀处理,得到第二头发掩膜。Erosion processing is performed on the first hair mask according to the background complexity image to obtain a second hair mask.
  47. 根据权利要求46所述的计算机可读存储介质,其特征在于,所述计算所述感兴趣区域图像对应的背景复杂度图像,包括:The computer-readable storage medium according to claim 46, wherein the calculating the background complexity image corresponding to the ROI image comprises:
    获取所述感兴趣区域图像的灰度图像;Acquiring a grayscale image of the image of the region of interest;
    对所述灰度图像进行边缘检测,得到第一边缘图像;performing edge detection on the grayscale image to obtain a first edge image;
    根据所述第一头发掩膜去除所述第一边缘图像中的头发边缘,得到第二边缘图像;removing hair edges in the first edge image according to the first hair mask to obtain a second edge image;
    对所述第二边缘图像进行膨胀处理及模糊处理,以得到背景复杂度图像。Dilation and blurring are performed on the second edge image to obtain a background complexity image.
  48. 根据权利要求46所述的计算机可读存储介质,其特征在于,所述根据所述背景复杂度图像对所述第一头发掩膜进行腐蚀处理,得到第二头发掩膜,包括:The computer-readable storage medium according to claim 46, wherein the etching process is performed on the first hair mask according to the background complexity image to obtain a second hair mask, comprising:
    根据所述背景复杂度图像,确定所述第一头发掩膜中复杂度大于复杂度阈值的背景复杂区域;According to the background complexity image, determine a background complex area in the first hair mask whose complexity is greater than a complexity threshold;
    对所述第一头发掩膜中处于所述背景复杂区域周围的头发区域进行腐蚀处理;Erosion processing is performed on the hair area around the background complex area in the first hair mask;
    将腐蚀处理前的第一头发掩膜与腐蚀处理后的第一头发掩膜进行融合,得到第二头发掩膜。The first hair mask before the corrosion treatment is fused with the first hair mask after the corrosion treatment to obtain a second hair mask.
  49. 根据权利要求45所述的计算机可读存储介质,其特征在于,所述对所述第一头发掩膜进行优化处理,得到第二头发掩膜,包括:The computer-readable storage medium according to claim 45, wherein said optimizing the first hair mask to obtain a second hair mask comprises:
    对所述第一头发掩膜的头发区域中的孔洞进行填充,得到第二头发掩膜。Filling holes in the hair region of the first hair mask to obtain a second hair mask.
  50. 根据权利要求45所述的计算机可读存储介质,其特征在于,所述对所述第一头发掩膜进行优化处理,得到第二头发掩膜,包括:The computer-readable storage medium according to claim 45, wherein said optimizing the first hair mask to obtain a second hair mask comprises:
    对所述第一头发掩膜的头发区域的边缘进行增强处理,得到第二头发掩膜。The edge of the hair region of the first hair mask is enhanced to obtain a second hair mask.
  51. 根据权利要求45所述的计算机可读存储介质,其特征在于,所述对所述第一头发掩膜进行优化处理,得到第二头发掩膜,包括:The computer-readable storage medium according to claim 45, wherein said optimizing the first hair mask to obtain a second hair mask comprises:
    若所述原始人物图像对应的图像场景为目标场景,则对所述第一头发掩膜的头发区域的边缘进行柔化处理,得到第二头发掩膜,所述目标场景为场景亮度值低于亮度阈值的场景。If the image scene corresponding to the original character image is the target scene, soften the edges of the hair region of the first hair mask to obtain a second hair mask, and the target scene is a scene whose brightness value is lower than The brightness threshold of the scene.
  52. 根据权利要求51所述的计算机可读存储介质,其特征在于,所述计算机程序被处理器执行时,使得所述处理器在执行所述若所述原始人物图像对应的图像场景为目标场景,则对所述第一头发掩膜的头发区域的边缘进行模糊处理的步骤之前,还执行如下步骤:The computer-readable storage medium according to claim 51, wherein when the computer program is executed by the processor, the processor executes the if the image scene corresponding to the original character image is the target scene, Then before the step of blurring the edge of the hair region of the first hair mask, the following steps are also performed:
    获取所述原始人物图像对应的感光值;Acquiring the photosensitive value corresponding to the original person image;
    若所述感光值大于感光阈值,则确定所述原始人物图像对应的图像场景为目标场景。If the light-sensing value is greater than the light-sensing threshold, it is determined that the image scene corresponding to the original person image is the target scene.
  53. 根据权利要求45所述的计算机可读存储介质,其特征在于,所述对所述第一头发掩膜进行优化处理,得到第二头发掩膜,包括:The computer-readable storage medium according to claim 45, wherein said optimizing the first hair mask to obtain a second hair mask comprises:
    计算所述感兴趣区域图像对应的背景复杂度图像;Calculating the background complexity image corresponding to the ROI image;
    根据所述背景复杂度图像对所述第一头发掩膜进行腐蚀处理;performing erosion processing on the first hair mask according to the background complexity image;
    对腐蚀处理后的第一头发掩膜的头发区域中的孔洞进行填充;filling holes in the hair region of the first hair mask after the erosion process;
    对填充后的第一头发掩膜的头发区域的边缘进行增强处理;performing enhancement processing on the edges of the hair region of the filled first hair mask;
    若所述原始人物图像对应的图像场景为目标场景,则对增强处理后的第一头发掩膜的头发区域的边缘进行柔化处理,以得到第二头发掩膜;If the image scene corresponding to the original person image is the target scene, softening the edge of the hair region of the enhanced first hair mask to obtain a second hair mask;
    若所述原始人物图像对应的图像场景不为所述目标场景,则将所述增强处理后的第一头发掩膜作为第二头发掩膜。If the image scene corresponding to the original person image is not the target scene, the enhanced first hair mask is used as the second hair mask.
  54. 根据权利要求45~53任一所述的计算机可读存储介质,其特征在于,所述对所述第二头发掩膜进行上采样滤波处理,得到所述原始人物图像对应的目标头发掩膜,包括:The computer-readable storage medium according to any one of claims 45-53, wherein the upsampling and filtering process is performed on the second hair mask to obtain the target hair mask corresponding to the original person image, include:
    将所述感兴趣区域图像的灰度图像作为引导滤波器的引导图像,通过所述引导滤波器对所述第二头发掩膜进行上采样滤波处理,得到所述原始人物图像对应的目标头发掩膜。Using the grayscale image of the region of interest image as the guide image of the guide filter, performing upsampling filtering on the second hair mask through the guide filter, to obtain the target hair mask corresponding to the original person image membrane.
  55. 根据权利要求54所述的计算机可读存储介质,其特征在于,所述计算机程序被处理器执行时, 使得所述处理器在执行所述将所述感兴趣区域图像的灰度图像作为引导滤波器的引导图像,通过所述引导滤波器对所述第二头发掩膜进行上采样滤波处理的步骤之前,还执行步骤:根据所述感兴趣区域图像对应的背景复杂度图像对所述第二头发掩膜进行区域划分,得到背景简单区域及背景复杂区域,所述背景简单区域为复杂度低于或等于复杂度阈值的背景区域,所述背景复杂区域为复杂度高于所述复杂度阈值的背景区域;The computer-readable storage medium according to claim 54, wherein when the computer program is executed by the processor, the processor is executed to use the grayscale image of the region of interest image as a guide filter Before the step of upsampling and filtering the second hair mask through the guiding filter, the step of: performing the step of: The hair mask is divided into regions to obtain a simple background region and a complex background region, the simple background region is a background region whose complexity is lower than or equal to the complexity threshold, and the complex background region is a background region whose complexity is higher than the complexity threshold the background area of
    所述将所述感兴趣区域图像的灰度图像作为引导滤波器的引导图像,通过所述引导滤波器对所述第二头发掩膜进行上采样滤波处理,得到所述原始人物图像对应的目标头发掩膜,包括:The grayscale image of the region of interest image is used as the guide image of the guide filter, and the second hair mask is subjected to upsampling filtering through the guide filter to obtain the target corresponding to the original person image Hair masks, including:
    将所述感兴趣区域图像的灰度图像作为引导滤波器的引导图像,通过所述引导滤波器对所述第二头发掩膜中处于所述背景简单区域周围的头发区域进行上采样滤波处理,得到第一滤波结果;Using the grayscale image of the region of interest image as the guide image of the guide filter, performing upsampling filter processing on the hair region around the background simple region in the second hair mask through the guide filter, Obtain the first filtering result;
    采用双线性插值算法对所述第二头发掩膜中处于所述背景复杂区域周围的头发区域进行上采样滤波处理,得到第二滤波结果;Using a bilinear interpolation algorithm to perform upsampling and filtering on the hair area around the complex background area in the second hair mask to obtain a second filtering result;
    将所述第一滤波结果及第二滤波结果进行融合,得到目标头发掩膜。The first filtering result and the second filtering result are fused to obtain a target hair mask.
  56. 根据权利要求40~44、45~53任一所述的计算机可读存储介质,其特征在于,所述根据所述感兴趣区域图像及所述区域分割图像生成第一头发掩膜,包括:The computer-readable storage medium according to any one of claims 40-44, 45-53, wherein the generating the first hair mask according to the region-of-interest image and the region-segmented image comprises:
    将所述感兴趣区域图像及所述区域分割图像输入图像处理模型,通过所述图像处理模型对所述感兴趣区域图像及所述区域分割图像进行处理,得到第一头发掩膜,其中,所述图像处理模型是根据多组样本训练图像进行训练得到的,每一组样本训练图像包括样本人物图像、与所述样本人物图像对应的样本人像分割图像及样本头发掩膜。Inputting the region-of-interest image and the region-segmented image into an image processing model, and processing the region-of-interest image and the region-segmented image through the image processing model to obtain a first hair mask, wherein the The image processing model is obtained by training according to multiple sets of sample training images, and each set of sample training images includes a sample person image, a sample portrait segmentation image corresponding to the sample person image, and a sample hair mask.
  57. 根据权利要求56所述的计算机可读存储介质,其特征在于,所述样本头发掩膜是根据所述样本人物图像对应的背景复杂度图像进行腐蚀处理后得到的。The computer-readable storage medium according to claim 56, wherein the sample hair mask is obtained by performing corrosion processing on the background complexity image corresponding to the sample character image.
  58. 根据权利要求40~44、45~53任一所述的计算机可读存储介质,其特征在于,所述计算机程序被处理器执行时,还使得所述处理器执行如下步骤:The computer-readable storage medium according to any one of claims 40-44, 45-53, characterized in that, when the computer program is executed by the processor, it also causes the processor to perform the following steps:
    根据所述目标头发掩膜对所述原始人物图像的背景区域进行虚化处理,得到目标人物图像。The background area of the original person image is blurred according to the target hair mask to obtain the target person image.
PCT/CN2021/100148 2021-06-15 2021-06-15 Image processing method and apparatus, electronic device, and computer-readable storage medium WO2022261828A1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
PCT/CN2021/100148 WO2022261828A1 (en) 2021-06-15 2021-06-15 Image processing method and apparatus, electronic device, and computer-readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2021/100148 WO2022261828A1 (en) 2021-06-15 2021-06-15 Image processing method and apparatus, electronic device, and computer-readable storage medium

Publications (1)

Publication Number Publication Date
WO2022261828A1 true WO2022261828A1 (en) 2022-12-22

Family

ID=84526752

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/100148 WO2022261828A1 (en) 2021-06-15 2021-06-15 Image processing method and apparatus, electronic device, and computer-readable storage medium

Country Status (1)

Country Link
WO (1) WO2022261828A1 (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116385641A (en) * 2023-03-29 2023-07-04 北京百度网讯科技有限公司 Image processing method and device, electronic equipment and storage medium
CN116433666A (en) * 2023-06-14 2023-07-14 江西萤火虫微电子科技有限公司 Board card line defect online identification method, system, electronic equipment and storage medium
CN117237397A (en) * 2023-07-13 2023-12-15 天翼爱音乐文化科技有限公司 Portrait segmentation method, system, equipment and storage medium based on feature fusion
CN117237397B (en) * 2023-07-13 2024-05-28 天翼爱音乐文化科技有限公司 Portrait segmentation method, system, equipment and storage medium based on feature fusion

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103456010A (en) * 2013-09-02 2013-12-18 电子科技大学 Human face cartoon generation method based on feature point localization
US20160154993A1 (en) * 2014-12-01 2016-06-02 Modiface Inc. Automatic segmentation of hair in images
CN110992374A (en) * 2019-11-28 2020-04-10 杭州趣维科技有限公司 Hair refined segmentation method and system based on deep learning
CN111402407A (en) * 2020-03-23 2020-07-10 杭州相芯科技有限公司 High-precision image model rapid generation method based on single RGBD image
CN111507994A (en) * 2020-04-24 2020-08-07 Oppo广东移动通信有限公司 Portrait extraction method, portrait extraction device and mobile terminal
CN112508811A (en) * 2020-11-30 2021-03-16 北京百度网讯科技有限公司 Image preprocessing method, device, equipment and storage medium
CN112861661A (en) * 2021-01-22 2021-05-28 深圳市慧鲤科技有限公司 Image processing method and device, electronic equipment and computer readable storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103456010A (en) * 2013-09-02 2013-12-18 电子科技大学 Human face cartoon generation method based on feature point localization
US20160154993A1 (en) * 2014-12-01 2016-06-02 Modiface Inc. Automatic segmentation of hair in images
CN110992374A (en) * 2019-11-28 2020-04-10 杭州趣维科技有限公司 Hair refined segmentation method and system based on deep learning
CN111402407A (en) * 2020-03-23 2020-07-10 杭州相芯科技有限公司 High-precision image model rapid generation method based on single RGBD image
CN111507994A (en) * 2020-04-24 2020-08-07 Oppo广东移动通信有限公司 Portrait extraction method, portrait extraction device and mobile terminal
CN112508811A (en) * 2020-11-30 2021-03-16 北京百度网讯科技有限公司 Image preprocessing method, device, equipment and storage medium
CN112861661A (en) * 2021-01-22 2021-05-28 深圳市慧鲤科技有限公司 Image processing method and device, electronic equipment and computer readable storage medium

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116385641A (en) * 2023-03-29 2023-07-04 北京百度网讯科技有限公司 Image processing method and device, electronic equipment and storage medium
CN116385641B (en) * 2023-03-29 2024-03-19 北京百度网讯科技有限公司 Image processing method and device, electronic equipment and storage medium
CN116433666A (en) * 2023-06-14 2023-07-14 江西萤火虫微电子科技有限公司 Board card line defect online identification method, system, electronic equipment and storage medium
CN116433666B (en) * 2023-06-14 2023-08-15 江西萤火虫微电子科技有限公司 Board card line defect online identification method, system, electronic equipment and storage medium
CN117237397A (en) * 2023-07-13 2023-12-15 天翼爱音乐文化科技有限公司 Portrait segmentation method, system, equipment and storage medium based on feature fusion
CN117237397B (en) * 2023-07-13 2024-05-28 天翼爱音乐文化科技有限公司 Portrait segmentation method, system, equipment and storage medium based on feature fusion

Similar Documents

Publication Publication Date Title
US11882357B2 (en) Image display method and device
JP6961811B2 (en) Methods and devices for image processing, as well as computer-readable storage media
EP3477931B1 (en) Image processing method and device, readable storage medium and electronic device
US11250571B2 (en) Robust use of semantic segmentation in shallow depth of field rendering
EP3757890A1 (en) Method and device for image processing, method and device for training object detection model
CN107808136B (en) Image processing method, image processing device, readable storage medium and computer equipment
CN107730444B (en) Image processing method, image processing device, readable storage medium and computer equipment
CN111402135A (en) Image processing method, image processing device, electronic equipment and computer readable storage medium
WO2021022983A1 (en) Image processing method and apparatus, electronic device and computer-readable storage medium
CN108537749B (en) Image processing method, image processing device, mobile terminal and computer readable storage medium
CN113766125B (en) Focusing method and device, electronic equipment and computer readable storage medium
CN108846807B (en) Light effect processing method and device, terminal and computer-readable storage medium
WO2021057474A1 (en) Method and apparatus for focusing on subject, and electronic device, and storage medium
CN107734253A (en) Image processing method, device, mobile terminal and computer-readable recording medium
CN107368806B (en) Image rectification method, image rectification device, computer-readable storage medium and computer equipment
WO2019105297A1 (en) Image blurring method and apparatus, mobile device, and storage medium
WO2022261828A1 (en) Image processing method and apparatus, electronic device, and computer-readable storage medium
CN110276831B (en) Method and device for constructing three-dimensional model, equipment and computer-readable storage medium
CN113313661A (en) Image fusion method and device, electronic equipment and computer readable storage medium
US11836903B2 (en) Subject recognition method, electronic device, and computer readable storage medium
CN113313626A (en) Image processing method, image processing device, electronic equipment and storage medium
CN113658197B (en) Image processing method, device, electronic equipment and computer readable storage medium
WO2023217046A1 (en) Image processing method and apparatus, nonvolatile readable storage medium and electronic device
CN113673474B (en) Image processing method, device, electronic equipment and computer readable storage medium
CN110365897B (en) Image correction method and device, electronic equipment and computer readable storage medium

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: 21945421

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE