Color transfer between two images using covariance alignment in correlated RGB space.
This repository contains:
- MATLAB implementation:
Color_Transfer_CCS.m,ColorTransferDemo.m - Python notebook:
Colortransfer.ipynb - Python CLI demo:
color_transfer_demo.py - Example images:
files. - Report:
Djahnine_Aissam_Color_Transfer_in_Correlated_color_space.pdf
Given a source and target image, the method:
- Computes channel means and covariance matrices.
- Uses SVD to decorrelate/re-correlate color distributions.
- Applies translation + rotation + scaling transforms.
- Produces a source-shaped output with target-like color statistics.
From the repo root:
cd /Users/aissam/ColorTransfer
uv syncThis creates .venv and installs required runtime dependencies.
uv run color-transfer --save outputsThis processes:
files./source.jpg+files./target.jpgfiles./source_1.jpg+files./target_1.jpgfiles./source_2.jpg+files./target_2.jpgfiles./source_3.jpg+files./target_3.jpg
and writes:
outputs/result.jpgoutputs/result_1.jpgoutputs/result_2.jpgoutputs/result_3.jpg
uv run color-transfer --source /path/to/source.jpg --target /path/to/target.jpg --save outputsuv run color-transfer --save outputs --show
uv run color-transfer --save outputs --save-preview-grid previews--save-preview-grid writes side-by-side comparison images (preview*.jpg).
uv run color-transfer --method histogram --postprocess clip --save outputs --save-preview-grid previews --metrics-file outputs/histogram_metrics.csvUse --method ccs (default) to switch back to the correlated-color-space transform.
uv run color-transfer --helpImportant options:
--method {ccs,histogram}: choose algorithm (default:ccs)--source,--target: process one pair explicitly--pairs: number of indexed pairs in--base-dir(batch mode)--save/--save-dir: output directory for result images--show: OpenCV display windows--save-preview-grid: save source/target/result side-by-side grids--postprocess {minmax,clip,percentile}: output scaling mode--percentile-low,--percentile-high: percentile bounds for percentile mode--eps: eigenvalue regularization epsilon (stability for low-variance targets)--metrics-file: write run metrics to.jsonor.csv
Example:
uv run color-transfer --save outputs --metrics-file outputs/metrics.csv
uv run color-transfer --save outputs --metrics-file outputs/metrics.jsonMetrics include per-pair runtime, source/target dimensions, and per-channel mean/std for source, target, and result.
Install dev dependencies and run tests:
uv sync --group dev
uv run --group dev pytestCurrent tests cover:
- shape/type invariants
- deterministic behavior for same inputs
- no crash on mismatched image sizes and degenerate targets
Main function:
function est_im = Color_Transfer_CCS(source, target)Demo script:
ColorTransferDemoAlgorithm write-up:
Djahnine_Aissam_Color_Transfer_in_Correlated_color_space.pdf