CN113673474A - Image processing method, image processing device, electronic equipment and computer readable storage medium - Google Patents

Image processing method, image processing device, electronic equipment and computer readable storage medium Download PDF

Info

Publication number
CN113673474A
CN113673474A CN202111015385.5A CN202111015385A CN113673474A CN 113673474 A CN113673474 A CN 113673474A CN 202111015385 A CN202111015385 A CN 202111015385A CN 113673474 A CN113673474 A CN 113673474A
Authority
CN
China
Prior art keywords
image
face
region
portrait
pixel point
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202111015385.5A
Other languages
Chinese (zh)
Other versions
CN113673474B (en
Inventor
李章宇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Guangdong Oppo Mobile Telecommunications Corp Ltd
Original Assignee
Guangdong Oppo Mobile Telecommunications Corp Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Guangdong Oppo Mobile Telecommunications Corp Ltd filed Critical Guangdong Oppo Mobile Telecommunications Corp Ltd
Priority to CN202111015385.5A priority Critical patent/CN113673474B/en
Publication of CN113673474A publication Critical patent/CN113673474A/en
Application granted granted Critical
Publication of CN113673474B publication Critical patent/CN113673474B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T5/00Image enhancement or restoration
    • G06T5/50Image enhancement or restoration using two or more images, e.g. averaging or subtraction
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T5/00Image enhancement or restoration
    • G06T5/70Denoising; Smoothing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/20Special algorithmic details
    • G06T2207/20081Training; Learning
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/20Special algorithmic details
    • G06T2207/20084Artificial neural networks [ANN]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/20Special algorithmic details
    • G06T2207/20212Image combination
    • G06T2207/20221Image fusion; Image merging
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/30Subject of image; Context of image processing
    • G06T2207/30196Human being; Person
    • G06T2207/30201Face

Landscapes

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

Abstract

The embodiment of the application discloses an image processing method, an image processing device, electronic equipment and a computer readable storage medium. The method comprises the following steps: carrying out face recognition on a first image to obtain face information of each face contained in the first image; generating a weight mask according to the portrait mask of the first image and the face information, wherein the weight mask is used for determining a face clear region corresponding to each face in the first image and a portrait fuzzy transition region corresponding to each face; acquiring a blurred image and a background blurring image corresponding to the first image; and fusing the blurred image and the background blurring image according to the weight mask to obtain a second image. The image processing method, the image processing device, the electronic equipment and the computer readable storage medium can avoid the problem that all portrait areas in the image are clear and cause no highlight, and improve the visual display effect of the image.

Description

Image processing method, image processing device, electronic equipment and computer readable storage medium
Technical Field
The present application relates to the field of image technologies, and in particular, to an image processing method and apparatus, an electronic device, and a computer-readable storage medium.
Background
In the field of video technology, in order to highlight a portrait in an image, a background area in the portrait image is usually blurred to achieve an effect of making a subject person photographed clear. The existing blurring technology can keep all portrait areas in an image clear, so that the problem of no highlight is caused, and the visual effect of the image is poor.
Disclosure of Invention
The embodiment of the application discloses an image processing method, an image processing device, electronic equipment and a computer readable storage medium, which can avoid the problem that no salient key points appear due to the fact that all portrait areas in an image are clear, and improve the visual display effect of the image.
The embodiment of the application discloses an image processing method, which comprises the following steps:
carrying out face recognition on a first image to obtain face information of each face contained in the first image;
generating a weight mask according to the portrait mask of the first image and the face information, wherein the weight mask is used for determining a face clear region corresponding to each face in the first image and a portrait fuzzy transition region corresponding to each face; the face sharp region refers to a region which needs to be kept sharp in a portrait region of the first image, and the portrait fuzzy transition region refers to a change region from sharp to fuzzy in the portrait region;
acquiring a blurred image and a background blurred image corresponding to the first image, wherein the blurring degree of the blurred image is smaller than that of a background area in the background blurred image;
and fusing the blurred image and the background blurring image according to the weight mask to obtain a second image.
An embodiment of the application discloses an image processing apparatus, including:
the face recognition module is used for carrying out face recognition on the first image so as to obtain face information of each face contained in the first image;
the weight generation module is used for generating a weight mask according to the human image mask of the first image and the human face information, wherein the weight mask is used for determining a human face clear region corresponding to each human face in the first image and a human image fuzzy transition region corresponding to each human face; the face sharp region refers to a region which needs to be kept sharp in a portrait region of the first image, and the portrait fuzzy transition region refers to a change region from sharp to fuzzy in the portrait region;
the image acquisition module is used for acquiring a blurred image and a background blurring image corresponding to the first image, wherein the blurring degree of the blurred image is smaller than that of a background area in the background blurring image;
and the fusion module is used for fusing the blurred image and the background blurring image according to the weight mask to obtain a second image.
The embodiment of the application discloses an electronic device, which comprises 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 enabled to realize the method.
An embodiment of the application discloses a computer-readable storage medium, on which a computer program is stored, which, when executed by a processor, implements the method as described above.
The image processing method, the device, the electronic equipment and the computer readable storage medium disclosed by the embodiment of the application carry out face recognition on a first image to obtain face information of each face contained in the first image, generate a weight mask according to the face mask and the face information of the first image, fuse a blurred image and a background blurred image corresponding to the first image based on the weight mask to obtain a second image, and can keep each face clear in the second image obtained by fusing two blurred images with different blurring degrees and the background blurred image based on the weight mask, and gradually transition other face areas from clear to blurred, so that the problem of no salient point caused by the clear of all the face areas in the image can be avoided, and the image effect is more natural, and the visual display effect of the image is improved.
In addition, under the condition that the first image comprises a plurality of faces, each face in the obtained second image can be ensured to be clear, the condition that only one person is focused and other faces are blurred can be avoided, and the image blurring effect is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings without creative efforts.
FIG. 1 is a block diagram of image processing circuitry in one embodiment;
FIG. 2 is a flow diagram of a method of image processing in one embodiment;
FIG. 3 is a flow diagram of generating a weight mask in one embodiment;
FIG. 4A is a diagram illustrating a human face region in accordance with an embodiment;
FIG. 4B is a diagram of a weight mask in one embodiment;
FIG. 5 is a flowchart of an image processing method in another embodiment;
FIG. 6 is a block diagram of an image processing apparatus in one embodiment;
fig. 7 is a block diagram of an electronic device in one embodiment.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
It is to be noted that the terms "comprises" and "comprising" and any variations thereof in the examples and figures of the present application are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements listed, but may alternatively include other steps or elements not listed, or inherent to such process, method, article, or apparatus.
It will be understood that, as used herein, the terms "first," "second," and the like may be used herein to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish one element from another. For example, a first image may be referred to as a second image, and similarly, a second image may be referred to as a first image, without departing from the scope of the present application. The first image and the second image are both images, but they are not the same image.
The existing portrait image blurring technology generally adopts a mode of blurring a background area after the background area of the portrait image is identified, so that all portrait areas of the portrait image keep a clear effect, and the problem of no prominent key points can be caused. In some technical solutions, the image of the figure is blurred based on a high-precision depth image, but the method usually only keeps one person clear, and other figures not at the same depth level are blurred, so that the blurring effect of the image is poor.
The embodiment of the application discloses an image processing method, an image processing device, electronic equipment and a computer readable storage medium, which can avoid the problem that no salient key points appear due to the fact that all portrait areas in an image are clear, improve the visual display effect of the image, avoid the situation that only one person focuses but other faces are blurred, and improve the image blurring effect.
The embodiment of the present application provides an electronic device, which may include, but is not limited to, a mobile phone, a smart wearable device, a tablet Computer, a PC (Personal Computer), a vehicle-mounted terminal, a digital camera, and the like, and the embodiment of the present application is not limited thereto. The electronic device includes therein an Image Processing circuit, which may be implemented using hardware and/or software components, and may include various Processing units defining an ISP (Image Signal Processing) pipeline. FIG. 1 is a block diagram of an image processing circuit in one embodiment. For ease of illustration, FIG. 1 illustrates only aspects of image processing techniques related to embodiments of the present application.
As shown in fig. 1, the image processing circuit includes an ISP processor 140 and control logic 150. The image data captured by the imaging device 110 is first processed by the ISP processor 140, and the ISP processor 140 analyzes the image data to capture image statistics that may be used to determine one or more control parameters of the imaging device 110. The imaging device 110 may include one or more lenses 112 and an image sensor 114. Image sensor 114 may include an array of color filters (e.g., Bayer filters), and image sensor 114 may acquire light intensity and wavelength information captured by each imaging pixel and provide a set of raw image data that may be processed by ISP processor 140. The attitude sensor 120 (e.g., a three-axis gyroscope, hall sensor, accelerometer, etc.) may provide parameters of the acquired image processing (e.g., anti-shake parameters) to the ISP processor 140 based on the type of interface of the attitude sensor 120. The attitude sensor 120 interface may employ an SMIA (Standard Mobile Imaging Architecture) interface, other serial or parallel camera interfaces, or a combination thereof.
It should be noted that, although only one imaging device 110 is shown in fig. 1, in the embodiment of the present application, at least two imaging devices 110 may be included, each imaging device 110 may respectively correspond to one image sensor 114, or a plurality of imaging devices 110 may correspond to one image sensor 114, which is not limited herein. The operation of each image forming apparatus 110 can refer to the above description.
In addition, the image sensor 114 may also transmit raw image data to the attitude sensor 120, the attitude sensor 120 may provide the raw image data to the ISP processor 140 based on the type of interface of the attitude sensor 120, or the attitude sensor 120 may store the raw image data in the image memory 130.
The ISP processor 140 processes the raw image data pixel by pixel in a variety of 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, gathering statistical information about the image data. Wherein the image processing operations may be performed with the same or different bit depth precision.
The ISP processor 140 may also receive image data from the image memory 130. For example, the attitude sensor 120 interface sends raw image data to the image memory 130, and the raw image data in the image memory 130 is then provided to the ISP processor 140 for processing. The image Memory 130 may be a portion of a Memory device, a storage device, or a separate dedicated Memory within an electronic device, and may include a DMA (Direct Memory Access) feature.
Upon 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. ISP processor 140 receives the processed data from image memory 130 and performs image data processing on the processed data in the raw domain and in the RGB and YCbCr color spaces. The image data processed by ISP processor 140 may be output to display 160 for viewing by a user and/or further processed by a Graphics Processing Unit (GPU). Further, the output of the ISP processor 140 may also be sent to the image memory 130, and the display 160 may read image data from the image memory 130. In one embodiment, image memory 130 may be configured to implement one or more frame buffers.
The statistics determined by the ISP processor 140 may be sent to the control logic 150. For example, the statistical data may include image sensor 114 statistics such as gyroscope vibration frequency, auto-exposure, auto-white balance, auto-focus, flicker detection, black level compensation, lens 112 shading correction, and the like. The control logic 150 may include a processor and/or microcontroller that executes one or more routines (e.g., firmware) that may determine control parameters of the imaging device 110 and control parameters of the ISP processor 140 based on the received statistical data. For example, the control parameters of the imaging device 110 may include attitude sensor 120 control parameters (e.g., gain, integration time of exposure control, anti-shake parameters, etc.), camera flash control parameters, camera anti-shake displacement parameters, lens 112 control parameters (e.g., focal length for focusing or zooming), or a combination of these parameters. The ISP control parameters may include gain levels and color correction matrices for automatic white balance and color adjustment (e.g., during RGB processing), as well as lens 112 shading correction parameters.
The image processing method provided by the embodiment of the present application is exemplarily described with reference to the image processing circuit of fig. 1. The ISP processor 140 may obtain the first image from the imaging device 110 or the image memory 130, and perform face recognition on the first image to obtain face information of each face included in the first image. The ISP processor 140 may generate a weight mask according to the image mask and the face information of the first image, where the weight mask may be used to determine a face sharp region corresponding to each face in the first image and a face blur transition region corresponding to each face. The ISP processor 140 may obtain a blurred image and a background blurred image corresponding to the first image, where a blur degree of the blurred image is smaller than a blur degree of a background area in the background blurred image, and then fuse the blurred image and the background blurred image according to the weight mask to obtain a second image.
Alternatively, the ISP processor 140 may send the second image to the image memory 130 for storage and may also send the second image to the display 160 for display.
It should be noted that the image processing method provided in the embodiment of the present application may also be implemented by other processors of the electronic device, for example, by a processor such as a CPU (central processing unit) or a GPU (graphics processing unit), and the other processors may obtain the image data processed by the ISP processor 140, that is, obtain the first image, and implement the image processing method provided in the embodiment of the present application.
As shown in fig. 2, in one embodiment, an image processing method is provided, which can be applied to the electronic device described above, and the method can include the following steps:
step 210, performing face recognition on the first image to obtain face information of each face included in the first image.
The first image may be an image including a person, and the first image may be an image that needs to be subjected to image processing. The first image may be a color image, and may be, for example, an image in RGB (Red Green Blue) format or an image in YUV (Y denotes brightness, and U and V denote chroma) format, or the like. The first image may be an image pre-stored in a memory of the electronic device, or an image acquired by the electronic device in real time through a camera.
The electronic device may perform face recognition on the first image to obtain face information of each face included in the first image, where the face information may include, but is not limited to, one or more of a face area of each face, coordinates of a center point of each face area, a radius of each face area, and the like.
In some embodiments, the way of performing face recognition on the first image may include, but is not limited to, a way of performing face recognition based on a face template, a way of performing face recognition based on a classifier, a way of performing face recognition through a deep neural network, and the like.
For example, the electronic device may perform face recognition on the first image by using a convolutional neural network, where the convolutional neural network may be trained according to a face sample set, and the face sample set may include a plurality of face images marked with face regions. The convolutional neural network can extract human face characteristic points in the first image, a human face detection frame corresponding to each human face in the first image is determined according to the human face characteristic points, and an image area where the human face detection frame corresponding to each human face is located can be used as a human face area.
Alternatively, the shape of the face detection box may include, but is not limited to, a square, a rectangle, a circle, and the like. If the face detection frame is a square, rectangle, or other quadrilateral, the radius of the corresponding face region may be the radius of the circumscribed circle of the face detection frame, and if the face detection frame is a circle, the radius of the face region is the radius of the face detection frame. The central point coordinate of the face area is the coordinate of the central pixel point of the face detection frame, if the face detection frame is a square, a rectangle or other quadrangle, the abscissa of the central pixel point can be half of the width of the face detection frame, and the ordinate of the central pixel point can be half of the height of the face detection frame. If the face detection frame is circular, the center point of the face area is the circle center of the face detection frame.
Step 220, generating a weight mask according to the human face mask and the human face information of the first image.
In this embodiment of the application, the weight mask may be used to determine a face sharp region corresponding to each face in the first image, and a portrait fuzzy transition region corresponding to each face, where the face sharp region refers to a region that needs to be kept sharp in the portrait region of the first image, and the portrait fuzzy transition region refers to a region that changes from sharp to fuzzy in the portrait region.
The portrait mask of the first image can be obtained, the portrait mask can be used for representing the position of the portrait area in the first image, and pixel points belonging to the portrait area in the first image can be labeled. Alternatively, in the human image mask, different pixel values may be used to represent the human image region and the non-human image region (i.e. the background region), for example, a pixel value of 255 indicates that the pixel belongs to the human image region, a pixel value of 0 indicates that the pixel belongs to the background region, or a pixel value of 0 indicates that the pixel belongs to the human image region, a pixel value of 255 indicates that the pixel belongs to the background region, etc., but is not limited thereto.
In some embodiments, the portrait mask may be pre-stored in the memory, and after the electronic device acquires the first image, the electronic device may acquire the corresponding portrait mask from the memory according to an image identifier of the first image, where the image identifier may include, but is not limited to, an image number, an image acquisition time, an image name, and other information. The portrait mask may also be generated by the electronic device through portrait recognition on the first image after the electronic device acquires the first image. The way of performing the portrait recognition on the first image may include, but is not limited to, the following ways:
in the first mode, a portrait area of the first image is identified based on the depth map of the first image, and a portrait mask is obtained. The depth estimation can be performed on the first image to obtain a depth map of the first image, the depth map can include depth information corresponding to each pixel point in the first image, the depth information can be used for representing the distance between a point on the shot object and the camera, and the larger the depth information is, the farther the distance is. Because the depth information between the portrait area and the background area is greatly different, the portrait area of the first image may be identified according to the depth map, for example, an area formed by pixel points whose depth information is smaller than a first depth threshold in the first image may be determined as the portrait area, an area formed by pixel points whose depth information is greater than a second depth threshold may be determined as the background area, and the like, where the first depth threshold may be less than or equal to the second depth threshold.
The electronic device may perform depth estimation on the first image in a software depth estimation manner, or in a manner of calculating depth information in combination with a hardware device. The depth estimation manner of the software may include, but is not limited to, a manner of performing depth estimation using a neural network such as a depth estimation model, where the depth estimation model may be obtained by training a depth training set, and the depth training set may include a plurality of sample images and a depth map corresponding to each sample image. The depth estimation method combined with the hardware device may include, but is not limited to, depth estimation using multiple cameras (e.g., dual cameras), depth estimation using structured light, depth estimation using Time of flight (TOF), and the like. The depth estimation method is not limited in the embodiments of the present application.
In some embodiments, the face information of each face in the first image may be combined with the depth map, the depth information of each face region in the depth map may be determined, and a depth difference between the depth information of each pixel point in the depth map and the depth information of each face region may be calculated, and if the depth difference between a pixel point and any one face region is smaller than a difference threshold, it may be determined that the pixel point belongs to the face region corresponding to the face region, and accuracy of face region identification may be improved.
And in the second mode, the first image can be subjected to portrait segmentation processing to obtain a portrait mask. The method of the portrait segmentation process may include, but is not limited to, a portrait segmentation method based on graph theory, a portrait segmentation method based on clustering, a portrait segmentation method based on semantics, a portrait segmentation method based on examples, a portrait segmentation method based on a deeplab series Network model, a segmentation method based on a U-Network (U-Net), or a portrait segmentation method based on a full volume Network (FCN).
Taking the example that the electronic device performs the portrait segmentation processing on the first image through the portrait segmentation model to obtain the portrait mask, the portrait segmentation model may be a model with a U-Net structure, the portrait segmentation model may include an encoder and a decoder, the encoder may include a plurality of down-sampling layers, and the decoder may include a plurality of up-sampling layers. The portrait segmentation model can firstly carry out down-sampling convolution processing on the first image for multiple times through a plurality of down-sampling layers of the encoder, and then carry out up-sampling processing for multiple times through a plurality of up-sampling layers of the decoder to obtain the portrait mask. In the portrait segmentation model, jump connection can be realized between the down-sampling layer and the up-sampling layer between the same resolution, and the features of the down-sampling layer and the up-sampling layer between the same resolution are fused, so that the up-sampling process is more accurate.
Optionally, the portrait segmentation model may be obtained by training according to a portrait sample set, where the portrait sample set may include a plurality of portrait sample images carrying portrait labels, and the portrait labels may be used to label portrait areas in the portrait sample images, for example, the portrait labels may include sample portrait masks and the like.
In some embodiments, a face sharpness region corresponding to each face in the face mask of the first image may be determined according to the face information of each face, and optionally, the face sharpness region of each face may be a face region corresponding to the face, or may be a circumscribed circle region of the face region, or may be a region defined in the face region. Further, the central point of the face clear region can coincide with the central point of the face region to ensure the face is clear.
The face blurring transition region in the face region corresponding to each face can be determined based on each face sharp region to generate the weight mask, and the face blurring transition region can be a part of the face region except for the face sharp region. As an embodiment, the pixel point belonging to the face sharpness region in the weight mask may correspond to a first pixel value, the pixel point not belonging to the face sharpness region or the person blur transition region in the person region may correspond to a second pixel value, and the pixel value of the pixel point belonging to the blur transition region may be between the first pixel value and the second pixel value, for example, the first pixel value may be 0, the second pixel value may be 255, and the like, but is not limited thereto.
Step 230, a blurred image and a background blurring image corresponding to the first image are obtained.
The blurred image is an image obtained by blurring the first image, and the background blurred image is an image obtained by blurring a background area of the first image, optionally, the blurring process may include, but is not limited to, a mean blurring process, a median blurring process, and the like, and the blurring process may be implemented by using a gaussian filter, a mean blurring process, a median blurring process, and the like, which is not limited herein.
The blurred image may have a degree of blur less than a degree of blur of a background region in the background blurred image, and in some embodiments, the blurred image may be an image obtained by blurring the first image based on a first blur radius, and the background blurred image may be an image obtained by blurring the background region of the first image based on a second blur radius. Wherein, the fuzzy radius can be used for representing the fuzzy degree, the larger the fuzzy radius is, the stronger the fuzzy effect is, therefore, the first fuzzy radius can be smaller than the second fuzzy radius.
And 240, fusing the blurred image and the background blurring image according to the weight mask to obtain a second image.
Because the weight mask is marked with a face clear area corresponding to each face and a portrait fuzzy transition area corresponding to each face, the fuzzy image and the background blurring image are fused by the weight mask to obtain a second image, the face clear area and the background area can correspond to the image content in the background blurring image, other portrait areas except the face clear area and the portrait fuzzy transition area in the portrait area can correspond to the image content in the fuzzy image, and the image content in the portrait fuzzy transition area in the second image can be the combination of the background blurring image and the fuzzy image, so that the effect of the portrait area from clear to fuzzy is realized. The portrait area in the background blurring image is clear image content, the whole image in the blurred image has a blurring effect, each face in the second image can be kept clear, other portrait areas are kept blurred to a small degree, and a transition area is arranged between the clear image and the blurred image, so that the overall image effect is more natural.
In the embodiment of the application, because the weight mask is marked with the face clear region corresponding to each face in the first image and the face fuzzy transition region corresponding to each face, each face can be kept clear in the second image obtained by fusing the two fuzzy images with different fuzzy degrees and the background blurring image based on the weight mask, and other face regions are gradually transited from clear to fuzzy, so that the problem that no salient point appears due to the fact that all the face regions in the image are clear can be avoided, the image effect is more natural, and the visual display effect of the image is improved. In addition, under the condition that the first image comprises a plurality of faces, each face in the obtained second image can be ensured to be clear, the condition that only one person is focused and other faces are blurred can be avoided, and the image blurring effect is improved.
As shown in fig. 3, in an embodiment, the step of generating the weight mask according to the face mask and the face information of the first image may include the following steps:
step 302, determining a face clear region corresponding to each face in the face mask of the first image according to the face information.
The face information may include information such as a face region, coordinates of a center point of the face region, and a radius of a circumscribed circle of the face region. The face clear area corresponding to each face in the face mask is a circular area taking the central point coordinate of the face area corresponding to each face as a central point and taking the circumscribed circle radius of the face area corresponding to each face as an area radius.
Taking the first face in the first image as an example, the first face is any one face in the first image, and the face clear region of the first face may be a circular region taking the center point coordinate of the face region corresponding to the first face as a center point and taking the circumscribed circle radius of the face region corresponding to the first face as a region radius, that is, the face clear region of the first face may be the circumscribed circular region of the face region of the first face.
Illustratively, fig. 4A is a schematic diagram of a face sharp region in one embodiment. As shown in fig. 4A, the white area in the portrait mask is a portrait area, the black area is a background area, the portrait mask includes two faces, and a face clear area 412 and a face clear area 414 can be determined based on the face area of each face.
Step 304, respectively determining a first distance between each pixel point of the portrait area in the portrait mask and a central point of the corresponding target human face clear area.
The target face clear region corresponding to each pixel point of the image region can be the target face clear region with the closest distance between each pixel point of the image region. In some embodiments, the number of faces included in the first image may be determined according to a recognition result of face recognition performed on the first image, and if only one face is included in the first image, the face sharpness region corresponding to the face is a target face sharpness region corresponding to all pixel points of the face region in the face mask, and it may be determined that a distance between each pixel point of the face region in the face mask and a center point of the face sharpness region corresponding to the face is a first distance.
If the first image comprises at least two faces, determining a target face clear region with the closest distance between each pixel point of the face region in the face mask and calculating a first distance between each pixel point and the central point of the corresponding target face clear region respectively. The distances between the pixel points and the face clear areas can be respectively calculated, and the face clear area with the minimum distance is selected as the target face clear area.
In some embodiments, the determining a target face sharp region with a closest distance between each pixel point of the portrait region in the portrait mask and calculating a first distance between each pixel point of the portrait region and a center point of the corresponding target face sharp region respectively may include: calculating a third distance from the target pixel point to each face clear region according to a second distance between the target pixel point and the central point of each face clear region and the region radius of each face clear region; determining the human image clear area with the minimum third distance as a target human face clear area corresponding to the target pixel point; and determining a first distance between the target pixel point and the central point of the target face clear region according to a third distance from the target pixel point to the target face region and the region radius of the target face region.
The target pixel point can be any pixel point of the portrait area in the portrait mask, the coordinate of the central point of each face clear area can be obtained, and the second distance from the target pixel point to the central point of each face clear area can be calculated according to the coordinate of the target pixel point and the coordinate of the central point of each face clear area by using a distance formula between two points. The second distance from the target pixel point to the central point of each face clear region can be subtracted by the region radius of the corresponding face clear region to obtain a third distance from the target pixel point to each face clear region.
Specifically, the formula for calculating the third distance from the target pixel point to each portrait clear area may be shown as formula (1):
d3_k(x,y)=d2_k(x,y)-rkformula (1);
wherein d is3_k(x,y)Representing a third distance, d, from the pixel point (x, y) to the clear region of the kth person's image2_k(x,y)Representing pixel (x, y) andsecond distance between center points of k-th person image clear areas, rkThe area radius representing the clear area of the kth personal image. k may be a positive integer greater than or equal to 2.
And after the third distance from the target pixel point to each portrait clear area is obtained, selecting the smallest third distance from the target pixel points, and taking the portrait clear area corresponding to the smallest third distance as the target portrait clear area corresponding to the target pixel point. The third distance from the target pixel point to the target human image clear region can be added to the region radius of the target human face region to obtain the first distance between the target pixel point and the central point of the target human face clear region.
Specifically, the formula for calculating the first distance between the target pixel point and the center point of the target face sharp region may be as shown in formula (2):
d1(x,y)=MIN(d3_k(x,y))+rk′formula (2);
wherein, MIN (d)3_k(x,y)) A third distance r representing the minimum of the third distances from the pixel point (x, y) to the respective portrait clear areask′A region radius representing a clear region of the image (i.e., a clear region of the target image) corresponding to the minimum third distance, d1(x,y)A first distance is represented from the pixel point (x, y) to a center point of the target portrait clear area.
All pixel points of the portrait area in the portrait mask can be traversed, and each pixel point of the portrait area can be calculated according to the method described in the embodiment to obtain the first distance between the pixel point and the central point of the target portrait clear area. Taking fig. 4A as an example, it may be determined whether a target face distinct region corresponding to each pixel point in a white region (i.e., a human image region) in fig. 4A is a human face distinct region 412 or a human face distinct region 414, that is, the attribution of each pixel point in the white region is determined, and then the first distance between each pixel point in the white region and the corresponding target face distinct region is calculated.
And 306, normalizing the first distance of each pixel point according to the portrait transition range of the target face clear area corresponding to each pixel point to obtain a normalized value corresponding to each pixel point, and generating a weight mask according to the normalized value and the portrait mask.
The portrait transition range may be a preset region range of the portrait fuzzy transition region, and the shape and size of the region of the portrait fuzzy transition region may be set according to actual requirements, which is not limited in the embodiment of the present application.
The human face clear regions with different sizes can respectively correspond to human image transition ranges with different sizes, and the sizes of the human image transition ranges can be related to the region radiuses of the corresponding human face clear regions. Illustratively, the portrait transition range may be a circular range outside the face clarity area and close to the face clarity area, a small circle radius of the circular range is an area radius of the face clarity area, and a large circle radius may be 2 times the area radius of the face clarity area. That is, the human image transition range may be a range formed from the area radius to 2 times the area radius from the center point of the human face sharp area.
Aiming at each pixel point of the portrait area in the portrait mask, normalization processing can be performed on the first distance of each pixel point of the portrait area respectively to obtain a normalization value corresponding to each pixel point, wherein the normalization processing can be used for mapping a numerical value to a value in an interval of 0-1.
Taking a target pixel point in the portrait area as an example, the target pixel point may be any pixel point in the portrait area, and the portrait transition range corresponding to the target face clear area may be determined according to the area radius of the target face clear area corresponding to the target pixel point. For example, the portrait transition range may be [ r ]k′,2rk′]I.e. the range from the area radius to 2 times the area radius from the center point of the face-sharp area.
The first distance from the target pixel point to the central point of the target face clear area and the difference value of the area radius of the target face clear area can be calculated, the ratio between the difference value and the portrait transition range is determined, and then normalization processing is carried out on the ratio to obtain the normalization value of the target pixel point.
Specifically, the human image transition range is [ r ]k′,2rk′]For example, the formula for calculating the ratio can be as shown in formula (3):
Figure BDA0003240134170000141
wherein d is1(x,y)Representing a first distance, r, from the pixel point (x, y) to a center point of the target portrait clear areak′Area radius, F, representing the clear area of the target portrait corresponding to pixel (x, y)(x,y)And expressing the ratio corresponding to the pixel point (x, y).
The ratio corresponding to the target pixel point can be normalized, as an implementation mode, whether the ratio is smaller than 0 or larger than 1 can be judged, if the ratio is smaller than 0, the target pixel point belongs to a human face clear area, and the normalization value of the target pixel point can be determined to be 0; if the ratio is larger than 1, the target pixel point is not in the portrait transition range corresponding to the target portrait clear area, does not belong to the portrait fuzzy transition area and does not belong to the face clear area, and the normalization value of the target pixel point can be determined to be 1. If the ratio is greater than or equal to 0 and less than or equal to 1, it indicates that the target pixel point belongs to the portrait fuzzy transition area in the portrait transition range corresponding to the target portrait clear area, and the ratio can be used as the normalization value of the target pixel point.
After the normalized value of each pixel point of the portrait area in the portrait mask is obtained through calculation according to the mode, the weight mask can be generated according to the normalized value of each pixel point of the portrait area and the portrait mask. In some embodiments, the pixel value of each pixel point of the portrait area may be multiplied by the normalized value of each pixel point of the portrait area to obtain a weight value corresponding to each pixel point of the portrait area, so as to generate a weight mask.
Specifically, a formula for calculating the weight value corresponding to each pixel point of the portrait area in the portrait mask may be shown in formula (4):
W_Mask(x,y)=P_Marsk(x,y)·f(x,y)formula (4);
wherein, W _ Mask(x,y)Represents the weight value of the pixel point (x, y), P _ Markk(x,y)Representing the pixel value of a pixel (x, y) in a portrait mask, f(x,y)And expressing the normalized value corresponding to the pixel point (x, y).
Illustratively, FIG. 4B is a diagram of a weight mask in one embodiment. As shown in fig. 4B, the weight mask corresponding to the human image mask of fig. 4A includes two human faces, where the left human face corresponds to the human face sharp region 412 and the human image fuzzy transition region 422 (the region gradually changing from black to white in the left human image region), the right human face corresponds to the human face sharp region 414 and the human image fuzzy transition region 424 (the region gradually changing from black to white in the right human image region), and there are corresponding human face sharp regions and human image fuzzy transition regions for each human face. It should be noted that fig. 4B shows two circles and one straight line only to assist in explaining the region in the weight mask, and does not indicate that the real weight mask carries the graph.
In some embodiments, after the weight mask is generated according to the normalization value corresponding to each pixel point of the portrait area in the portrait mask and the portrait mask, the weight mask may be further subjected to a blurring process, which may include a median blurring process, so that the blurred weight mask is smoother, and then the blurred image and the background blurred image are fused according to the blurred weight mask to obtain a second image, which may be smoother and more natural.
In the embodiment of the application, according to the face mask of the first image and the face information of each face in the first image, the corresponding weight mask can be accurately generated, the face clear region and the face fuzzy transition region of each face in the first image are accurately marked through the weight mask, and the visual display effect of the second image obtained by subsequent fusion can be improved.
As shown in fig. 5, in another embodiment, an image processing method is provided, which may include the steps of:
step 502, performing face recognition on the first image to obtain face information of each face included in the first image.
Step 504, a weight mask is generated according to the face mask and the face information of the first image.
The description of steps 502-504 can refer to the related description in the above embodiments, and will not be repeated herein.
In some embodiments, the weight mask may be further generated according to the human image mask of the first image, the depth map of the first image, and the above-mentioned human face information, where the depth map may include depth information corresponding to each pixel point in the first image. As an embodiment, according to the depth map, depth information of each pixel point in the portrait area in the portrait mask may be obtained, and the depth information of each pixel point is used as a weight value to generate the weight mask.
As another embodiment, the depth information of the face region in the first image may be determined, and the weight value of each pixel point of the face region may be determined according to the depth difference between the depth information of each pixel point of the face region in the face mask and the depth information of the face region.
Optionally, the depth difference may also be normalized, the normalized value corresponding to the pixel point whose depth difference is smaller than the first threshold may be 0, the normalized value corresponding to the pixel point whose depth difference is greater than the second threshold may be 1, and the normalized value corresponding to the pixel point whose depth difference is between the first threshold and the second threshold may be a ratio of the depth difference to a difference value between the second threshold and the first threshold. The first threshold and the second threshold can be set according to actual requirements, and the second threshold is larger than the first threshold.
In some embodiments, when the first image includes a plurality of faces, there may be a case where depth information of the portrait area is inconsistent, and therefore, the depth information of each face area may be obtained, and the portrait area in the portrait mask is subjected to nonlinear stretching processing based on the depth information of each face area, so that the depth information of the whole portrait area is connected to the same level, and then the weight value of each pixel point is determined according to the depth information of each pixel point in the portrait area after the stretching processing. The depth information of the face region may be average depth information of all pixel points included in the face region, or may be depth information of a central point of the face region.
The weight mask is generated through the depth map, the portrait mask, the face information and the like of the first image, so that the portrait area closer to the face in the second image obtained through subsequent fusion is clearer, the portrait area farther from the face is more fuzzy, and a relatively real portrait refocusing effect is realized.
Step 506, performing blurring processing on the first image based on the first blurring radius to obtain a blurred image.
And step 508, blurring the background area of the first image based on the second blur radius to obtain a background blurring image.
The descriptions of steps 506-508 can refer to the related descriptions in the above embodiments, and are not repeated herein.
In some embodiments, the background region of the first image may be divided according to the depth map of the first image, and pixel points with the same or similar depth information in the background region are divided into the same region, so as to obtain a plurality of background sub-regions. The second fuzzy radius of each background sub-region can be determined according to the depth information of each background sub-region, and the depth information of the background sub-region can be in positive correlation with the corresponding second fuzzy radius, i.e. the larger the depth information of the background sub-region is, the larger the second fuzzy radius can be, the farther and the blurry effect can be realized, and the image effect of the background blurred image can be improved.
It should be noted that the sequence of steps 506 to 508 is not limited in the embodiment of the present application, and if the processing may be performed in parallel, or the processing may be performed sequentially, or the processing may be performed before or after the weight mask is generated.
And step 510, taking the weight mask as an Alpha value of the blurred image, and performing Alpha fusion on the blurred image and the background blurring image to obtain a second image.
In some embodiments, the fusion mode of the blurred image and the background blurred image may be Alpha fusion processing, and the Alpha fusion processing may assign an Alpha value to each pixel point in the blurred image and the background blurred image, respectively, so that the blurred image and the background blurred image have different transparencies. The weight mask can be used as an Alpha value of the blurred image, and based on the target weight map, the blurred image and the background blurring image are subjected to Alpha fusion to obtain a second image.
Specifically, Alpha fusion processing is performed on the blurred image and the background blurred image, and a formula of the Alpha fusion processing may be represented by formula (5):
I=αI1+(1-α)I2formula (5);
wherein, I1Representing a blurred image, alpha representing a weight mask, I2Representing a background blurring image, and I representing a second image resulting from the fusion. Further, assuming that the pixel value of each pixel point in the portrait area in the portrait mask is 255 and the pixel value of the pixel point in the background area is 0, the weight value of the portrait clear area in the weight mask is 0, the weight value of the portrait fuzzy transition area is a value which gradually changes within an interval of 0-255, the weight values of other portrait areas except the portrait clear area and the portrait fuzzy transition area are 255, and the value of the pixel point in the background area in the weight mask may be 0. Therefore, the clear face region and the background region in the second image obtained by fusion correspond to the image content in the background blurred image, the other portrait regions except the clear portrait region and the blurred portrait transition region correspond to the image content in the blurred image, the blurred portrait transition region is the fused image content of the background blurred image and the blurred image, and the blurred portrait transition region can present the transition effect from clear to blurred, so that the second image is more natural.
In the embodiment of the application, the face of each portrait main body in the second image can be kept clear, and the portrait areas except the face are kept fuzzy to a smaller extent, so that the portrait refocusing is realized, the problem that all the portrait areas in the image are clear and cause no highlight is caused can be avoided, the situation that only one person is focused and other faces are fuzzy can be avoided, and the image blurring effect is improved.
As shown in fig. 6, in an embodiment, an image processing apparatus 600 is provided, which can be applied to the electronic device described above, and the image processing apparatus 600 can include a face recognition module 610, a weight generation module 620, an image acquisition module 630, and a fusion module 640.
The face recognition module 610 is configured to perform face recognition on the first image to obtain face information of each face included in the first image.
And a weight generating module 620, configured to generate a weight mask according to the face mask and the face information of the first image, where the weight mask is used to determine a face sharp region corresponding to each face in the first image and a face fuzzy transition region corresponding to each face.
The image obtaining module 630 is configured to obtain a blurred image and a background blurred image corresponding to the first image, where a blurring degree of the blurred image is smaller than a blurring degree of a background area in the background blurred image.
And a fusion module 640, configured to fuse the blurred image and the background blurred image according to the weight mask to obtain a second image.
In the embodiment of the application, because the weight mask is marked with the face clear region corresponding to each face in the first image and the face fuzzy transition region corresponding to each face, each face can be kept clear in the second image obtained by fusing the two fuzzy images with different fuzzy degrees and the background blurring image based on the weight mask, and other face regions are gradually transited from clear to fuzzy, so that the problem that no salient point appears due to the fact that all the face regions in the image are clear can be avoided, the image effect is more natural, and the visual display effect of the image is improved. In addition, under the condition that the first image comprises a plurality of faces, each face in the obtained second image can be ensured to be clear, the condition that only one person is focused and other faces are blurred can be avoided, and the image blurring effect is improved.
In one embodiment, the weight generation module 620 includes a clear region determination unit, a distance determination unit, and a normalization unit.
And the clear region determining unit is used for determining a face clear region corresponding to each face in the face mask of the first image according to the face information.
In one embodiment, the face information comprises coordinates of a center point of the face region and a radius of a circumscribed circle of the face region; the face clear area corresponding to each face in the face mask is a circular area taking the central point coordinate of the face area corresponding to each face as a central point and taking the circumscribed circle radius of the face area corresponding to each face as an area radius.
And the distance determining unit is used for respectively determining a first distance between each pixel point of the portrait area in the portrait mask and the central point of the corresponding target face clear area, wherein the target face clear area corresponding to each pixel point of the portrait area is the target face clear area with the closest distance between each pixel point.
In an embodiment, the distance determining unit is further configured to determine, as the first distance, a distance between each pixel point of the portrait area in the portrait mask and a center point of the portrait clear area corresponding to the face, if the first image only includes one face; and the first image is used for determining a target face clear region with the closest distance between each pixel point of the portrait region in the portrait mask and the central point of the corresponding target face clear region if the first image comprises at least two faces, and respectively calculating a first distance between each pixel point of the portrait region and the central point of the corresponding target face clear region.
In one embodiment, the distance determining unit is further configured to calculate a third distance from the target pixel point to each of the face sharp regions according to a second distance between the target pixel point and a center point of each of the face sharp regions and a region radius of each of the face sharp regions, where the target pixel point is any one of pixel points of the face region in the face mask; determining the human image clear area with the minimum third distance as a target human face clear area corresponding to the target pixel point; and the first distance between the target pixel point and the central point of the target face clear region is determined according to the third distance from the target pixel point to the target face region and the region radius of the target face region.
And the normalization unit is used for normalizing the first distance of each pixel point of the portrait area according to the portrait transition range of the target face clear area corresponding to each pixel point of the portrait area in the portrait mask to obtain a normalization value corresponding to each pixel point of the portrait area, and generating a weight mask according to the normalization value and the portrait mask.
In one embodiment, the normalization unit is further configured to determine a portrait transition range corresponding to the target face clear region according to a region radius of the target face clear region corresponding to the target pixel point, where the target pixel point is any pixel point of the portrait region in the portrait mask; calculating a difference value between the first distance of the target pixel point and the area radius, and determining a ratio of the difference value to the portrait transition range; and carrying out normalization processing on the ratio to obtain a normalization value of the target pixel point.
In an embodiment, the normalization unit is further configured to determine that the normalization value of the target pixel point is 0 if the ratio is smaller than 0; if the ratio is larger than 1, determining that the normalization value of the target pixel point is 1; and if the ratio is greater than or equal to 0 and less than or equal to 1, taking the ratio as the normalized value of the target pixel point.
In an embodiment, the normalization unit is further configured to multiply the pixel value of each pixel point of the portrait area in the portrait mask with the normalization value of each pixel point of the portrait area to obtain a weight value corresponding to each pixel point of the portrait area, so as to generate the weight mask.
In one embodiment, the weight generation module 620 includes a fuzzy unit in addition to the clear region determination unit, the distance determination unit, and the normalization unit.
And the blurring unit is used for blurring the weight mask.
The fusion module 640 is further configured to fuse the blurred image and the background blurred image according to the weight mask after the blurring processing, so as to obtain a second image.
In the embodiment of the application, according to the face mask of the first image and the face information of each face in the first image, the corresponding weight mask can be accurately generated, the face clear region and the face fuzzy transition region of each face in the first image are accurately marked through the weight mask, and the visual display effect of the second image obtained by subsequent fusion can be improved.
In an embodiment, the weight generating module 620 is further configured to generate a weight mask according to the portrait mask of the first image, the depth map of the first image, and the face information, where the depth map includes depth information corresponding to each pixel point in the first image.
In an embodiment, the image obtaining module 630 is further configured to perform a blurring process on the first image based on the first blur radius, so as to obtain a blurred image; and blurring the background area of the first image based on the second blurring radius to obtain a background blurring image, wherein the first blurring radius is smaller than the second blurring radius.
In an embodiment, the fusion module 640 is further configured to perform Alpha fusion on the blurred image and the background blurred image by using the weight mask as an Alpha value of the blurred image, so as to obtain a second image.
In the embodiment of the application, the face of each portrait main body in the second image can be kept clear, and the portrait areas except the face are kept fuzzy to a smaller extent, so that the portrait refocusing is realized, the problem that all the portrait areas in the image are clear and cause no highlight is caused can be avoided, the situation that only one person is focused and other faces are fuzzy can be avoided, and the image blurring effect is improved.
Fig. 7 is a block diagram of an electronic device in one embodiment. As shown in fig. 7, electronic device 700 may include one or more of the following components: a processor 710, a memory 720 coupled to the processor 710, wherein the memory 720 may store one or more computer programs that may be configured to be executed by the one or more processors 710 to implement the methods as described in the various embodiments above.
Processor 710 may include one or more processing cores. The processor 710 interfaces with various components throughout the electronic device 700 using various interfaces and circuitry to perform various functions of the electronic device 700 and process data by executing or executing instructions, programs, code sets, or instruction sets stored in the memory 720 and invoking data stored in the memory 720. Alternatively, the processor 710 may be implemented in hardware using at least one of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA). The processor 710 may integrate one or more of a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), a modem, and the like. Wherein, the CPU mainly processes an operating system, a user interface, an application program and the like; the GPU is used for rendering and drawing display content; the modem is used to handle wireless communications. It is understood that the modem may not be integrated into the processor 710, but may be implemented by a communication chip.
The Memory 720 may include a Random Access Memory (RAM) or a Read-Only Memory (ROM). The memory 720 may be used to store instructions, programs, code sets, or instruction sets. The memory 720 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing the various method embodiments described above, and the like. The storage data area may also store data created during use by the electronic device 700, and the like.
It is understood that the electronic device 700 may include more or less structural elements than those shown in the above structural block diagrams, for example, a power module, a physical button, a WiFi (Wireless Fidelity) module, a speaker, a bluetooth module, a sensor, etc., and is not limited thereto.
The embodiment of the application discloses a computer readable storage medium, which stores a computer program, wherein the computer program realizes the method described in the above embodiment when being executed by a processor.
Embodiments of the present application disclose a computer program product comprising a non-transitory computer readable storage medium storing a computer program, and the computer program, when executed by a processor, implements the method as described in the embodiments above.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a non-volatile computer-readable storage medium, and can include the processes of the embodiments of the methods described above when the program is executed. The storage medium may be a magnetic disk, an optical disk, a ROM, etc.
Any reference to memory, storage, database, or other medium as used herein may include non-volatile and/or volatile memory. Suitable non-volatile memory can include ROM, Programmable ROM (PROM), Erasable PROM (EPROM), 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 (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced SDRAM (ESDRAM), Synchlink DRAM (SLDRAM), Rambus Direct RAM (RDRAM), and Direct Rambus DRAM (DRDRAM).
It should be appreciated that reference throughout this specification to "one embodiment" or "an embodiment" means that a particular feature, structure or characteristic described in connection with the embodiment is included in at least one embodiment of the present application. Thus, the appearances of the phrases "in one embodiment" or "in an embodiment" in various places throughout this specification are not necessarily all 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 appreciate that the embodiments described in this specification are all alternative embodiments and that the acts and modules involved are not necessarily required for this application.
In various embodiments of the present application, it should be understood that the size of the serial number of each process described above does not mean that the execution sequence is necessarily sequential, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The foregoing detailed description has provided a detailed description of an image processing method, an image processing apparatus, an electronic device, and a computer-readable storage medium, which are disclosed in the embodiments of the present application, and the detailed description has been provided to explain the principles and implementations of the present application, and the description of the embodiments is only provided to help understanding the method and the core idea of the present application. Meanwhile, for a person skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (15)

1. An image processing method, comprising:
carrying out face recognition on a first image to obtain face information of each face contained in the first image;
generating a weight mask according to the portrait mask of the first image and the face information, wherein the weight mask is used for determining a face clear region corresponding to each face in the first image and a portrait fuzzy transition region corresponding to each face; the face sharp region refers to a region which needs to be kept sharp in a portrait region of the first image, and the portrait fuzzy transition region refers to a change region from sharp to fuzzy in the portrait region;
acquiring a blurred image and a background blurred image corresponding to the first image, wherein the blurring degree of the blurred image is smaller than that of a background area in the background blurred image;
and fusing the blurred image and the background blurring image according to the weight mask to obtain a second image.
2. The method of claim 1, wherein generating a weight mask from the face mask of the first image and the face information comprises:
determining a face clear region corresponding to each face in a face mask of the first image according to the face information;
respectively determining a first distance between each pixel point of a portrait area in the portrait mask and a central point of a corresponding target face clear area, wherein the target face clear area corresponding to each pixel point is the face clear area with the closest distance between each pixel point;
and normalizing the first distance of each pixel point according to the portrait transition range of the target face clear area corresponding to each pixel point to obtain a normalized value corresponding to each pixel point, and generating a weight mask according to the normalized value and the portrait mask.
3. The method of claim 2, wherein the separately determining a first distance between each pixel point of the image region in the image mask and a center point of the corresponding target human face sharp region comprises:
if the first image only contains one face, determining the distance between each pixel point of a portrait area in the portrait mask and the center point of a face clear area corresponding to the face as a first distance;
if the first image comprises at least two faces, determining a target face clear region with the closest distance between each pixel point and calculating a first distance between each pixel point and the central point of the corresponding target face clear region respectively.
4. The method according to claim 3, wherein the determining the target face sharp region with the closest distance between each pixel point and the central point of the corresponding target face sharp region and calculating the first distance between each pixel point and the central point of the corresponding target face sharp region respectively comprises:
calculating a third distance from a target pixel point to each face clear region according to a second distance between the target pixel point and a central point of each face clear region and the region radius of each face clear region, wherein the target pixel point is any pixel point of the face regions in the face mask;
determining the human image clear area with the minimum third distance as a target human face clear area corresponding to the target pixel point;
and determining a first distance between the target pixel point and the central point of the target face clear region according to a third distance from the target pixel point to the target face region and the region radius of the target face region.
5. The method according to any one of claims 2 to 4, wherein the face information comprises coordinates of a center point of a face region and a radius of a circumscribed circle of the face region; the face clear area corresponding to each face in the face mask is a circular area taking the center point coordinate of the face area corresponding to each face as a center point and taking the circumscribed circle radius of the face area corresponding to each face as an area radius.
6. The method according to claim 2, wherein the normalizing the first distance of each pixel point according to the portrait transition range of the target face sharp area corresponding to each pixel point to obtain the normalized value corresponding to each pixel point comprises:
determining a portrait transition range corresponding to a target face clear area according to the area radius of the target face clear area corresponding to the target pixel point, wherein the target pixel point is any pixel point of the portrait area in the portrait mask;
calculating a difference value between a first distance of the target pixel point and the radius of the area, and determining a ratio between the difference value and the portrait transition range;
and carrying out normalization processing on the ratio to obtain a normalization value of the target pixel point.
7. The method according to claim 6, wherein the normalizing the ratio to obtain the normalized value of the target pixel point comprises:
if the ratio is smaller than 0, determining that the normalization value of the target pixel point is 0;
if the ratio is larger than 1, determining that the normalization value of the target pixel point is 1;
and if the ratio is greater than or equal to 0 and less than or equal to 1, taking the ratio as the normalization value of the target pixel point.
8. The method of claim 6 or 7, wherein generating a weight mask from the normalized values and the portrait mask comprises:
and multiplying the pixel value of each pixel point of the portrait area in the portrait mask by the normalized value of each pixel point to obtain a weighted value corresponding to each pixel point so as to generate a weighted mask.
9. The method according to any of claims 2 to 4, wherein after the generating a weight mask from the normalized values and the portrait mask, the method further comprises:
carrying out fuzzy processing on the weight mask;
and the step of fusing the blurred image and the background blurring image according to the weight mask to obtain a second image comprises the following steps:
and fusing the blurred image and the background blurring image according to the weight mask after the blurring processing to obtain a second image.
10. The method of claim 1, wherein generating a weight mask from the face mask of the first image and the face information comprises:
and generating a weight mask according to the portrait mask of the first image, the depth map of the first image and the face information, wherein the depth map comprises depth information corresponding to each pixel point in the first image.
11. The method according to any one of claims 1 to 4, wherein the acquiring the blurred image and the background blurring image corresponding to the first image comprises:
blurring the first image based on a first blurring radius to obtain a blurred image;
blurring the background area of the first image based on a second blurring radius to obtain a background blurring image, wherein the first blurring radius is smaller than the second blurring radius.
12. The method according to any one of claims 1 to 4, wherein the fusing the blurred image and the background blurred image according to the weight mask to obtain a second image comprises:
and taking the weight mask as an Alpha value of the blurred image, and performing Alpha fusion on the blurred image and the background blurring image to obtain a second image.
13. An image processing apparatus characterized by comprising:
the face recognition module is used for carrying out face recognition on the first image so as to obtain face information of each face contained in the first image;
the weight generation module is used for generating a weight mask according to the human image mask of the first image and the human face information, wherein the weight mask is used for determining a human face clear region corresponding to each human face in the first image and a human image fuzzy transition region corresponding to each human face; the face sharp region refers to a region which needs to be kept sharp in a portrait region of the first image, and the portrait fuzzy transition region refers to a change region from sharp to fuzzy in the portrait region;
the image acquisition module is used for acquiring a blurred image and a background blurring image corresponding to the first image, wherein the blurring degree of the blurred image is smaller than that of a background area in the background blurring image;
and the fusion module is used for fusing the blurred image and the background blurring image according to the weight mask to obtain a second image.
14. An electronic device comprising a memory and a processor, the memory having stored thereon a computer program that, when executed by the processor, causes the processor to carry out the method of any one of claims 1 to 12.
15. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1 to 12.
CN202111015385.5A 2021-08-31 2021-08-31 Image processing method, device, electronic equipment and computer readable storage medium Active CN113673474B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111015385.5A CN113673474B (en) 2021-08-31 2021-08-31 Image processing method, device, electronic equipment and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111015385.5A CN113673474B (en) 2021-08-31 2021-08-31 Image processing method, device, electronic equipment and computer readable storage medium

Publications (2)

Publication Number Publication Date
CN113673474A true CN113673474A (en) 2021-11-19
CN113673474B CN113673474B (en) 2024-01-12

Family

ID=78547791

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111015385.5A Active CN113673474B (en) 2021-08-31 2021-08-31 Image processing method, device, electronic equipment and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN113673474B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115223022A (en) * 2022-09-15 2022-10-21 平安银行股份有限公司 Image processing method, device, storage medium and equipment
CN115526809A (en) * 2022-11-04 2022-12-27 山东捷瑞数字科技股份有限公司 Image processing method and device, electronic equipment and storage medium

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107704798A (en) * 2017-08-09 2018-02-16 广东欧珀移动通信有限公司 Image weakening method, device, computer-readable recording medium and computer equipment
CN108234882A (en) * 2018-02-11 2018-06-29 维沃移动通信有限公司 A kind of image weakening method and mobile terminal
WO2019105214A1 (en) * 2017-11-30 2019-06-06 Oppo广东移动通信有限公司 Image blurring method and apparatus, mobile terminal and storage medium
CN111402111A (en) * 2020-02-17 2020-07-10 深圳市商汤科技有限公司 Image blurring method, device, terminal and computer readable storage medium
CN112561822A (en) * 2020-12-17 2021-03-26 苏州科达科技股份有限公司 Beautifying method and device, electronic equipment and storage medium
CN112884637A (en) * 2021-01-29 2021-06-01 北京市商汤科技开发有限公司 Special effect generation method, device, equipment and storage medium
CN112991208A (en) * 2021-03-11 2021-06-18 Oppo广东移动通信有限公司 Image processing method and device, computer readable medium and electronic device

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107704798A (en) * 2017-08-09 2018-02-16 广东欧珀移动通信有限公司 Image weakening method, device, computer-readable recording medium and computer equipment
WO2019105214A1 (en) * 2017-11-30 2019-06-06 Oppo广东移动通信有限公司 Image blurring method and apparatus, mobile terminal and storage medium
CN108234882A (en) * 2018-02-11 2018-06-29 维沃移动通信有限公司 A kind of image weakening method and mobile terminal
CN111402111A (en) * 2020-02-17 2020-07-10 深圳市商汤科技有限公司 Image blurring method, device, terminal and computer readable storage medium
CN112561822A (en) * 2020-12-17 2021-03-26 苏州科达科技股份有限公司 Beautifying method and device, electronic equipment and storage medium
CN112884637A (en) * 2021-01-29 2021-06-01 北京市商汤科技开发有限公司 Special effect generation method, device, equipment and storage medium
CN112991208A (en) * 2021-03-11 2021-06-18 Oppo广东移动通信有限公司 Image processing method and device, computer readable medium and electronic device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
王长城等: "无监督深度学习模型的多聚焦图像融合算法", 《计算机工程与应用》 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115223022A (en) * 2022-09-15 2022-10-21 平安银行股份有限公司 Image processing method, device, storage medium and equipment
CN115223022B (en) * 2022-09-15 2022-12-09 平安银行股份有限公司 Image processing method, device, storage medium and equipment
CN115526809A (en) * 2022-11-04 2022-12-27 山东捷瑞数字科技股份有限公司 Image processing method and device, electronic equipment and storage medium
CN115526809B (en) * 2022-11-04 2023-03-10 山东捷瑞数字科技股份有限公司 Image processing method and device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN113673474B (en) 2024-01-12

Similar Documents

Publication Publication Date Title
CN111402135B (en) Image processing method, device, electronic equipment and computer readable storage medium
CN111741211B (en) Image display method and apparatus
CN110248096B (en) Focusing method and device, electronic equipment and computer readable storage medium
EP3757890A1 (en) Method and device for image processing, method and device for training object detection model
WO2021022983A1 (en) Image processing method and apparatus, electronic device and computer-readable storage medium
CN113888437A (en) Image processing method, image processing device, electronic equipment and computer readable storage medium
CN113766125B (en) Focusing method and device, electronic equipment and computer readable storage medium
WO2021057474A1 (en) Method and apparatus for focusing on subject, and electronic device, and storage medium
CN110149482A (en) Focusing method, device, electronic equipment and computer readable storage medium
CN110191287B (en) Focusing method and device, electronic equipment and computer readable storage medium
CN113313661A (en) Image fusion method and device, electronic equipment and computer readable storage medium
CN113673474B (en) Image processing method, device, electronic equipment and computer readable storage medium
KR20160140453A (en) Method for obtaining a refocused image from 4d raw light field data
CN112017137B (en) Image processing method, device, electronic equipment and computer readable storage medium
WO2022261828A1 (en) Image processing method and apparatus, electronic device, and computer-readable storage medium
CN110881103B (en) Focusing control method and device, electronic equipment and computer readable storage medium
CN113313626A (en) Image processing method, image processing device, electronic equipment and storage medium
CN112836625A (en) Face living body detection method and device and electronic equipment
CN110276831A (en) Constructing method and device, equipment, the computer readable storage medium of threedimensional model
CN110956679A (en) Image processing method and device, electronic equipment and computer readable storage medium
CN113658197B (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
CN113610884A (en) Image processing method, image processing device, electronic equipment and computer readable storage medium
CN113610865A (en) Image processing method, image processing device, electronic equipment and computer readable storage medium
CN113674303A (en) Image processing method, image processing device, electronic equipment and storage medium

Legal Events

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