Image color replacement using numerical optimization.
pip install -r requirements.txt
- Edit
config.yml
(configuration options explanation below) python image_color_replacement.py
input_image_path
: Path of source (input) imageoutput_image_path
: Path to save target imageintermeidate_representation_path
(optional): Path to save intermediate image representationsfrom_colors
: List of RGB colors to replaceto_colors
: List of RGB colors with which to replace colors fromfrom_colors
, in matching orderfixed_colors
: List of RGB colors that shouldn't changelatent_color_components_k
: Number of latent color componentsoptimization_scale
: How much to downscale image before performing optimization (it is not a good idea to optimize on an unscaled large image)wolfe_conditions
: Wolfe line search parameters (only used if BFGS implementation is "scratch
")penalty_weights
: List of penalty weights (weighting objective vs. constraint violation)bfgs_max_iterations
: Max BFGS iterations (per penalty weight)bfgs_implementation
: One of "scipy
" and "scratch
", "scipy
" highly advised
See this post for more details.