Home

Awesome

Parametric Image Harmonization (PIH)

Project Page | Paper | Bibtex

Semi-supervised Parametric Real-world Image Harmonization.
CVPR 2023
Ke Wang, Michaël Gharbi, He Zhang, Zhihao Xia, Eli Shechtman

<img src='github_images/Figure_teaser.png'>

A novel semi-supervised training strategy and the first harmonization method that learns complex local appearance harmonization from unpaired real composites.

The code was developed by Ke Wang when Ke was a research scientist intern at Adobe research.

Please contact Ke (kewang@berkeley.edu) or Michaël (mgharbi@adobe.com) if you have any question.

Results <img src='github_images/Figure5.png'>

Our results show better visual agreements with the ground truth compared to SOTA methods in terms of color harmonization (rows 1,2 and 4) and shading correction (row 3).

<img src='github_images/Figure_8_final.png'>

RGB curves harmonize the global color/tone (center), while our shading map corrects the local shading in the harmonization output (right).


Prerequisites


Table of Contents:<br>

  1. Setup - set up the enviroment<br>
  2. Pretrained Models - download pretrained models and resources<br>
  3. Interactive Demo - off-line interactive demo<br>
  4. Inference - inference on high-resolution images with pretrained model<br>
  5. Dataset - prepare your own dataset for the training<br>
  6. Training - pipeline for training PIH<br>
  7. Citation - bibtex citation<br>

Setup

git clone git@github.com:adobe/PIH.git

We create a environment.yml to install the dependencies, you need to have Conda installed. Run

conda env create -f environment.yml

(essentially install PyTorch)


Pretrained models

We provide our pre-trained model (93M parameters) on Artist Retouched Dataset from this link and put it in the folder.

./pretrained/

Demo

We provide an interactive demo host offline built with PyGame

First, we install the dependencies:

python -m pip install -U pygame --user
pip install pygame_gui
pip install timm

Then, simpy run the following command to start the demo:

python demo.py

Here we provide a tutorial video for the demo.

<img src='github_images/demo.gif'>

Inference

We provide the inference code for evaluations:

python inference.py --bg <background dir *.png> --fg <foreground dir *.png> --checkpoints <checkpoint dir> [--gpu]

notes:

Example:

python inference.py --bg Demo_hr/Real_09_bg.jpg --fg Demo_hr/Real_09_fg.png --checkpoints pretrained/ckpt_g39.pth --gpu

Check the results/ folder for output images.


Dataset

<img src='github_images/S1.png'>

We prepare a guidline of preparing Artist Retouched Dataset.

For image with name <image-name>, we organize the data directory like this:

data
  |--train
    |--bg
        |-- <image-name>_before.png
        |-- <image-name>_after.png
    |--masks
        |-- <image-name>_before.png
        |-- <image-name>_after.png
    |--real_images
        |-- <image-name>_before.png
        |-- <image-name>_after.png
    
  |--test
    |--bg
        |-- <image-name>_before.png
        |-- <image-name>_after.png
    |--masks
        |-- <image-name>_before.png
        |-- <image-name>_after.png
    |--real_images
        |-- <image-name>_before.png
        |-- <image-name>_after.png

notes:


Training

Our approach uses a dual-stream semi-supervised training to bridge the domain gap, alleviating the generalization issues that plague many state-of-the-art harmonization models

<img src='github_images/Figure_3.png'>

We provide the script train_example.sh to perform training.

Training notes:

Simply run:

bash scripts/train_example.sh

to start the training.


Citation

If you use this code for your research, please cite our paper.

@article{wang2023semi,
  title={Semi-supervised Parametric Real-world Image Harmonization},
  author={Wang, Ke and Gharbi, Micha{\"e}l and Zhang, He and Xia, Zhihao and Shechtman, Eli},
  booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
  year      = {2023}
}