/color-transfer

Primary LanguagePythonOtherNOASSERTION

Color Transfer in Python

Three methods of color transfer implemented in Python.

Output Examples

Input image Reference image Mean std transfer Lab mean transfer Pdf transfer + Regrain
image image image image 效果不佳,舍弃
example1_input example1_ref example1_mt example1_lt example1_pdf-reg
example1_input example1_ref example1_mt example1_lt example1_pdf-reg

Methods

Let input image be $I$, reference image be $R$ and output image be $O$. Let $f{I}(r, g, b)$, $f{R}(r, g, b)$ be probability density functions of $I$ and $R$'s rgb values.

  • Mean std transfer

    $$O = (I - mean(I)) / std(I) * std(R) + mean(R).$$

  • Lab mean transfer1

    $$I' = rgb2lab(I)$$ $$R' = rgb2lab(R)$$ $$O' = (I' - mean(I')) / std(I') * std(R') + mean(R')$$ $$O = lab2rgb(O')$$

  • Pdf transfer2

    $O = t(I)$, where $t: R^3\rightarrow R^3$ is a continous mapping so that $f{t(I)}(r, g, b) = f{R}(r, g, b)$.

Requirements

Installation

From PyPi

pip install python-color-transfer

From source

git clone https://github.com/Uric369/color-transfer.git
cd python-color-transfer

pip install -r requirements.txt

Code setting 详见代码注释

  • mode: “cover” / “output”
  • method: “lt” / “mt”
  • target: “leaf” / “trunk”
  • (only “cover” mode)covered_image
  • src_img_folder & src_names
  • ref_img_folder & ref_names
  • out_img_folder & out_names

Footnotes

  1. Lab mean transfer: Color Transfer between Images by Erik Reinhard, Michael Ashikhmin, Bruce Gooch and Peter Shirley.
    Open source's python implementation

  2. Pdf transfer: Automated colour grading using colour distribution transfer by F. Pitie , A. Kokaram and R. Dahyot.
    Author's matlab implementation