This repository contains a Python script (color_correction/opt_loop_advanced.py) that optimizes the output of a projector (beamer) to make a projected image appear as close as possible to a target image, considering the color and texture of the projection surface and ambient light.
It uses an optimization loop (Adam optimizer) to adjust the projector's RGB output per pixel, minimizing the difference between the perceived image (simulated based on surface, ambient light, and projector output) and the desired target image.
- Simulation: The script simulates how the projector's light interacts with the projection surface (
surface.jpg) and ambient light. - Loss Calculation: It calculates the difference (currently using Mean Squared Error in RGB space) between the simulated perceived image and the
target.jpg. - Optimization: It uses the Adam optimizer to calculate the gradient of the loss with respect to the projector's output and updates the projector's output image (
beamer) to minimize this loss. - Visualization: It displays the surface, the current beamer output, the simulated perceived image, and the target image side-by-side during the optimization process.
- Output:
- Saves a video (
projection_evolution.mp4) showing the evolution of the optimization. - Saves a final comparison image (
comparison.jpg) showing the optimized result alongside the target and a default projection attempt.
- Saves a video (
- Python 3
- OpenCV (
opencv-python) - NumPy
You can install the required libraries using pip:
pip install opencv-python numpy- Place your projection surface image (e.g., a photo of the wall or object you're projecting onto) as
assets/surface.jpg. - Place your desired target image as
assets/target.jpg. - Navigate to the
color_correctiondirectory. - Run the script:
cd color_correction python opt_loop_advanced.py - The script will open a window showing the optimization process. Press
qorEscto stop. - The output video (
projection_evolution.mp4) and comparison image (comparison.jpg) will be saved in thecolor_correctiondirectory.
You can adjust various hyper-parameters within the opt_loop_advanced.py script, such as:
TARGET_SIZE: Resolution for processing.FPS: Output video frame rate.INITIAL_BEAMER_OUT_VALUE: Starting brightness for the projector simulation.AMBIENT_LIGHT_STRENGTH: Simulated ambient light level.LEARNING_RATE,BETA1,BETA2: Adam optimizer parameters.RGB_LOSS_W: Weight for the RGB loss component.