-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsample.py
34 lines (27 loc) · 1.1 KB
/
sample.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
import matplotlib.pyplot as plt
import numpy as np
import argparse
from PIL import Image
parser = argparse.ArgumentParser()
parser.add_argument('input', metavar='IMAGE_PATH')
parser.add_argument('-q', '--quality', dest='quality', required=False, default=None, metavar='QUALITY', type=int)
parser.add_argument('--show', dest='show', action='store_const', const=True, required=False, default=True)
parser.add_argument('-o', '--save', dest='save', required=False, default=None, metavar='OUTPUT_PATH')
def show_images(images):
n = len(images)
f = plt.figure()
for i in range(n):
f.add_subplot(1, n, i + 1)
plt.axis("off")
plt.imshow(images[i], cmap='gray')
plt.show(block=True)
if __name__ == '__main__':
args = parser.parse_args()
from noiseprint2 import gen_noiseprint, normalize_noiseprint
path = args.input
input_image = np.asarray(Image.open(path))
noiseprint = gen_noiseprint(path, quality=args.quality)
if args.save is not None:
np.save(args.save, noiseprint)
if args.show:
show_images((input_image, normalize_noiseprint(noiseprint)))