From 4c0f52e7f3a0644885824d906da010c06280a20b Mon Sep 17 00:00:00 2001 From: soumik12345 <19soumik.rakshit96@gmail.com> Date: Tue, 17 Aug 2021 00:20:52 +0530 Subject: [PATCH] Added CLI for python version --- README.md | 33 ++++++++++++++++++++++++++++++++- colorize.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 colorize.py diff --git a/README.md b/README.md index 2bd809f..af18b20 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,38 @@ build-failing Python and C++ implementations of a user-guided image/video colorization technique as proposed by the paper -[Colorization Using Optimization](https://dl.acm.org/doi/10.1145/1015706.1015780). +[Colorization Using Optimization](https://dl.acm.org/doi/10.1145/1015706.1015780). The algorithm is based on a simple premise; neighboring pixels in space-time that have similar intensities should have similar colors. This premise is formalized using a quadratic cost function and obtain an optimization problem that can be solved efficiently using standard techniques. While using this alogorithm, an artist only needs to annotate the image with a few color scribbles or visual clues, and the indicated colors are automatically propagated in both space and time to produce a fully colorized image or sequence. The annotation can be done using any drawing tool such as [JSPaint](https://jspaint.app/) or [Gimp](https://www.gimp.org/). + +## Instructions + +### Instructions for running python version + +1. Create a virtualenv using: + - `virtualenv venv --python=python3` + - `source venv/bin/activate` + - `pip install -r requirements.txt` + +2. Colorize images using the CLI: + ``` + Options: + --original_image TEXT Original Image Path + --visual_clue TEXT Visual Clue Image Path + --result_path TEXT Colorized Image Path (without file extensions) + -i, --use_itercative Use Iterative Mode + --epochs INTEGER Number of epochs for Iterative Mode + --log_intervals INTEGER Log Interval + --help Show this message and exit. + ``` + +### Instructions to build C++ version + +1. Install dependencies using `sh install.sh` + +2. Create a build directory `mkdir build && cd build` + +3. Generate makefiles and compile using `cmake .. && make` + +4. Run the executable using `./colorization [input-image] [visual-clues] [result] [gamma] [threshold]` ## Results diff --git a/colorize.py b/colorize.py new file mode 100644 index 0000000..b0db267 --- /dev/null +++ b/colorize.py @@ -0,0 +1,39 @@ +import cv2 +import click + +from colorization import Colorizer, IterativeColorizer + + +@click.command() +@click.option('--original_image', help='Original Image Path') +@click.option('--visual_clue', help='Visual Clue Image Path') +@click.option('--result_path', default='./result', help='Colorized Image Path (without file extensions)') +@click.option('--use_itercative', '-i', is_flag=True, help='Use Iterative Mode') +@click.option('--epochs', default=500, help='Number of epochs for Iterative Mode') +@click.option('--log_intervals', default=100, help='Log Interval') +def colorize(original_image, visual_clue, result_path, use_itercative, epochs, log_intervals): + if use_itercative: + colorizer = Colorizer( + gray_image_file=original_image, + visual_clues_file=visual_clue + ) + colorizer.plot_inputs() + result = colorizer.colorize() + colorizer.plot_results(result) + cv2.imwrite(result_path + '.png', result) + else: + colorizer = IterativeColorizer( + original_image=original_image, + visual_clues=visual_clue + ) + colorizer.plot_inputs() + colorizer.colorize( + epochs=epochs, log_interval=log_intervals + ) + colorizer.plot_results(log_intervals=log_intervals) + for i, result in enumerate(colorizer.result_history): + cv2.imwrite(result_path + '{}.png'.format(i + 1), result) + + +if __name__ == '__main__': + colorize()