The algorithm that I'm going to mention is based on the following paper:
In this paper, Reinhard and colleagues demonstrate that by utilizing the Lab* color space and the mean and standard deviation of each L*, a*, and b* channel, respectively, that the color can be transferred between two images.
The algorithm performs the following:
- Input a source and a target image. The source image contains the color space that you want your target image to mimic.
- Convert both the source and the target image to the Lab* color space. The Lab* color space models perceptual uniformity, where a small change in an amount of color value should also produce a relatively equal change in color importance. The Lab* color space does a substantially better job mimicking how humans interpret color than the standard RGB color space, and as you’ll see, works very well for color transfer.
- Split the channels for both the source and target.
- Compute the mean and standard deviation of each of the Lab* channels for the source and target images.
- Subtract the mean of the Lab* channels of the target image from target channels.
- Scale the target channels by the ratio of the standard deviation of the target divided by the standard deviation of the source, multiplied by the target channels.
- Add in the means of the Lab* channels for the source.
- Clip any values that fall outside the range [0, 255].
- Merge the channels back together.
- Convert back to the RGB color space from the Lab* space.
Make sure to have OpenCV for Python installed before you run the code.
Image to transfer colors from:
Image to transfer colors onto:
The final image:
Make a Flask webserver and convert this code into a REST API.