-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b304917
commit 6faf1f7
Showing
1 changed file
with
85 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,96 @@ | ||
# colortransfer | ||
|
||
`colortransfer` is a small tool that transfers the color distribution of one | ||
image to another image. The final image will have the mean and standard | ||
deviation of its color channels adjusted to match the mean and standard | ||
deviation of the color channels of the source image. It's a clone of | ||
<https://github.com/jrosebr1/color_transfer> but it works on the YCbCr color | ||
space, and it is written in Haskell. | ||
`colortransfer` is a small tool that transfers the color distribution | ||
of one image to another image. It offers two methods of color transfer, | ||
histogram matching and ellipsoid transformation. | ||
|
||
## Color Transfer Methods | ||
|
||
### Histogram Matching | ||
|
||
This method adjusts the mean and standard deviation of the color channels | ||
in the input image to match those of the reference image. It's a simple | ||
and effective approach for many cases, but it may not capture more | ||
complex color relationships. | ||
|
||
### Ellipsoid Transformation | ||
|
||
The ellipsoid transformation method offers a more advanced approach to | ||
color transfer: | ||
|
||
- It models the color distributions of both the input and reference | ||
images as 3D ellipsoids in the color space. | ||
- The method then computes a transformation that maps the input image's | ||
color ellipsoid to match the reference image's color ellipsoid. | ||
- This transformation takes into account not just the mean and standard | ||
deviation, but also the covariance between color channels, allowing for | ||
a more nuanced color transfer. | ||
- The result often preserves the relative relationships between colors | ||
better than simple histogram matching, potentially leading to more | ||
natural-looking results, especially for images with complex color | ||
distributions. | ||
|
||
## Run | ||
|
||
```shell | ||
nix run github:damianfral/colortransfer -- \ | ||
--source nice-colors.jpg \ | ||
--target my-photo.jpg \ | ||
--output my-photo-with-nice-colors.jpg | ||
--input my-photo.jpg \ | ||
--reference nice-colors.jpg \ | ||
--output my-photo-with-nice-colors.jpg \ | ||
``` | ||
|
||
## Options | ||
|
||
- `--input`: The image to be used as the color source | ||
- `--reference`: The image we want to transform | ||
- `--output`: The output image | ||
- `--method`: The color transfer method to use (default: 2) | ||
- 1: Histogram matching | ||
- 2: Ellipsoid transformation | ||
|
||
## Examples | ||
|
||
![test1](images/autumn-fallingwater.png?raw=true) | ||
![test2](images/oceansunset-oceanday.png?raw=true) | ||
![test3](images/woods-storm.png?raw=true) | ||
| Input Image | Reference Image | Histogram Matching | Ellipsoid Transformation | ||
|-------------|-----------------|--------------------|-------------------------- | ||
| ![Input](./test-resources/originals/ales-krivec-4miBe6zg5r0-unsplash.jpg) | ![Reference](./test-resources/originals/benjamin-voros-phIFdC6lA4E-unsplash.jpg) | ![HM](./test-resources/processed/ales-krivec--benjamin-voros--histogram-matching.jpeg) | ![ET](./test-resources/processed/ales-krivec--benjamin-voros--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/ales-krivec-4miBe6zg5r0-unsplash.jpg) | ![Reference](./test-resources/originals/jamie-fenn-XhzdJk1za2k-unsplash.jpg) | ![HM](./test-resources/processed/ales-krivec--jamie-fenn--histogram-matching.jpeg) | ![ET](./test-resources/processed/ales-krivec--jamie-fenn--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/ales-krivec-4miBe6zg5r0-unsplash.jpg) | ![Reference](./test-resources/originals/pawel-czerwinski-6lQDFGOB1iw-unsplash.jpg) | ![HM](./test-resources/processed/ales-krivec--pawel-czerwinski--histogram-matching.jpeg) | ![ET](./test-resources/processed/ales-krivec--pawel-czerwinski--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/ales-krivec-4miBe6zg5r0-unsplash.jpg) | ![Reference](./test-resources/originals/pine-watt-2Hzmz15wGik-unsplash.jpg) | ![HM](./test-resources/processed/ales-krivec--pine-watt--histogram-matching.jpeg) | ![ET](./test-resources/processed/ales-krivec--pine-watt--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/ales-krivec-4miBe6zg5r0-unsplash.jpg) | ![Reference](./test-resources/originals/ravi-sharma-f2h77fiLu18-unsplash.jpg) | ![HM](./test-resources/processed/ales-krivec--ravi-sharma--histogram-matching.jpeg) | ![ET](./test-resources/processed/ales-krivec--ravi-sharma--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/ales-krivec-4miBe6zg5r0-unsplash.jpg) | ![Reference](./test-resources/originals/tania-miron-EKX3Lx-t5CM-unsplash.jpg) | ![HM](./test-resources/processed/ales-krivec--tania-miron--histogram-matching.jpeg) | ![ET](./test-resources/processed/ales-krivec--tania-miron--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/benjamin-voros-phIFdC6lA4E-unsplash.jpg) | ![Reference](./test-resources/originals/ales-krivec-4miBe6zg5r0-unsplash.jpg) | ![HM](./test-resources/processed/benjamin-voros--ales-krivec--histogram-matching.jpeg) | ![ET](./test-resources/processed/benjamin-voros--ales-krivec--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/benjamin-voros-phIFdC6lA4E-unsplash.jpg) | ![Reference](./test-resources/originals/jamie-fenn-XhzdJk1za2k-unsplash.jpg) | ![HM](./test-resources/processed/benjamin-voros--jamie-fenn--histogram-matching.jpeg) | ![ET](./test-resources/processed/benjamin-voros--jamie-fenn--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/benjamin-voros-phIFdC6lA4E-unsplash.jpg) | ![Reference](./test-resources/originals/pawel-czerwinski-6lQDFGOB1iw-unsplash.jpg) | ![HM](./test-resources/processed/benjamin-voros--pawel-czerwinski--histogram-matching.jpeg) | ![ET](./test-resources/processed/benjamin-voros--pawel-czerwinski--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/benjamin-voros-phIFdC6lA4E-unsplash.jpg) | ![Reference](./test-resources/originals/pine-watt-2Hzmz15wGik-unsplash.jpg) | ![HM](./test-resources/processed/benjamin-voros--pine-watt--histogram-matching.jpeg) | ![ET](./test-resources/processed/benjamin-voros--pine-watt--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/benjamin-voros-phIFdC6lA4E-unsplash.jpg) | ![Reference](./test-resources/originals/ravi-sharma-f2h77fiLu18-unsplash.jpg) | ![HM](./test-resources/processed/benjamin-voros--ravi-sharma--histogram-matching.jpeg) | ![ET](./test-resources/processed/benjamin-voros--ravi-sharma--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/benjamin-voros-phIFdC6lA4E-unsplash.jpg) | ![Reference](./test-resources/originals/tania-miron-EKX3Lx-t5CM-unsplash.jpg) | ![HM](./test-resources/processed/benjamin-voros--tania-miron--histogram-matching.jpeg) | ![ET](./test-resources/processed/benjamin-voros--tania-miron--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/jamie-fenn-XhzdJk1za2k-unsplash.jpg) | ![Reference](./test-resources/originals/ales-krivec-4miBe6zg5r0-unsplash.jpg) | ![HM](./test-resources/processed/jamie-fenn--ales-krivec--histogram-matching.jpeg) | ![ET](./test-resources/processed/jamie-fenn--ales-krivec--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/jamie-fenn-XhzdJk1za2k-unsplash.jpg) | ![Reference](./test-resources/originals/benjamin-voros-phIFdC6lA4E-unsplash.jpg) | ![HM](./test-resources/processed/jamie-fenn--benjamin-voros--histogram-matching.jpeg) | ![ET](./test-resources/processed/jamie-fenn--benjamin-voros--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/jamie-fenn-XhzdJk1za2k-unsplash.jpg) | ![Reference](./test-resources/originals/pawel-czerwinski-6lQDFGOB1iw-unsplash.jpg) | ![HM](./test-resources/processed/jamie-fenn--pawel-czerwinski--histogram-matching.jpeg) | ![ET](./test-resources/processed/jamie-fenn--pawel-czerwinski--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/jamie-fenn-XhzdJk1za2k-unsplash.jpg) | ![Reference](./test-resources/originals/pine-watt-2Hzmz15wGik-unsplash.jpg) | ![HM](./test-resources/processed/jamie-fenn--pine-watt--histogram-matching.jpeg) | ![ET](./test-resources/processed/jamie-fenn--pine-watt--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/jamie-fenn-XhzdJk1za2k-unsplash.jpg) | ![Reference](./test-resources/originals/ravi-sharma-f2h77fiLu18-unsplash.jpg) | ![HM](./test-resources/processed/jamie-fenn--ravi-sharma--histogram-matching.jpeg) | ![ET](./test-resources/processed/jamie-fenn--ravi-sharma--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/jamie-fenn-XhzdJk1za2k-unsplash.jpg) | ![Reference](./test-resources/originals/tania-miron-EKX3Lx-t5CM-unsplash.jpg) | ![HM](./test-resources/processed/jamie-fenn--tania-miron--histogram-matching.jpeg) | ![ET](./test-resources/processed/jamie-fenn--tania-miron--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/pawel-czerwinski-6lQDFGOB1iw-unsplash.jpg) | ![Reference](./test-resources/originals/ales-krivec-4miBe6zg5r0-unsplash.jpg) | ![HM](./test-resources/processed/pawel-czerwinski--ales-krivec--histogram-matching.jpeg) | ![ET](./test-resources/processed/pawel-czerwinski--ales-krivec--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/pawel-czerwinski-6lQDFGOB1iw-unsplash.jpg) | ![Reference](./test-resources/originals/benjamin-voros-phIFdC6lA4E-unsplash.jpg) | ![HM](./test-resources/processed/pawel-czerwinski--benjamin-voros--histogram-matching.jpeg) | ![ET](./test-resources/processed/pawel-czerwinski--benjamin-voros--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/pawel-czerwinski-6lQDFGOB1iw-unsplash.jpg) | ![Reference](./test-resources/originals/jamie-fenn-XhzdJk1za2k-unsplash.jpg) | ![HM](./test-resources/processed/pawel-czerwinski--jamie-fenn--histogram-matching.jpeg) | ![ET](./test-resources/processed/pawel-czerwinski--jamie-fenn--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/pawel-czerwinski-6lQDFGOB1iw-unsplash.jpg) | ![Reference](./test-resources/originals/pine-watt-2Hzmz15wGik-unsplash.jpg) | ![HM](./test-resources/processed/pawel-czerwinski--pine-watt--histogram-matching.jpeg) | ![ET](./test-resources/processed/pawel-czerwinski--pine-watt--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/pawel-czerwinski-6lQDFGOB1iw-unsplash.jpg) | ![Reference](./test-resources/originals/ravi-sharma-f2h77fiLu18-unsplash.jpg) | ![HM](./test-resources/processed/pawel-czerwinski--ravi-sharma--histogram-matching.jpeg) | ![ET](./test-resources/processed/pawel-czerwinski--ravi-sharma--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/pawel-czerwinski-6lQDFGOB1iw-unsplash.jpg) | ![Reference](./test-resources/originals/tania-miron-EKX3Lx-t5CM-unsplash.jpg) | ![HM](./test-resources/processed/pawel-czerwinski--tania-miron--histogram-matching.jpeg) | ![ET](./test-resources/processed/pawel-czerwinski--tania-miron--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/pine-watt-2Hzmz15wGik-unsplash.jpg) | ![Reference](./test-resources/originals/ales-krivec-4miBe6zg5r0-unsplash.jpg) | ![HM](./test-resources/processed/pine-watt--ales-krivec--histogram-matching.jpeg) | ![ET](./test-resources/processed/pine-watt--ales-krivec--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/pine-watt-2Hzmz15wGik-unsplash.jpg) | ![Reference](./test-resources/originals/benjamin-voros-phIFdC6lA4E-unsplash.jpg) | ![HM](./test-resources/processed/pine-watt--benjamin-voros--histogram-matching.jpeg) | ![ET](./test-resources/processed/pine-watt--benjamin-voros--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/pine-watt-2Hzmz15wGik-unsplash.jpg) | ![Reference](./test-resources/originals/jamie-fenn-XhzdJk1za2k-unsplash.jpg) | ![HM](./test-resources/processed/pine-watt--jamie-fenn--histogram-matching.jpeg) | ![ET](./test-resources/processed/pine-watt--jamie-fenn--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/pine-watt-2Hzmz15wGik-unsplash.jpg) | ![Reference](./test-resources/originals/pawel-czerwinski-6lQDFGOB1iw-unsplash.jpg) | ![HM](./test-resources/processed/pine-watt--pawel-czerwinski--histogram-matching.jpeg) | ![ET](./test-resources/processed/pine-watt--pawel-czerwinski--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/pine-watt-2Hzmz15wGik-unsplash.jpg) | ![Reference](./test-resources/originals/ravi-sharma-f2h77fiLu18-unsplash.jpg) | ![HM](./test-resources/processed/pine-watt--ravi-sharma--histogram-matching.jpeg) | ![ET](./test-resources/processed/pine-watt--ravi-sharma--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/pine-watt-2Hzmz15wGik-unsplash.jpg) | ![Reference](./test-resources/originals/tania-miron-EKX3Lx-t5CM-unsplash.jpg) | ![HM](./test-resources/processed/pine-watt--tania-miron--histogram-matching.jpeg) | ![ET](./test-resources/processed/pine-watt--tania-miron--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/ravi-sharma-f2h77fiLu18-unsplash.jpg) | ![Reference](./test-resources/originals/ales-krivec-4miBe6zg5r0-unsplash.jpg) | ![HM](./test-resources/processed/ravi-sharma--ales-krivec--histogram-matching.jpeg) | ![ET](./test-resources/processed/ravi-sharma--ales-krivec--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/ravi-sharma-f2h77fiLu18-unsplash.jpg) | ![Reference](./test-resources/originals/benjamin-voros-phIFdC6lA4E-unsplash.jpg) | ![HM](./test-resources/processed/ravi-sharma--benjamin-voros--histogram-matching.jpeg) | ![ET](./test-resources/processed/ravi-sharma--benjamin-voros--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/ravi-sharma-f2h77fiLu18-unsplash.jpg) | ![Reference](./test-resources/originals/jamie-fenn-XhzdJk1za2k-unsplash.jpg) | ![HM](./test-resources/processed/ravi-sharma--jamie-fenn--histogram-matching.jpeg) | ![ET](./test-resources/processed/ravi-sharma--jamie-fenn--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/ravi-sharma-f2h77fiLu18-unsplash.jpg) | ![Reference](./test-resources/originals/pawel-czerwinski-6lQDFGOB1iw-unsplash.jpg) | ![HM](./test-resources/processed/ravi-sharma--pawel-czerwinski--histogram-matching.jpeg) | ![ET](./test-resources/processed/ravi-sharma--pawel-czerwinski--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/ravi-sharma-f2h77fiLu18-unsplash.jpg) | ![Reference](./test-resources/originals/pine-watt-2Hzmz15wGik-unsplash.jpg) | ![HM](./test-resources/processed/ravi-sharma--pine-watt--histogram-matching.jpeg) | ![ET](./test-resources/processed/ravi-sharma--pine-watt--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/ravi-sharma-f2h77fiLu18-unsplash.jpg) | ![Reference](./test-resources/originals/tania-miron-EKX3Lx-t5CM-unsplash.jpg) | ![HM](./test-resources/processed/ravi-sharma--tania-miron--histogram-matching.jpeg) | ![ET](./test-resources/processed/ravi-sharma--tania-miron--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/tania-miron-EKX3Lx-t5CM-unsplash.jpg) | ![Reference](./test-resources/originals/ales-krivec-4miBe6zg5r0-unsplash.jpg) | ![HM](./test-resources/processed/tania-miron--ales-krivec--histogram-matching.jpeg) | ![ET](./test-resources/processed/tania-miron--ales-krivec--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/tania-miron-EKX3Lx-t5CM-unsplash.jpg) | ![Reference](./test-resources/originals/benjamin-voros-phIFdC6lA4E-unsplash.jpg) | ![HM](./test-resources/processed/tania-miron--benjamin-voros--histogram-matching.jpeg) | ![ET](./test-resources/processed/tania-miron--benjamin-voros--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/tania-miron-EKX3Lx-t5CM-unsplash.jpg) | ![Reference](./test-resources/originals/jamie-fenn-XhzdJk1za2k-unsplash.jpg) | ![HM](./test-resources/processed/tania-miron--jamie-fenn--histogram-matching.jpeg) | ![ET](./test-resources/processed/tania-miron--jamie-fenn--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/tania-miron-EKX3Lx-t5CM-unsplash.jpg) | ![Reference](./test-resources/originals/pawel-czerwinski-6lQDFGOB1iw-unsplash.jpg) | ![HM](./test-resources/processed/tania-miron--pawel-czerwinski--histogram-matching.jpeg) | ![ET](./test-resources/processed/tania-miron--pawel-czerwinski--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/tania-miron-EKX3Lx-t5CM-unsplash.jpg) | ![Reference](./test-resources/originals/pine-watt-2Hzmz15wGik-unsplash.jpg) | ![HM](./test-resources/processed/tania-miron--pine-watt--histogram-matching.jpeg) | ![ET](./test-resources/processed/tania-miron--pine-watt--histogram-matching.jpeg) | ||
| ![Input](./test-resources/originals/tania-miron-EKX3Lx-t5CM-unsplash.jpg) | ![Reference](./test-resources/originals/ravi-sharma-f2h77fiLu18-unsplash.jpg) | ![HM](./test-resources/processed/tania-miron--ravi-sharma--histogram-matching.jpeg) | ![ET](./test-resources/processed/tania-miron--ravi-sharma--histogram-matching.jpeg) |