-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (29 loc) · 1.05 KB
/
main.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
import imageio
import numpy as np
import blending
def read_image(path) -> np.ndarray:
data = imageio.imread(path)
return np.array(data) / 255
def read_mask(path) -> np.ndarray:
image = read_image(path)
return image.mean(axis=2)
def write_image(image: np.ndarray, path):
image = (image - image.min()) / (image.max() - image.min())
image = image * 255
image = np.clip(image, 0, 255)
image = image.astype(np.uint8)
imageio.imwrite(path, image)
def compute_num_levels(image: np.ndarray):
h, w, c = image.shape
return int(np.floor(np.log2(min(h, w))))
if __name__ == "__main__":
# in png format
target = read_image("target.png")
source = read_image("source.png")
mask = read_mask("mask.png")
blender = blending.MultiBandBlending(num_levels=compute_num_levels(target))
composite = blender(target, source, mask)
write_image(composite, ".output_multiband.png")
blender = blending.NaiveBlending()
composite = blender(target, source, mask)
write_image(composite, ".output_naive.png")