iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📸

Replicating Aesthetic Color Grading with Python: Generating LUTs from Before/After Images

に公開

Introduction

Have you ever thought, "The colors in this photo are so emotional... I want to apply them to my other photos!"?

In many cases, such color schemes are distributed as "presets" or "LUTs (Look-Up Tables)," allowing you to freely transform your images.

What is a LUT?

A LUT (Look-Up Table) is a color preset that transforms the colors of a video or image using mathematical formulas. Source: What is a LUT? Explanation of types and usage (Color Grading Efficiency)

In other words, you can think of it as a color correspondence table that converts the tones of an image into something nice.

So, I thought: if I have the "before" and "after" images of a LUT conversion, wouldn't it be possible to calculate that LUT in reverse (to find the inverse function)? That's why I decided to implement it.

Implementation

I adopted trilinear interpolation for linear interpolation and implemented the following features in Python:

  • Input image smoothing: Reducing the impact of noise during estimation
  • Robust 2-stage interpolation: Stable estimation even for unknown colors
  • Trilinear interpolation: Thoroughly suppressing banding when applying the LUT

Results

The estimation turned out quite well!


Figure 1: Before applying LUT


Figure 2: Applying a pre-prepared LUT


Figure 3: Applying the estimated LUT

How to Run

1. Prepare the files

Prepare the following three image files.

  • Before image: The original state image, such as before.jpg.
  • After image: A sample image with the desired LUT or color correction applied, such as after.jpg.
  • Target image: The image you want to apply the newly estimated LUT to, such as target.jpg.

2. Edit the program

Open the script file (e.g., lut_estimator.py) and replace the file paths inside the if __name__ == '__main__': block at the end with the paths to the images you prepared.

3. Run

Run the script in your terminal or command prompt.

python lut_estimator.py

Once the process is complete, the resulting image and the .cube file will be saved to the specified output path.

Details are described in the README. See GitHub

Conclusion

Technical details are available on GitHub, so please give it a Star!

Discussion