-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcolorizer.py
More file actions
executable file
·70 lines (54 loc) · 2.32 KB
/
colorizer.py
File metadata and controls
executable file
·70 lines (54 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
'''
Copyright 2014 Samuel Bucheli
This file is part of ColorizationUsingOptimizationInPython.
ColorizationUsingOptimizationInPython is free software: you can
redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software
Foundation, either version 2 of the License, or (at your option)
any later version.
ColorizationUsingOptimizationInPython is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even
he implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ColorizationUsingOptimizationInPython. If not, see
<http://www.gnu.org/licenses/>.
'''
"""A Python implementation of Colorization Using Optimization
This code is based on
Levin, Anat, Dani Lischinski, and Yair Weiss.
"Colorization using optimization."
In ACM Transactions on Graphics (TOG), vol. 23, no. 3, pp. 689-694. ACM, 2004.
http://www.cs.huji.ac.il/~yweiss/Colorization/
Example usage:
$ python colorizer.py inputGrey.png inputMarked.png output.png --view
"""
import argparse
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
from colorizationSolver import colorize
def main():
# parse command line arguments
parser = argparse.ArgumentParser(description='Colorize pictures')
parser.add_argument('greyImage', help='png image to be coloured')
parser.add_argument('markedImage', help='png image with colour hints')
parser.add_argument('output', help='png output file')
parser.add_argument('-v', '--view', help='display image', action='store_true')
args = parser.parse_args()
# Note: when reading .png, division by 255. is not required
# Note: when reading .bmp, division by 255. is required
# TODO: make this more universal, i.e., support various image formats
# read images
greyImage = mpimg.imread(args.greyImage, format='png')
markedImage = mpimg.imread(args.markedImage, format='png')
# colorize
colouredImage = colorize(greyImage, markedImage)
# save output
mpimg.imsave(args.output,colouredImage, format='png')
# display output, if requested
if args.view:
plt.imshow(colouredImage)
plt.show()
if __name__ == "__main__":
main()