Code Monkey home page Code Monkey logo

color_transfer's Introduction

Super fast color transfer between images

The color_transfer package is an OpenCV and Python implementation based (loosely) on Color Transfer between Images [Reinhard et al., 2001] The algorithm itself is extremely efficient (much faster than histogram based methods), requiring only the mean and standard deviation of pixel intensities for each channel in the L*a*b* color space.

For more information, along with a detailed code review, take a look at this post on my blog.

#Requirements

  • OpenCV
  • NumPy

#Install To install, make sure you have installed NumPy and compiled OpenCV with Python bindings enabled.

From there, there easiest way to install is via pip:

$ pip install color_transfer

#Examples Below are some examples showing how to run the example.py demo and the associated color transfers between images.

$ python example.py --source images/autumn.jpg --target images/fallingwater.jpg Autumn and Fallingwater screenshot

$ python example.py --source images/woods.jpg --target images/storm.jpg Woods and Storm screenshot

$ python example.py --source images/ocean_sunset.jpg --target images/ocean_day.jpg Sunset and Ocean screenshot

color_transfer's People

Contributors

adamspannbauer avatar jrosebr1 avatar kumarujjawal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

color_transfer's Issues

Issue with images

Line 26
target = cv2.cvtColor(target, cv2.COLOR_BGR2LAB).astype("float32")

while trying to use differents jpg, raise error during the conversion to float32:

target = cv2.cvtColor(target, cv2.COLOR_BGR2LAB).astype("float32")
cv2.error: ........\opencv\modules\imgproc\src\color.cpp:4118: error: (-215) (scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F) in function cv::cvtColor

Failed with some images

Hi. Thanks for the code! Impressive work!
I find that for some images, the code seems to produce the wrong output. Here is the example:
source:
rock
target:
ocean_day
output:
oceanout

I will appreciate it if you can offer me some guidance. Thanks ahead of time!

Enhancement of Reinhard Method

I have identified a simple enhancement of the basic Reinhard method which for some input image pairs can produce images of far better quality.

https://github.com/TJCoding/Enhanced-Image-Colour-Transfer

The implementation is in C++ only for the moment, but an executable is provided for those who wish to try out the new method. Also a web app is now available which permits a comparison of various processing methods.
https://www.dustfreesolutions.com/CT/CT.html

I have an adaption of your code which implements the enhanced method in Python. How would you like me to deal with this? I could take a branch and issue a pull request or I could simply post it in my repository in a directory 'Python implementation of Enhanced-Image-Colour-Transfer' and fully credit you for your contribution. Although I have used your code as a template, there is quite a wide divergence from the original so a merge might not be so simple. The choice is yours.

The images below show target image, source image, output image from current processing, output image from enhanced processing.

Flowers_composite

source and target reverse

I believe the original paper means that we want the source image to mimic the color performance of the target image, and output a transferred source image. However, in your implementation, the target image is instead transferred. This is what makes the following formulas inconsistent with the paper.

l -= lMeanTar
a -= aMeanTar
b -= bMeanTar
if preserve_paper:
# scale by the standard deviations using paper proposed factor
l = (lStdTar / lStdSrc) * l
a = (aStdTar / aStdSrc) * a
b = (bStdTar / bStdSrc) * b
else:
# scale by the standard deviations using reciprocal of paper proposed factor
l = (lStdSrc / lStdTar) * l
a = (aStdSrc / aStdTar) * a
b = (bStdSrc / bStdTar) * b
# add in the source mean
l += lMeanSrc
a += aMeanSrc
b += bMeanSrc

automatic choosing of best `clip` & `preserve_paper` args?

Any interest in including a utility function for choosing the 'truest to source' color transfer?

I've implemented an (unoptimized) auto_color_transfer function that attempts to choose the best combination of clip & preserve_paper by comparing each potential result to the source image in the HSV color space using chi2 distance. The mean absolute error is calculated between the channel means of the source & candidate images. Since the 'truest' color transfer isn't always the most aesthetically pleasing the function also returns a comparison matrix image (see below).

In this case, the bottom left image is chosen as the truest transfer by the current method.

image

EDIT: updated distance used to determine 'truest' transfer

The args ` clip` & `preserve_paper` are missing in the pip library

When I use following line to install the lib,
pip install color_transfer
and use codes in the example.py, there will be errors:
TypeError: color_transfer() got an unexpected keyword argument 'preserve_paper'
TypeError: color_transfer() got an unexpected keyword argument 'clip'

so does the files in the pip lib older than the current repo?

scale by the standard deviations part is wrong??

hi, I have tried your code, but seems a bit wrong here =>
color_transfer / color_transfer / init.py

in the 42~45 lines,

scale by the standard deviations

l = (lStdTar / lStdSrc) * l
a = (aStdTar / aStdSrc) * a
b = (bStdTar / bStdSrc) * b

the StdSrc and StdTar should be replaced with each other.

I will try more test images and feedback to you~

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.