-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.py
50 lines (40 loc) · 1.35 KB
/
render.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
import argparse
import cv2
import numpy as np
from PIL import Image
from utils.post_proc import uniform_label
from utils.screentone import ToneLabel, ToneImageGenerator
def main():
parser = argparse.ArgumentParser()
parser.add_argument("line", help="line drawing")
parser.add_argument("label", help="screentone label")
parser.add_argument("--out", default="out.png")
parser.add_argument(
"--out-label",
default="label-vis.png",
help="visualization of the screentone label",
)
args: argparse.Namespace = parser.parse_args()
tone_gen: ToneImageGenerator = ToneImageGenerator()
# read a tone label
label: ToneLabel = ToneLabel.load(args.label)
label.visualize().save(args.out_label)
# width, height
size: tuple = (label.shape[1], label.shape[0])
# read a line drawing
if args.line is None:
line = None
else:
with Image.open(args.line) as f:
line = f.convert("L")
line = line.resize(size, Image.BICUBIC)
line = np.asarray(line, dtype=np.uint8)
# post-process
if args.line is not None:
label.data = uniform_label(label.data, line, thresh=144)
# render a manga image
img_rec: np.ndarray = tone_gen.render(label, line)
# save the manga image
cv2.imwrite(args.out, img_rec)
if __name__ == "__main__":
main()