Skip to content

Commit

Permalink
Added CLI for python version
Browse files Browse the repository at this point in the history
  • Loading branch information
soumik12345 committed Aug 16, 2021
1 parent e3afd75 commit 4c0f52e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,38 @@
<img src="https://github.com/soumik12345/colorization-using-optimization/workflows/test/badge.svg" alt="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

Expand Down
39 changes: 39 additions & 0 deletions colorize.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 4c0f52e

Please sign in to comment.