-
Notifications
You must be signed in to change notification settings - Fork 0
/
recolor.py
155 lines (129 loc) · 4.74 KB
/
recolor.py
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/python
import argparse
import os
import re
import colorsys
import skimage.io
import skimage.color
import numpy
from pprint import pprint
### Parse args
cliParser = argparse.ArgumentParser(
description="Recolor - recolor single-colored graphic elements")
cliParser.add_argument('-f',
'--force',
help="Overwrite without prompting.",
action='store_true')
cliParser.add_argument('-c', '--color',
help="Color in #RRGGBB, #RGB, rgb(100%, 0%, 0%), rgb(255,0,0),"
" hsl(359,0%,100%) or hsl(359,255,255) format. Color names are also"
" supported.")
cliParser.add_argument('--outdir',
help="Directory to write the recolored files to. If not specified, "
"the output is written to original_filename.out.original_extension.",
required=False)
cliParser.add_argument('--valuefactor',
help="Factor by which change in value should be accounted for.",
required=False)
cliParser.add_argument('--outfile',
help="Name of the output file.",
required=False)
cliParser.add_argument('infile', help="Input file names", nargs='+')
def process(inFile, outFile, color, valueFactor):
image = skimage.io.imread(inFile)
alpha = None
if image.shape[2] == 4:
alpha = image.compress([False, False, False, True], axis=2)
image = image.compress([True, True, True, False], axis=2)
colorHSV = colorsys.rgb_to_hsv(*color)
colorHSV = [colorHSV[0], colorHSV[1], colorHSV[2]]
imageHSV = skimage.color.rgb2hsv(image)
originalHSV = findMostSaturatedColor(imageHSV)