Methods and devices for face swapping
The face swapping method addresses misalignment and obstruction issues by calculating a face orientation metric for face or head swaps, ensuring clarity and natural appearance, and processing data locally to enhance image quality and security.
Patent Information
- Application Number
- PCT/CN2024/126249
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2024-10-22
- Publication Date
- 2026-04-30
AI Technical Summary
Existing face swapping methods face challenges with discrepancies in lighting, misalignment, and distorted faces due to obstructions, leading to reduced clarity and accuracy in image processing.
A method and system that calculates a face orientation metric to determine whether a face swap or head swap operation is required, preserving resolution and maintaining natural appearance by locally processing data on the device, including features like facial landmark detection, inpainting, and alpha blending.
The method maintains image clarity and natural appearance, allowing face swapping across historical and live images while protecting sensitive information and reducing reliance on cloud computing.
Smart Images

Figure CN2024126249_30042026_PF_FP_ABST
Abstract
Description
METHODS AND DEVICES FOR FACE SWAPPINGFIELD
[0001] The present technology is generally related to image processing, and more specifically, to methods and systems for face swapping.BACKGROUND
[0002] In recent years, the demand for capturing images where each individual is depicted with a desired expression has driven the development of face swapping methods. These methods allow users to replace faces in an image with faces from other images. The growing use of machine learning has played a significant role in enabling these methods.
[0003] In light of these considerations, at least some techniques have been developed to address the challenges associated with aligning faces from different images during face swap operation. Solutions have leveraged machine learning-based models to enhance the accuracy of face detection, matching, and transformation.
[0004] Despite recent advancements, limitations persist, such as discrepancies in lighting, misalignment, and distorted face in the output image due to obstructions that block portions the face.SUMMARY
[0005] Developers of the present technology have designed a method and a system that may tackle some of the challenges of the face swap operation. This method includes the calculation of a face orientation metric based on which the system determines whether a face swap operation is feasible or whether a head swap operation, which processes a larger area of the image compared to face swap operation, is required.
[0006] The present technology may have a variety of advantages. Some embodiments of the present technology may offer resolution preservation, that is, the images with swapped faces may retain the same level of clarity and detail compared to the original images. Additionally, the present technology may maintain the natural appearance of the swapped face, even in scenarios where an external object blocks at least a portion of the face. Furthermore, some embodiments of the present technology may allow for face swapping across historical images and live images. Furthermore, some embodiments of the present technology may process all data locally on the device, without the need for cloud-based computing. Processing all data locally on the device may protect sensitive personal information and reduce reliance on external computing resources.
[0007] Some implementations of the present technology can be used by social media platforms and image editing applications.
[0008] In a first broad aspect of the present technology, there is provided a method for performing head swap operation in an image, the method executable by a processor. The method comprises acquiring a destination image and a source image; detecting an individual in the destination image and the source image, the detecting including generating: a first bounding box including a first set of pixels associated with a face of the individual with a first face orientation in the destination image, a second bounding box including a second set of pixels associated with the face of the individual with a second face orientation in the source image; comparing the first face orientation against the second face orientation; in response to a difference between the first face orientation and the second face orientation being above a first threshold, generating a first enlarged bounding box and a second enlarged bounding box, the first enlarged bounding box including an enlarged first set of pixels, the second enlarged bounding box including an enlarged second set of pixels; generating a first modified image based on the destination image and the enlarged second set of pixels from the source image; and triggering display of the first modified image on a device.
[0009] In some embodiments of the method, the destination image and the source image are from a sequence of images captured by the device.
[0010] In some embodiments of the method, comparing the first face orientation against the second face orientation comprises: determining at least one of yaw, pitch, and roll parameters of the face of the individual with the first face orientation in the destination image; and determining at least one of yaw, pitch, and roll parameters of the face of the individual with the second face orientation in the source image.
[0011] In some embodiments of the method, the first enlarged bounding box further includes pixels associated with a first anchoring portion associated with the individual in the destination image; the second enlarged bounding box further includes pixels associated with a second anchoring portion associated with the individual in the source image. The method further comprises: in response to a difference between the first face orientation and the second face orientation being above a first threshold, comparing the first anchoring portion and the second anchoring portion; and in response to a difference between the first anchoring portion and the second anchoring portion being below a second threshold, generating the first modified image.
[0012] In some embodiments of the method, the first anchoring portion includes a first portion of clothing of the individual in the destination image, and the second anchoring portion includes a second portion of clothing of the individual in the source image.
[0013] In some embodiments of the method, the method further comprises: in response to the difference between the first face orientation and the second face orientation being below the first threshold, determining a set of facial landmarks on the face of the individual in the source image; aligning the face of the individual in the source image with the face of the individual in the destination image based on the determined facial landmarks; segmenting an obstruction on the face of the individual in the destination image; and generating a second modified image based on the destination image, the segmented obstruction, and the aligned face of the individual in the source image.
[0014] In some embodiments of the method, the comparing the first anchoring portion and the second anchoring portion includes: segmenting the first anchoring portion from the destination image and the second anchoring portion from the source image; and determining a number of matched points between the segmented portions corresponding to the first anchoring portion and the second anchoring portion, the number of matched points being indicative of how similar the first anchoring portion is with the second anchoring portion.
[0015] In some embodiments of the method, the generating the first modified image further comprises: positioning the enlarged second set of pixels relative to the destination image using the segmented portions corresponding to the first anchoring portion and the second anchoring portion.
[0016] In some embodiments of the method, the generating the first modified image further comprises: generating one or more synthetic pixels for the modified image by executing an inpainting procedure.
[0017] In some embodiments of the method, the method further comprises: performing alpha blending on the first modified image to adjust transparency levels of pixels associated with the first modified image.
[0018] In a second broad aspect of the present technology, there is provided an electronic device comprising a non-transitory computer-readable medium and a processor, the non-transitory computer-readable medium comprising instructions, which upon being executed by the processor, configure the processor to: acquire a destination image and a source image; detect an individual in the destination image and the source image, the detection including generating: a first bounding box including a first set of pixels associated with a face of the individual with a first face orientation in the destination image, a second bounding box including a second set of pixels associated with the face of the individual with a second face orientation in the source image; compare the first face orientation against the second face orientation; in response to a difference between the first face orientation and the second face orientation being above a first threshold, generate a first enlarged bounding box and a second enlarged bounding box, the first enlarged bounding box including an enlarged first set of pixels, the second enlarged bounding box including an enlarged second set of pixels; generate a first modified image based on the destination image and the enlarged second set of pixels from the source image; and trigger display of the first modified image on a device.
[0019] In some embodiments of the electronic device, the destination image and the source image are from a sequence of images captured by a user of a device.
[0020] In some embodiments of the electronic device, comparing the first face orientation against the second face orientation comprises: determining at least one of yaw, pitch, and roll parameters of the face of the individual with the first face orientation in the destination image; and determining at least one of yaw, pitch, and roll parameters of the face of the individual with the second face orientation in the source image.
[0021] In some embodiments of the electronic device, the first enlarged bounding box further includes pixels associated with a first anchoring portion associated with the individual in the destination image; the second enlarged bounding box further includes pixels associated with a second anchoring portion associated with the individual in the source image; and wherein the processor is further configured to: in response to a difference between the first face orientation and the second face orientation being above a first threshold, compare the first anchoring portion and the second anchoring portion; and in response to a difference between the first anchoring portion and the second anchoring portion being below a second threshold, generate the first modified image.
[0022] In some embodiments of the electronic device, the first anchoring portion includes a first portion of clothing of the individual in the destination image, and the second anchoring portion includes a second portion of clothing of the individual in the source image.
[0023] In some embodiments of the electronic device, the processor is further configured to: in response to the difference between the first face orientation and the second face orientation being below the first threshold, determine a set of facial landmarks on the face of the individual in the source image; align the face of the individual in the source image with the face of the individual in the destination image based on the determined facial landmarks; segment an obstruction on the face of the individual in the destination image; and generate a second modified image based on the destination image, the segmented obstruction, and the aligned face of the individual in the source image.
[0024] In some embodiments of the electronic device, the comparing the first anchoring portion and the second anchoring portion includes: segmenting the first anchoring portion from the destination image and the second anchoring portion from the source image; and determining a number of matched points between the segmented portions corresponding to the first anchoring portion and the second anchoring portion, the number of matched points being indicative of how similar the first anchoring portion is with the second anchoring portion.
[0025] In some embodiments of the electronic device, the generating the first modified image further comprises: positioning the enlarged second set of pixels relative to the destination image using the segmented portions corresponding to the first anchoring portion and the second anchoring portion.
[0026] In some embodiments of the electronic device, the generating the first modified image further comprises: generating one or more synthetic pixels for the modified image by executing an inpainting procedure.
[0027] In some embodiments of the electronic device, the processor is further configured to: perform alpha blending on the first modified image to adjust transparency levels of pixels associated with the first modified image.
[0028] In another broad aspect, there is provided one or more non-transitory, computer-readable storage media comprising computer-executable instructions, wherein the instructions, when executed, cause one or more processors to: acquire a destination image and a source image; detect an individual in the destination image and the source image, the detection including generating: a first bounding box including a first set of pixels associated with a face of the individual with a first face orientation in the destination image, a second bounding box including a second set of pixels associated with the face of the individual with a second face orientation in the source image; compare the first face orientation against the second face orientation; in response to a difference between the first face orientation and the second face orientation being above a first threshold, generate a first enlarged bounding box and a second enlarged bounding box, the first enlarged bounding box including an enlarged first set of pixels, the second enlarged bounding box including an enlarged second set of pixels; generate a first modified image based on the destination image and the enlarged second set of pixels from the source image; and trigger display of the first modified image on a device.
[0029] In the context of the present technology, “face swap” operation refers to the process of replacing an individual’s face in an image with a face from another image.
[0030] In the context of the present technology, “head swap” operation refers to the process of replacing a larger portion of the image, including the entire head, rather than just the face.
[0031] In the context of the present technology, “pixels” refer to the smallest units of an image, representing a specific color or intensity.
[0032] In the context of the present technology, a “convex hull mask” refers to a mask that outlines the boundary around curved facial features, such as the jawline.
[0033] In the context of the present technology, “inpainting” refers to a method used to fill in missing parts of an image by generating new pixels.
[0034] In the context of the present technology, “facial landmark” refers to points on parts of a human face, such as the eyes, nose, mouth, and jawline, which are used to identify facial features.
[0035] In the context of the present technology, “semantic segmentation” refers to a method for categorizing different parts of an image, such as face, hair, clothing etc.
[0036] In the context of the present technology, “live image” refers to an image format that captures several frames rather than just a single frame.
[0037] In the context of the present technology, “face blocking” refers to scenarios where parts of the face in an image are obscured by external objects, such as hair, fingers, hands, glasses etc.
[0038] In the context of the present technology, “historical image” refers to a previously captured image.
[0039] In the context of the present technology, “source image” refers to an image that contains the face or head that will be swapped into the face or head contained in another image.
[0040] In the context of the present technology, “destination image” refers to an image that contains the face or head that will be replaced or modified by the face or head contained in another image.
[0041] In the context of the present technology, “alpha blending” refers to a method used to combine the pixels of two images by adjusting their transparency levels.
[0042] In the context of the present technology, “Scale-Invariant Feature Transform (SIFT) ” matching refers to a method used to compare objects from two images, such as clothing or features around the head.
[0043] In the context of the present technology, “affine transformation” refers to a method used to modify an image by scaling, rotating, translating, or skewing objects, while preserving straight lines and proportional relationships between those objects. This transformation allows for non-uniform scaling, meaning that different dimensions of an object can be scaled by different amounts.
[0044] In the context of the present technology, “similarity transform matrix” refers to a matrix that is used to modify an image by uniformly scaling, rotating, and translating it, while preserving the angles and proportions between objects. Unlike affine transformation, it ensures that the shape of an object, for example, a face or a head remains unchanged.
[0045] In the context of the present specification, a “server” is a computer program that is running on appropriate hardware and is capable of receiving requests (e.g., from devices) over a network, and carrying out those requests, or causing those requests to be carried out. The hardware may be one physical computer or one physical computer system, but neither is required to be the case with respect to the present technology. In the present context, the use of the expression a “server” is not intended to mean that every task (e.g., received instructions or requests) or any particular task will have been received, carried out, or caused to be carried out, by the same server (i.e., the same software and / or hardware) ; it is intended to mean that any number of software elements or hardware devices may be involved in receiving / sending, carrying out or causing to be carried out any task or request, or the consequences of any task or request; and all of this software and hardware may be one server or multiple servers, both of which are included within the expression “at least one server” .
[0046] In the context of the present specification, “device” is any computer hardware that is capable of running software appropriate to the relevant task at hand. Thus, some (non-limiting) examples of devices include personal computers (desktops, laptops, netbooks, etc. ) , smartphones, and tablets, as well as network equipment such as routers, switches, and gateways. It should be noted that a device acting as a device in the present context is not precluded from acting as a server to other devices. The use of the expression “adevice” does not preclude multiple devices being used in receiving / sending, carrying out or causing to be carried out any task or request, or the consequences of any task or request, or steps of any method described herein.
[0047] In the context of the present specification, a “database” is any structured collection of data, irrespective of its particular structure, the database management software, or the computer hardware on which the data is stored, implemented or otherwise rendered available for use. A database may reside on the same hardware as the process that stores or makes use of the information stored in the database or it may reside on separate hardware, such as a dedicated server or plurality of servers. It can be said that a database is a logically ordered collection of structured data kept electronically in a computer system.
[0048] In the context of the present specification, the expression “information” includes information of any nature or kind whatsoever capable of being stored in a database. Thus, information includes, but is not limited to audiovisual works (images, movies, sound records, presentations etc. ) , data (location data, numerical data, etc. ) , text (opinions, comments, questions, messages, etc. ) , documents, spreadsheets, lists of words, etc.
[0049] In the context of the present specification, the expression “component” is meant to include software (appropriate to a particular hardware context) that is both necessary and sufficient to achieve the specific function (s) being referenced.
[0050] In the context of the present specification, the expression “computer usable information storage medium” is intended to include media of any nature and kind whatsoever, including RAM, ROM, disks (CD-ROMs, DVDs, floppy disks, hard drivers, etc. ) , USB keys, solid state-drives, tape drives, etc.
[0051] In the context of the present specification, the words “first” , “second” , “third” , etc. have been used as adjectives only for the purpose of allowing for distinction between the nouns that they modify from one another, and not for the purpose of describing any particular relationship between those nouns. Thus, for example, it should be understood that, the use of the terms “first server” and “third server” is not intended to imply any particular order, type, chronology, hierarchy or ranking (for example) of / between the server, nor is their use (by itself) intended imply that any “second server” must necessarily exist in any given situation. Further, as is discussed herein in other contexts, reference to a “first” element and a “second” element does not preclude the two elements from being the same actual real-world element. Thus, for example, in some instances, a “first” server and a “second” server may be the same software and / or hardware, in other cases they may be different software and / or hardware.
[0052] Implementations of the present technology each have at least one of the above-mentioned object and / or aspects, but do not necessarily have all of them. It should be understood that some aspects of the present technology that have resulted from attempting to attain the above-mentioned object may not satisfy this object and / or may satisfy other objects not specifically recited herein.
[0053] Additional and / or alternative features, aspects and advantages of implementations of the present technology will become apparent from the following description, the accompanying drawings and the appended claims.BRIEF DESCRIPTION OF THE DRAWINGS
[0054] For a better understanding of the present technology, as well as other aspects and further features thereof, reference is made to the following description which is to be used in conjunction with the accompanying drawings, where:
[0055] FIG. 1 illustrates an example of a computing device that may be used to implement any of the methods described herein.
[0056] FIG. 2 illustrates a workflow for performing face swap operation or head swap operation in images, in accordance with at least some non-limiting embodiments of the present technology.
[0057] FIG. 3 illustrates a decision process for displaying, rejecting, and storing results of the face swap operation or the head swap operation based on the success of the swap, in accordance with at least some non-limiting embodiments of the present technology.
[0058] FIG. 4 is a scheme-block illustration of a method executed by a processor of the computing device of FIG. 1, in accordance with at least some non-limiting embodiments of the present technology.DETAILED DESCRIPTION
[0059] The examples and conditional language recited herein are principally intended to aid the reader in understanding the principles of the present technology and not to limit its scope to such specifically recited examples and conditions. It will be appreciated that those skilled in the art may devise various arrangements which, although not explicitly described or shown herein, nonetheless embody the principles of the present technology and are included within its spirit and scope.
[0060] Furthermore, as an aid to understanding, the following description may describe relatively simplified implementations of the present technology. As persons skilled in the art would understand, various implementations of the present technology may be of a greater complexity.
[0061] In some cases, what are believed to be helpful examples of modifications to the present technology may also be set forth. This is done merely as an aid to understanding, and, again, not to define the scope or set forth the bounds of the present technology. These modifications are not an exhaustive list, and a person skilled in the art may make other modifications while nonetheless remaining within the scope of the present technology. Further, where no examples of modifications have been set forth, it should not be interpreted that no modifications are possible and / or that what is described is the sole manner of implementing that element of the present technology.
[0062] Moreover, all statements herein reciting principles, aspects, and implementations of the present technology, as well as specific examples thereof, are intended to encompass both structural and functional equivalents thereof, whether they are currently known or developed in the future. Thus, for example, it will be appreciated by those skilled in the art that any block diagrams herein represent conceptual views of illustrative circuitry embodying the principles of the present technology. Similarly, it will be appreciated that any flowcharts, flow diagrams, state transition diagrams, pseudo-code, and the like represent various processes which may be substantially represented in computer-readable media and so executed by a computer or processor, whether or not such computer or processor is explicitly shown.
[0063] The functions of the various elements shown in the figures, including any functional block labeled as a “processor” , may be provided through the use of dedicated hardware as well as hardware capable of executing software in association with appropriate software. When provided by a processor, the functions may be provided by a single dedicated processor, by a single shared processor, or by a plurality of individual processors, some of which may be shared. In some embodiments of the present technology, the processor may be a general purpose processor, such as a central processing unit (CPU) or a processor dedicated to a specific purpose, such as a digital signal processor (DSP) . Moreover, explicit use of the term a “processor” should not be construed to refer exclusively to hardware capable of executing software, and may implicitly include, without limitation, application specific integrated circuit (ASIC) , field programmable gate array (FPGA) , read-only memory (ROM) for storing software, random access memory (RAM) , and non-volatile storage. Other hardware, conventional and / or custom, may also be included.
[0064] Software modules, or simply modules which are implied to be software, may be represented herein as any combination of flowchart elements or other elements indicating performance of process steps and / or textual description. Such modules may be executed by hardware that is expressly or implicitly shown. Moreover, it should be understood that module may include for example, but without being limitative, computer program logic, computer program instructions, software, stack, firmware, hardware circuitry or a combination thereof which provides the required capabilities.
[0065] With these fundamentals in place, we will now consider some non-limiting examples to illustrate various implementations of aspects of the present technology.
[0066] FIG. 1 illustrates a diagram of a computing environment 100 in accordance with an embodiment of the present technology is shown. In some embodiments, the computing environment 100 may be implemented by any of a conventional personal computer, a computer dedicated to operating and / or monitoring systems relating to a data center, a controller and / or an electronic device (such as, but not limited to, a mobile device, a tablet device, a server, a controller unit, a control device, a monitoring device etc. ) and / or any combination thereof appropriate to the relevant task at hand. In some embodiments, the computing environment 100 comprises various hardware components including one or more single or multi-core processors collectively represented by a processor 110, a solid-state drive 120, a random access memory 130 and an input / output interface 150.
[0067] In some embodiments, the computing environment 100 may also be a sub-system of one of the above-listed systems. In some other embodiments, the computing environment 100 may be an “off the shelf” generic computer system. In some embodiments, the computing environment 100 may also be distributed amongst multiple systems. The computing environment 100 may also be specifically dedicated to the implementation of the present technology. As a person in the art of the present technology may appreciate, multiple variations as to how the computing environment 100 is implemented may be envisioned without departing from the scope of the present technology.
[0068] Communication between the various components of the computing environment 100 may be enabled by one or more internal and / or external buses 160 (e.g. a PCI bus, universal serial bus, IEEE 1394 “Firewire” bus, SCSI bus, Serial-ATA bus, ARINC bus, etc. ) , to which the various hardware components are electronically coupled.
[0069] The input / output interface 150 may allow enabling networking capabilities such as wire or wireless access. As an example, the input / output interface 150 may comprise a networking interface such as, but not limited to, a network port, a network socket, a network interface controller and the like. Multiple examples of how the networking interface may be implemented will become apparent to the person skilled in the art of the present technology. For example, but without being limitative, the networking interface may implement specific physical layer and data link layer standard such as Ethernet, Fibre Channel, Wi-Fi or Token Ring. The specific physical layer and the data link layer may provide a base for a full network protocol stack, allowing communication among small groups of computers on the same local area network (LAN) and large-scale network communications through routable protocols, such as Internet Protocol (IP) .
[0070] According to implementations of the present technology, the solid-state drive 120 stores program instructions suitable for being loaded into the random access memory 130 and executed by the processor 110 for executing operating data centers based on a generated machine learning pipeline. For example, the program instructions may be part of a library or an application.
[0071] In some embodiments of the present technology, the computing environment 100 may be implemented as part of a cloud computing environment. Broadly, a cloud computing environment is a type of computing that relies on a network of remote servers hosted on the internet, for example, to store, manage, and process data, rather than a local server or personal computer. This type of computing allows users to access data and applications from remote locations, and provides a scalable, flexible, and cost-effective solution for data storage and computing. Cloud computing environments can be divided into three main categories: Infrastructure as a Service (IaaS) , Platform as a Service (PaaS) , and Software as a Service (SaaS) . In an IaaS environment, users can rent virtual servers, storage, and other computing resources from a third-party provider, for example. In a PaaS environment, users have access to a platform for developing, running, and managing applications without having to manage the underlying infrastructure. In a SaaS environment, users can access pre-built software applications that are hosted by a third-party provider, for example. In summary, cloud computing environments offer a range of benefits, including cost savings, scalability, increased agility, and the ability to quickly deploy and manage applications.
[0072] FIG. 2 illustrates a workflow 200 for performing face swap operation 300 or head swap operation 400 in images, in accordance with at least some non-limiting embodiments of the present technology.
[0073] The process begins with the selection of an image 201 with one or more faces by a user, referred to as the destination image. This destination image serves as the base image where faces from other images, referred to as source images, are to be swapped in.
[0074] In this embodiment, the processor 110 with reference to FIG. 1 processes a set of query images 202, which includes both live images and historical images. One image from these query images serves as the source image for the face swap operation or the head swap operation.
[0075] The processor 110 proceeds with face detection 203 and face matching 204. During this stage, the processor 110 detects faces in both the destination and query images and groups the faces by individual identity through a matching process, creating sets of grouped faces 205, where each group corresponds to a unique individual.
[0076] Once the faces have been grouped, the user selects a face from one group to be used as the source face. The image to which the source face belongs may be referred to as the source image. Next, the processor 110 generates bounding boxes 206 around the face 208 from the destination image 201 and the source face 207. The face 208 may be referred to as the destination face. The bounding boxes are used to identify areas which will be processed by the processor 110 to compute a face orientation metric 209. This metric evaluates the difference in orientations of the faces 207 and 208 by analyzing their yaws, pitches, and roll parameters. A higher value of the face orientation metric indicates a greater degree of variation between the source face 207 and the destination face 208.
[0077] The processes of face detection 203, face matching 204, and calculating the face orientation metric 209 can be performed using models within the Huawei Artificial Intelligence (HiAI) framework or other suitable machine learning models. The HiAI framework includes a variety of machine learning-based models designed for image processing. For example, face detection and matching can be carried out by a combination of machine learning models that identify and group faces across multiple images. The calculation of the face orientation metric may be performed by machine learning models capable of classifying and determining the similarity of facial orientations between two images.
[0078] The face orientation metric is used by the processor 110 to determine whether to proceed with face swap operation 300 or head swap operation 400. If the face orientation metric is below a predetermined threshold, the processor 110 initiates face swap operation 300. If the face orientation metric is above the threshold, indicating significant variation between the two faces, the processor 110 proceeds to head swap 400 operation.
[0079] For face swap operation 300, the processor 110 uses a facial landmark detection model 301 to identify key facial features of the source face 207. This step can be performed by the Huawei HiAI 276-Facial Landmark Model or other suitable machine learning models. In the case of the HiAI model, 270 facial points may be detected, indicating the face contour, eyebrows, eyes, mouth, and nose.
[0080] The facial points are used by the processor 110 to create a similarity transform matrix that aligns and transforms the source face 207 to match the size and rotation of the destination face 208. The processor 110 averages key points for areas like the eyebrows and mouth, while lower bound points are chosen for the eyes. The lower bound points refer to the points located on the lower part of the eye socket. The lower bound points tend to have smaller displacement variations compared to the points located on the upper part of the eye socket, particularly in cases where an opened eye in the source face needs to be pasted onto a closed eye in the destination face, or vice versa. An affine transformation, guided by Least Median of Squares, is then applied by the processor 110 to the source face 207, improving alignment accuracy by focusing on inlier points.
[0081] Once the alignment is achieved, the processor 110 performs semantic segmentation 302 of both the transformed source face 270 and the destination face 208 to identify different regions, such as hair 304 and 341, facial regions 305 and 350, clothing 306 and 360, and any other objects that may be present in the images. Thus, the processor 110 can identify obstructions, such as hair, glasses, or hand gestures etc. that may block parts of the facial region 305 in 208. The segmentation can be performed by the Huawei HiAI framework or similar machine learning models.
[0082] Next, the processor 110 generates masks to isolate the facial region 305 in 208 by excluding the hair, body, and any other objects that may be present in 208. To achieve this, the processor 110 combines a mask focusing solely on the facial region 305 with a convex hull mask based on the landmark points on the jawline in 208. This combined mask contains only the facial region from 208 without any obstructions.
[0083] By detecting the obstruction and generating the combined mask which shows only the facial region from 208 without any obstruction, the processor 110 isolates the facial region from any obstruction. In subsequent processing, this isolation helps the obstruction on the destination face 208 to be preserved without any change and be integrated with the swapped face.
[0084] Next, the processor 110 applies color matching and alpha blending 303. Color matching is applied by the processor 110 to adjust the skin tone and lighting of the region 350 from the transformed source face 270, so that it blends with the lighting conditions of the destination face 208. After color matching, the processor 110 applies alpha blending to merge the region 350 from the source face 270 into the region 305 from the destination face 208 to generate the swapped face 3000. Furthermore, alpha blending adjusts the transparency levels of the pixels in the destination image with the swapped face. During alpha blending, any obstruction on the destination face detected by segmentation 302 remains unchanged.
[0085] For the head swap operation 400, the processor 110 enlarges the bounding boxes 401 around both the source face 207 and destination face 208 to encompass not only the faces but also the heads, including hair, necks, and clothing. This enlarged context is helpful for head swap operation in cases where face swap operation would not produce satisfactory results.
[0086] Next, the processor 110 performs segmentation 402 on 207 and 208 to identify the heads and other relevant features, such as hair and clothing.
[0087] In certain cases, the results of the segmentation 402 may cause the processor 110 to determine that the faces of different individuals in the image 201 are positioned too closely together, as indicated by 405. In such cases, the processor 110 determines that head swap operation is not feasible, and proceeds to an exit 407.
[0088] Otherwise, the processor 110 identifies an inpainting area 404 in the destination image 201 after the segmentation 402. This inpainting area 404 represents parts of the destination image 201 which would be missing due to head swap operation, particularly when the head orientations between the source and destination images differ. For example, if the head in the source image (referred to as source head) is turned at a different angle than the head in the destination image (referred to as the destination head) , certain parts of the head or background in the destination image 201 may need to be inpainted.
[0089] Once the segmentation is complete, the processor 110 conducts SIFT matching 403, a method used to match corresponding areas or points of the clothing between the source and destination images.
[0090] In SIFT matching, if the number of matched points is lesser than a predetermined number of points, both the source image and the destination image undergo preprocessing, and SIFT matching is repeated for a predetermined number of iterations.
[0091] If the number of matched points is lesser than the predetermined number of points after repeating the SIFT matching for the predetermined number of iterations, the processor 110 determines that the clothing in the source and destination images are too dissimilar, marks the case as unqualified 406, and proceeds to an exit 407.
[0092] If the number of matched points is higher than the predetermined number of points after any number of SIFT matching iteration, the processor 110 performs head swap 410 by applying a similarity transform matrix to the source head to align the source head with the destination head. The processor 110 may generate the similarity transform matrix using various methods, for example, a facial landmark detection model, SIFT matching etc. To further refine the alignment, the processor 110 applies graph cut algorithm to accurately align the edges of the head and surrounding regions.
[0093] Next, alpha blending 408 is performed by the processor 110 to merge the source head into the destination head.
[0094] Finally, inpainting 409 is performed by the processor 110 to fill the inpainting area by generating synthetic pixels and generate the swapped head 4000.
[0095] FIG. 3 illustrates a decision process for displaying, rejecting, and storing results of the face swap operation or the head swap operation based on the success of the swap, in accordance with at least some non-limiting embodiments of the present technology.
[0096] In this embodiment, the process 500 begins with a check for a successful face swap operation 501 by the processor 110. If the face swap operation is successful, the processor 110 proceeds to display the result, as indicated by 503. If the face swap operation is unsuccessful, the processor 110 evaluates whether a successful head swap operation 506 can be performed. If the head swap operation is successful, the processor 110 displays the result, as indicated by 503.
[0097] If neither the face swap operation nor the head swap operation is successful, the processor 110 does not display any result, as indicated by 502.
[0098] Once the result of either face swap operation or head swap operation is displayed 503, the processor 110 passes the result through the user interface (UI) 504. The UI allows the user to interact with and review the swapped face or head. Following this, the final step is the storage 505 of the processed image, where the result is saved by the processor 110 for future use or sharing.
[0099] In some embodiments of the present technology, the processor 110 is configured to execute a method 1000 for head swap operation. A scheme-block illustration of operations of the method 1000 is depicted in FIG. 4. In one or more aspects, the method 1000 or one or more steps thereof may be performed by the processor 110 of the computer system 100. The method 1000 or one or more steps thereof may be embodied in computer-executable instructions that are stored in a computer-readable medium, such as a non-transitory mass storage device, loaded into memory and executed by a CPU. Some steps or portions of steps in the flow diagram may be omitted or changed in order.
[0100] The method 1000 starts with acquiring, at operation 1001, a destination image and a source image. For example, with reference to FIG. 2, the processor 110 may be configured to acquire the destination image 201 and a source image from the set of query images 202.
[0101] The method 1000 continues with detecting, at operation 1002, an individual in the destination image and the source image, the detecting including generating: a first bounding box including a first set of pixels associated with a face of the individual with a first face orientation in the destination image, a second bounding box including a second set of pixels associated with the face of the individual with a second face orientation in the source image. For example, with reference to FIG. 2, the processor 110 may be configured to generate bounding boxes around the face 208 from the destination image 201 and the source face 207.
[0102] The method 1000 continues with comparing, at operation 1003, the first face orientation against the second face orientation. For example, with reference to FIG. 2, the processor 110 may be configured to compute a face orientation metric 209. This metric evaluates the difference in orientations of the faces 207 and 208 by analyzing their yaws, pitches, and roll parameters. A higher value of the face orientation metric indicates a greater degree of variation between the source face 207 and the destination face 208.
[0103] The method 1000 continues with generating, at operation 1004, in response to a difference between the first face orientation and the second face orientation being above a first threshold, a first enlarged bounding box and a second enlarged bounding box, the first enlarged bounding box including an enlarged first set of pixels, the second enlarged bounding box including an enlarged second set of pixels. For example, with reference to FIG. 2, the processor 110 may be configured to enlarge the bounding boxes around both the source face 207 and destination face 208 to encompass not only the faces but also the heads, including hair, necks, and clothing.
[0104] The method 1000 continues with generating, at operation 1005, a first modified image based on the destination image and the enlarged second set of pixels from the source image. For example, with reference to FIG. 2, the processor 110 may be configured to perform segmentation 402 on 207 and 208, identify an inpainting area 404 in the destination image 201, perform SIFT matching 403 to match corresponding areas or points of the clothing between the source and destination images, generate a similarity transform matrix using various methods, for example, a facial landmark detection model, SIFT matching etc., and apply the similarity transform matrix to the source head to align the source head with the destination head, apply graph cut algorithm to accurately align the edges of the head and surrounding regions, perform alpha blending 408 to merge the source head into the destination head, and perform inpainting 409 to fill the inpainting area by generating synthetic pixels and thereby generate the swapped head 4000.
[0105] The method 1000 continues with triggering, at operation 1006, display of the first modified image on a device. For example, with reference to FIG. 3, for a successful head swap operation, the processor 110 may be configured to display the result, as indicated by 503.
[0106] While the above-described implementations have been described and shown with reference to particular operations performed in a particular order, it will be understood that these steps may be combined, sub-divided, or re-ordered without departing from the teachings of the present technology. At least some of the steps may be executed in parallel or in series. Accordingly, the order and grouping of the steps is not a limitation of the present technology.
[0107] It will be appreciated that at least some of the operations of the method 1000 may also be performed by computer programs, which may exist in a variety of forms, both active and inactive. Such as, the computer programs may exist as software program (s) comprised of program instructions in source code, object code, executable code or other formats. Any of the above may be embodied on a computer readable medium, which include storage devices and signals, in compressed or uncompressed form. Representative computer readable storage devices include conventional computer system RAM (random access memory) , ROM (read only memory) , EPROM (erasable, programmable ROM) , EEPROM (electrically erasable, programmable ROM) , and magnetic or optical disks or tapes. Representative computer readable signals, whether modulated using a carrier or not, are signals that a computer system hosting or running the computer program may be configured to access, including signals downloaded through the Internet or other networks. Concrete examples of the foregoing include distribution of the programs on a CD ROM or via Internet download. In a sense, the Internet itself, as an abstract entity, is a computer readable medium. The same is true of computer networks in general.
[0108] It should be expressly understood that not all technical effects mentioned herein need to be enjoyed in each and every embodiment of the present technology.
[0109] Modifications and improvements to the above-described implementations of the present technology may become apparent to those skilled in the art. The foregoing description is intended to be exemplary rather than limiting. The scope of the present technology is therefore intended to be limited solely by the scope of the appended claims.
Claims
1.A method, comprising:acquiring a destination image and a source image;detecting an individual in the destination image and the source image, the detecting including generating:a first bounding box including a first set of pixels associated with a face of the individual with a first face orientation in the destination image,a second bounding box including a second set of pixels associated with the face of the individual with a second face orientation in the source image;comparing the first face orientation against the second face orientation;in response to a difference between the first face orientation and the second face orientation being above a first threshold,generating a first enlarged bounding box and a second enlarged bounding box,the first enlarged bounding box including an enlarged first set of pixels,the second enlarged bounding box including an enlarged second set of pixels;generating a first modified image based on the destination image and the enlarged second set of pixels from the source image; andtriggering display of the first modified image on a device.2.The method of claim 1, wherein the destination image and the source image are from a sequence of images captured by the device.3.The method of any one of claims 1 to 2, wherein comparing the first face orientation against the second face orientation comprises:determining at least one of yaw, pitch, and roll parameters of the face of the individual with the first face orientation in the destination image; anddetermining at least one of yaw, pitch, and roll parameters of the face of the individual with the second face orientation in the source image.4.The method of any one of claims 1 to 3, whereinthe first enlarged bounding box further includes pixels associated with a first anchoring portion associated with the individual in the destination image;the second enlarged bounding box further includes pixels associated with a second anchoring portion associated with the individual in the source image;and wherein the method further comprises:in response to a difference between the first face orientation and the second face orientation being above a first threshold,comparing the first anchoring portion and the second anchoring portion; andin response to a difference between the first anchoring portion and the second anchoring portion being below a second threshold, generating the first modified image.5.The method of claim 4, wherein the first anchoring portion includes a first portion of clothing of the individual in the destination image, and the second anchoring portion includes a second portion of clothing of the individual in the source image.6.The method of any one of claims 1 to 5, wherein the method further comprises:in response to the difference between the first face orientation and the second face orientation being below the first threshold,determining a set of facial landmarks on the face of the individual in the source image;aligning the face of the individual in the source image with the face of the individual in the destination image based on the determined facial landmarks;segmenting an obstruction on the face of the individual in the destination image; andgenerating a second modified image based on the destination image, the segmented obstruction, and the aligned face of the individual in the source image.7.The method of any one of claims 4 to 6, wherein the comparing the first anchoring portion and the second anchoring portion includes:segmenting the first anchoring portion from the destination image and the second anchoring portion from the source image; anddetermining a number of matched points between the segmented portions corresponding to the first anchoring portion and the second anchoring portion, the number of matched points being indicative of how similar the first anchoring portion is with the second anchoring portion.8.The method of any one of claims 1 to 7, wherein the generating the first modified image further comprises:positioning the enlarged second set of pixels relative to the destination image using the segmented portions corresponding to the first anchoring portion and the second anchoring portion.9.The method of any one of claims 1 to 8, wherein the generating the first modified image further comprises:generating one or more synthetic pixels for the modified image by executing an inpainting procedure.10.The method of any one of claims 1 to 9, wherein the method further comprises:performing alpha blending on the first modified image to adjust transparency levels of pixels associated with the first modified image.11.An electronic device comprising a non-transitory computer-readable medium and a processor, the non-transitory computer-readable medium comprising instructions, which upon being executed by the processor, configure the processor to:acquire a destination image and a source image;detect an individual in the destination image and the source image, the detection including generating:a first bounding box including a first set of pixels associated with a face of the individual with a first face orientation in the destination image,a second bounding box including a second set of pixels associated with the face of the individual with a second face orientation in the source image;compare the first face orientation against the second face orientation;in response to a difference between the first face orientation and the second face orientation being above a first threshold,generate a first enlarged bounding box and a second enlarged bounding box,the first enlarged bounding box including an enlarged first set of pixels,the second enlarged bounding box including an enlarged second set of pixels;generate a first modified image based on the destination image and the enlarged second set of pixels from the source image; andtrigger display of the first modified image on a device.12.The electronic device of claim 11, wherein the destination image and the source image are from a sequence of images captured by a user of a device.13.The electronic device of any one of claims 11 to 12, wherein comparing the first face orientation against the second face orientation comprises:determining at least one of yaw, pitch, and roll parameters of the face of the individual with the first face orientation in the destination image; anddetermining at least one of yaw, pitch, and roll parameters of the face of the individual with the second face orientation in the source image.14.The electronic device of any one of claims 11 to 13, whereinthe first enlarged bounding box further includes pixels associated with a first anchoring portion associated with the individual in the destination image;the second enlarged bounding box further includes pixels associated with a second anchoring portion associated with the individual in the source image;and wherein the processor is further configured to:in response to a difference between the first face orientation and the second face orientation being above a first threshold,compare the first anchoring portion and the second anchoring portion; andin response to a difference between the first anchoring portion and the second anchoring portion being below a second threshold, generate the first modified image.15.The electronic device of claim 14, wherein the first anchoring portion includes a first portion of clothing of the individual in the destination image, and the second anchoring portion includes a second portion of clothing of the individual in the source image.16.The electronic device of any one of claims 11 to 15, wherein the processor is further configured to:in response to the difference between the first face orientation and the second face orientation being below the first threshold,determine a set of facial landmarks on the face of the individual in the source image;align the face of the individual in the source image with the face of the individual in the destination image based on the determined facial landmarks;segment an obstruction on the face of the individual in the destination image; andgenerate a second modified image based on the destination image, the segmented obstruction, and the aligned face of the individual in the source image.17.The electronic device of any one of claims 14 to 16, wherein the comparing the first anchoring portion and the second anchoring portion includes:segmenting the first anchoring portion from the destination image and the second anchoring portion from the source image; anddetermining a number of matched points between the segmented portions corresponding to the first anchoring portion and the second anchoring portion, the number of matched points being indicative of how similar the first anchoring portion is with the second anchoring portion.18.The electronic device of any one of claims 11 to 17, wherein the generating the first modified image further comprises:positioning the enlarged second set of pixels relative to the destination image using the segmented portions corresponding to the first anchoring portion and the second anchoring portion.19.The electronic device of any one of claims 11 to 18, wherein the generating the first modified image further comprises:generating one or more synthetic pixels for the modified image by executing an inpainting procedure.20.The electronic device of any one of claims 11 to 19, wherein the processor is further configured to:perform alpha blending on the first modified image to adjust transparency levels of pixels associated with the first modified image.21.One or more non-transitory, computer-readable storage media comprising computer-executable instructions, wherein the instructions, when executed, cause one or more processors to:acquire a destination image and a source image;detect an individual in the destination image and the source image, the detection including generating:a first bounding box including a first set of pixels associated with a face of the individual with a first face orientation in the destination image,a second bounding box including a second set of pixels associated with the face of the individual with a second face orientation in the source image;compare the first face orientation against the second face orientation;in response to a difference between the first face orientation and the second face orientation being above a first threshold,generate a first enlarged bounding box and a second enlarged bounding box,the first enlarged bounding box including an enlarged first set of pixels,the second enlarged bounding box including an enlarged second set of pixels;generate a first modified image based on the destination image and the enlarged second set of pixels from the source image; andtrigger display of the first modified image on a device.
Citation Information
Patent Citations
Image fusion method and device and computer storage medium
CN108876718A
Face changing recognition method, device and equipment and computer readable storage medium
CN112116525A
Face image processing method and device
CN114612291A
Image face changing method based on feature mark training strategy
CN115019223A
Method for improving quality of face transformation by using image blending
WO2024147462A1