-
Notifications
You must be signed in to change notification settings - Fork 0
/
histograms.py
36 lines (26 loc) · 905 Bytes
/
histograms.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
import numpy as np
import matplotlib.pyplot as plt
import argparse
import os
from PIL import Image
parser = argparse.ArgumentParser()
parser.add_argument('directory')
parser.add_argument('-n', '--normalize', action='store_true')
args = parser.parse_args()
if not os.path.exists("./histograms"):
os.makedirs("./histograms")
for file in os.listdir(args.directory):
# if not file.endswith("_raw.png"):
# continue
print(file)
with Image.open(args.directory + "/" + file) as img:
data = np.asarray(img)
data = data / 256
plt.clf()
if args.normalize:
data = data - np.mean(data)
data = data / np.std(data)
else:
plt.xlim(0, 20)
plt.hist(data.flatten(), bins=20)
plt.savefig("./histograms/" + os.path.splitext(file)[0] + "_hist.png")