-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
answer_84.py
50 lines (41 loc) · 1.12 KB
/
answer_84.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 cv2
import numpy as np
import matplotlib.pyplot as plt
from glob import glob
## Dicrease color
def dic_color(img):
img //= 63
img = img * 64 + 32
return img
## Database
def get_DB():
# get image paths
train = glob("dataset/train_*")
train.sort()
# prepare database
db = np.zeros((len(train), 13), dtype=np.int32)
# each image
for i, path in enumerate(train):
img = dic_color(cv2.imread(path))
# get histogram
for j in range(4):
db[i, j] = len(np.where(img[..., 0] == (64 * j + 32))[0])
db[i, j+4] = len(np.where(img[..., 1] == (64 * j + 32))[0])
db[i, j+8] = len(np.where(img[..., 2] == (64 * j + 32))[0])
# get class
if 'akahara' in path:
cls = 0
elif 'madara' in path:
cls = 1
# store class label
db[i, -1] = cls
img_h = img.copy() // 64
img_h[..., 1] += 4
img_h[..., 2] += 8
plt.subplot(2, 5, i+1)
plt.hist(img_h.ravel(), bins=12, rwidth=0.8)
plt.title(path)
print(db)
plt.show()
# get database
get_DB()