Final Project for CIS 581 by Grace Benner, Chenchen Lin, and Isaac Wasserman
🚧 Dependencies
Note that we have not included a
requirements.txt
file in this repo. Our codebase is made up of two preexisting shadow removal methods and one novel method, each with their own conflicting dependencies. Additionally, in the case of the novel method, not all of the dependencies can be installed frompip
orconda
.To reproduce our results with each method, refer to the various "Usage" sections listed below.
ShadowGP, a pioneering unsupervised shadow removal method, distinguishes itself from supervised approaches by leveraging deep generative priors from a pretrained GAN model. The model decomposes a shadowed portrait into a shadow-free image, a full-shadow image, and a shadow mask, reconstructing the image using progressive optimization. Given an input shadow portrait
The ShadowGP component can be run from a self contained Jupyter Notebook at ShadowGP/shadowgp_colab.ipynb.
This notebook installs all of its required packages and weights. When run inside of Google Colab, it will automatically import the rest of the repository.
BlindShadowRemoval is a supervised model specialized for portrait shadow removal. Different from prior work, Blind Shadow Removal method only
look at gray-scale image for first stage decomposition:
The Blind Shadow Removal component can be run from a self contained Jupyter Notebook at BlindShadowRemoval/BlindShadowRemoval.ipynb.
This notebook installs all of its required packages and weights. When run inside of Google Colab, it will automatically import the rest of the repository.
We explore an alternative to deep learning techniques for facial image manipulation, opting for a handcrafted approach with intentional design choices. Our model starts by detecting facial landmarks, generating a face mask that allows us to focus on skin regions. To address harsh adjustment boundaries, we introduce a vertex-coloring technique, softening edges of the mask. Using a Gaussian mixture model in LAB space, we identify shadowed and well-lit face regions. After further refining the shadow mask through morphological operations, color adjustments in shadowed areas are made by treating skin color as a function of pixel coordinates, employing linear regression trained on well-lit regions. We enhance the inpainting process for shadowed boundaries using the PatchMatch algorithm [3], significantly improving image fidelity. However, challenges arise in high-frequency areas like eyes or mouth, leading us to apply targeted sharpening to mitigate blurring effects. Our non-deep learning model demonstrates effectiveness in achieving somewhat-realistic facial image manipulations, offering a promising alternative to more complex neural approaches.
Running our classical approach requires installation of PyPatchMatch, an implementation of the PatchMatch algorithm from InvokeAI. This can be difficult, and we have not been successful in completing this installation in Google Colab. Therefore, we recommend running this method locally.
Here are instructions for running this method:
-
Install
pypatchmatch
. Full instructions with details for each operating system can be found here, but a summary is given below.a. Install OpenCV (both the development kit and the Python bindings)
b.
pip install pypatchmatch
c. Confirm installation with:
python >>> from patchmatch import patch_match
which should print logs from building the binaries.
-
From the
/classical
directory, runpip install -r requirements.txt
-
Run the cells contained in classical/classical.ipynb.
For the remaining exploratory files that are not a key portion of our research, such as baseline or shadow classifier. The requirements, inputs, and results are self-contained in the respective folders and .ipynb files.
[1] Yingqing He, Yazhou Xing, Tianjia Zhang, and Qifeng Chen. Unsupervised portrait shadow removal via generative priors. In Proceedings of the 29th ACM International Conference on Multimedia, pages 236–244, 2021.
[2] Yaojie Liu, Andrew Hou, Xinyu Huang, Liu Ren, and Xiaoming Liu. Blind removal of facial foreign shadows. 2022.
[3] Connelly Barnes, Eli Shechtman, Adam Finkelstein, and Dan B Goldman. PatchMatch: A randomized correspondence algorithm for structural image editing. ACM Transactions on Graphics (Proc. SIGGRAPH), 28(3), Aug. 2009.