Giter Site home page Giter Site logo

color-transfer's Introduction

Color transfer

A color transfer consists of giving the colors of a source image to a target image.
Here, a pixel of the source can be used only one time, and the two images must have the same area.
The operation then boils down to rearranging the pixels of the source image to make it resemble the target image as closely as possible.

Requirements

pip install -r requirements.txt

Use

positional arguments:
  target_image          Targeted image.
  source_image          Source image.

optional arguments:
  -h, --help            show this help message and exit
  -sa SAVE, --save SAVE
                        Output file to save.
  -sh, --show           Preview the output at the end.

Example

python color_transfer.py inputs/space.jpg intputs/sky.jpg -sa outputs/output.jpg -sh

The colors of sky.jpg will be transferred to space.jpg, the output image will be stored inside output.jpg in the outputs' directory, and a preview of the output will be show at the end of the execution.

Inputs

space sky

Output

output

Method

One-dimensional optimal transport

The transfer is made by sorting each image pixels according to their dot product with a certain vector. The two sorted lists of the source and target are then compared to make each pixel of same rank correspond to each other. The source can then be rearranged according to these correspondences.

Optimal vector search

To find the vector that would sort them best, the goal is to rotate a vector in all the positive directions and find the one with the lowest associated cost.
The search would be done by finding the three angles components of the vector. For each x, y, z unit vectors, we increment them by an angle of 1° and look at their associated cost. We repeat the process until 90° in the worst case. If at some point, the cost becomes higher than the previous one, we stop the search and return the previous vector.
Once each component vector is found, we compute the corresponding unit vector, which is the best vector.

Ultimately, the precision of the result vector depends on the angle precision that is incremented at each steps. But increasing the angle precision will also increase the computation time.

color-transfer's People

Contributors

clau555 avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.