The Process
Overview
- Convert both input images to LMS colorspace
- Convert both input images to lαβ colorspace
- Transfer image1 colors onto image2 lαβ colorspace
- Convert image2 back to LMS colorspace
- Convert image2 back to RGB colorspace
Programming Notes
- Floating point numbers 0.0 .. 1.0 were used for pixel values
- Math.log10 and Math.pow are functions used
Step 1 - Converting from RGB to LMS Colorspace
For both images, apply this matrix to each pixel
| 0.3811 |
0.5783 |
0.0402 |
| 0.1967 |
0.7244 |
0.0782 |
| 0.0241 |
0.1288 |
0.8444 |
Then, for each pixel, and each channel L, M, S, let L=logL, M=logM, and S=logS
Step 2 - Converting from LMS to lαβ Colorspace
For both images, apply this matrix to each pixel
| 1.0 |
1.0 |
1.0 |
| 1.0 |
1.0 |
-2.0 |
| 1.0 |
-1.0 |
0.0 |
And then apply this matrix to the pixels of both images
| 1.0 / √3 |
0.0 |
0.0 |
| 0.0 |
1.0 / √6 |
0.0 |
| 0.0 |
0.0 |
1.0 / √2 |
Step 3 - Transferring image1's colors to image2
First, do these steps:
- For each image, find the average l, α, and β values
- For each image, find the standard deviation of each channel l, α, and β
- Calculate image1's standard deviation / image2's standard deviation for each channel
After finding these variables, complete the following mathematical steps on image2's lαβ data:
- For each channel, subtract image2's average values found previously
- For each channel, multiply the ratio of standard devations that correspond with the channel
- For each channle, add image1's average values found previously
Step 4 - Converting from lαβ to LMS Colorspace
Only for image2, apply this matrix to each pixel
| √3 / 3 |
0.0 |
0.0 |
| 0.0 |
√6 / 6 |
0.0 |
| 0.0 |
0.0 |
√2 / 2 |
And then apply this matrix to the pixels
| 1.0 |
1.0 |
1.0 |
| 1.0 |
1.0 |
-1.0 |
| 1.0 |
-2.0 |
0.0 |
Step 5 - Converting from LMS to RGB Colorspace
Then, for each pixel in image2, and each channel L, M, S, let L=L^10, M=M^10, and S=S^10.
Then apply this matrix
| 4.4679 |
-3.5873 |
0.1193 |
| -1.2186 |
2.3809 |
-0.1624 |
| 0.0497 |
-0.2439 |
1.2045 |