Face Migration in Classical Artwork
I. Motivation
In project 3 (a project on the topic of gradient domain editing), we implemented texture style transfer, learning how to transfer the "drawing style" from one picture to another based on pixel intensity. Given the creative perspective of this notion, we want to incorporate additional techniques not yet covered in class projects, such as object averaging (morphing), image warping, matting, and hole-filling, to create a pipeline for “Face Migration in Classical Artwork.”
Our inspiration comes from a creative rendition of Vermeer’s “Girl with a Pearl Earring” (shown in Figure 1), where the girl's face is replaced with that of an oil-paint cat. This gave us the idea of seamlessly merging objects from one classical artwork into the scene or objects of another. Our primary objective is to facilitate face-to-face swaps that do more than just blend faces; we also want to apply texture transfer to match the drawing style and morph only into the face region, preserving the integrity of the original artwork. Figure 2 shows another example we aim to achieve, swapping the two faces in “American Gothic” by Grant Wood.
II. Approach
Our approach comprises several steps, each of which is covered in the class. The pipeline shown above provides an overview of our method (refer to Figure 3), and here are steps with more detailed descriptions:
- Image Selection: We first obtain two sets of images. One set consists of pictures of a "cat," the other set includes numerous classical portrait artworks.
- Source and Target Images: Select one image from each set, labeling them as the 'source' and 'target' images, respectively.
- Facial Landmarks Extraction: Extract facial landmarks from both images using the standard 68 landmarks model.
- For human faces, we automatically extract the landmarks using dlib’s detector and predictor, which is a mature technology.
- For cat faces, we manually extract the landmarks using a Python tool we developed, taking the positions of dlib’s predictor landmarks as reference (Elmahmudi, Ali, et. al.). For more details, see the README file in the code repo.
- Triangulation: Triangulate the facial landmarks of each face to match the same mesh structure. This is achieved using a convex hull and the Delaunay algorithm.
- Affine Transformation: Perform an affine transformation from the stylized source face to the target face, or vice versa. Obtain the mask of each face.
- Poisson Blending: Apply Poisson or Mixed blending using the source face's region of interest, the target artwork, and the source face mask.
III. Results
IV. Implementation
For this project, Python was our primary programming language, complemented by a range of open-source libraries. Below is a list of these libraries in our project:
cv2
(OpenCV):- General Functions: Used for reading images, converting color spaces, visualizing landmarks on images, and calculating the bounding box coordinates.
- Convex Hull and Subdiv2D: Used for creating convex hulls and Delaunay triangulation, essential in the process of meshing facial landmarks.
cv2.getAffineTransform()
,cv2.warpAffine()
: These functions perform affine transformations for morphing faces from source to target images.cv2.fillConvexPoly()
: Fills a convex polygon, which we used for masking and blending regions in the image.- Poisson Blending: we opted for the
cv2.seamlessClone()
function instead of the functions built during project 3 for its efficiency and effectiveness in the blending step.
dlib
: Used for its robust facial detector and predictor, providing the facial landmarks necessary for our transformations.Pillow
: Used for opening and handling the content and style images from their respective directories.- Others:
matplotlib
,numpy
,json
For image datasets, some were acquired from the internet (e.g., Google Arts, Google Search), while others were generated using GAN technology (e.g., DALL-E). The sources of these images will be listed in the reference section.
V. Problem
The main problem was achieving a seamless blend of the source face with the target artwork's color palette and style. We initially tried mixed gradient blending, which sometimes caused the source face to lose its unique features. We then experimented with poisson gradient blending, which retained more of the source face structure and was ultimately chosen for our project. We provide users with both blending options, allowing them to select based on their preference.
For future improvements, we hope to explore other techniques that account for variations in lighting, saturation, and color profiles. Potential solutions include:
- Implementing a multi-scale blending approach for preserving finer details while ensuring a smooth transition.
- Incorporating color correction algorithms to match the source face's color tone with the target artwork.
- Enhancing triangulation, especially around key facial features, to achieve more detailed and accurate morphing.
Our initial goal of facilitating general object migration between artworks, time constraints led us to focus solely on facial swaps. An automatic segmentation method could be incorporated into the project to handle the different shapes, colors, and textures present in various objects, which would be quite interesting to observe as objects migrate through each other across different artworks. Recent developments with Semantic Automatic Matting (SAM) (Kirillov et al., 2023) seem to be a promising option to be integrated in the future.
VI. Acknowledgements
Tommy Liu
- Project report writing and the finalized version
- Implemented a tool to manually annotate the 68 landmarks for cat face, as well as save/load the landmark file to be used in the Notebook
- (Main notebook) implemented the parts for landmark extraction, triangulation w/ convex hull and Delaunny algorithm, face blending, the final output and comparing section, as well as the final code integration
- Ran demo on various source and target images to showcase the project's capabilities
- Wrote the README file in the GitHub repo
The full code is located here on GitHub.
Reference
List of images used
- van Eyck, J. (c. 1438). Portrait of Giovanni di Nicolao Arnolfini. [Painting].Berlin.
- Christus, P. (c. 1465-1470). Portrait of a Young Girl. [Oil-on-oak panel]. Gemäldegalerie, Berlin.
- van den Valckert, W. (1617). Man With a Ring. Location Unknown.
- Vermeer, J. (c. 1665). Girl with a Pearl Earring. [Oil painting]. Mauritshuis museum, The Hague.
- Repin, I. (1884). Portrait of Vsevolod Mikhailovich Garshin. [Oil on canvas]. Metropolitan Museum of Art.
- Wood, G. (1930). American Gothic. [Painting]. Location Unknown.
- Elmahmudi, A. and Ugail, H., 2021. Identification of facial landmarks using Dlib [Digital Image]. In A. Elmahmudi and H. Ugail, "A framework for facial age progression and regression using exemplar face templates," The Visual Computer, vol. 37. doi: 10.1007/s00371-020-01960-z. Available: https://www.researchgate.net/figure/dentification-of-facial-landmarks-using-Dlib-a-Facial-landmarks-b-The-position-and_fig2_343699139
- Adam88xx. (2014, May 23). Cat Kitten Gaze Regard Glance Look Head. [Digital Image]. IStock. Available: www.istockphoto.com/photo/cat-gm493250135-40361554. Accessed 6 Dec. 2023.
- Aleksandrov, V. Red Cat. [Digital Art]. ArtPal. Available: www.artpal.com/VladimirAleksand?i=238586-12. Accessed 6 Dec. 2023.
- Brooks, K. (2015, Sept. 3). Cats Are Taking over Famous Western Artworks and We’re Definitely Not Mad about It. HuffPost. Available: www.huffpost.com/entry/cats-are-taking-over-famous-western-artworks_n_55e75737e4b0aec9f355c018. Accessed 6 Dec. 2023.
- Flood, S. Orlando. [Painting]. Year and Location Unknown.
List of readings
- A. Kirillov, E. Mintun, N. Ravi, H. Mao, C. Rolland, L. Gustafson, T. Xiao, S. Whitehead, A. C. Berg, W.-Y. Lo, P. Dollár, and R. Girshick, "Segment Anything," 2023. arXiv:2304.02643 [cs.CV]. [Online]. Available: https://arxiv.org/abs/2304.02643
- D. King, "Dlib's demo code for using 68 landmarks predictor," dlib.net. [Online]. Available: http://dlib.net/face_landmark_detection.py.html. [Accessed: Dec. 05, 2023].
- OpenCV, "seamlessClone() - OpenCV 3.4 documentation," docs.opencv.org. [Online]. Available: https://docs.opencv.org/3.4/df/da0/group__photo__clone.html#ga2bf426e4c93a6b1f21705513dfeca49d. [Accessed: Dec. 05, 2023].
- OpenCV, "Subdiv2D() - OpenCV 3.4 documentation," docs.opencv.org. [Online]. Available: https://docs.opencv.org/3.4/df/d5b/group__imgproc__subdiv2d.html. [Accessed: Dec. 05, 2023].
- L. R. Finka et al., "Geometric morphometrics for the study of facial expressions in non-human animals, using the domestic cat as an exemplar," Scientific Reports, vol. 9, no. 1, Art. no. 9883, Jul. 2019, doi: 10.1038/s41598-019-46330-5.
- G. Martvel, I. Shimshoni, and A. Zamansky, "Automated Detection of Cat Facial Landmarks," 2023. arXiv:2310.09793. [Online]. Available: https://arxiv.org/abs/2310.09793 [cs.CV]. [Accessed: Dec. 05, 2023].
- G. Martvel, N. Farhat, I. Shimshoni, and A. Zamansky, "CatFLW: Cat Facial Landmarks in the Wild Dataset," 2023. arXiv:2305.04232. [Online]. Available: https://arxiv.org/abs/2305.04232 [cs.CV]. [Accessed: Dec. 05, 2023].
- Tech4Animals Lab, "CatFLW: Cat Facial Landmarks in the Wild Dataset," Tech4Animals, 2023. [Online]. Available: https://www.tech4animals.org/catflw. [Accessed: Dec. 05, 2023].
- Piętka, Ola. “Face Swapping & Style Transfer.” GitHub, 14 Nov. 2023, github.com/OlaPietka/Portrait-Style-Transfer. Accessed 7 Dec. 2023.
- Q. Zhang, "Landmark Detection for Animal Face and 3D Reconstructions," zhangtemplar.github.io, 2023. [Online]. Available: https://zhangtemplar.github.io/animal-keypoints/. [Accessed: Dec. 05, 2023].
- S. Mallick, "Face Swap using OpenCV," learnopencv.com, 2023. [Online]. Available: https://learnopencv.com/face-swap-using-opencv-c-python/. [Accessed: Dec. 05, 2023].