-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHSV_channel.py
108 lines (82 loc) · 2.74 KB
/
HSV_channel.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import glob
import os
import sys
from skimage.io import imread
from skimage import color
import numpy as np
from scipy.stats import mode
DIR = "/Users/damoncrockett/Desktop/Seoul_selfies/"
input_paths = [
DIR+"slices_128/",
DIR+"slices_256/",
DIR+"slices_512/"
]
descriptor = "slice"
for input_path in input_paths:
filename = []
hue = []
sat = []
val = []
hue_med = []
sat_med = []
val_med = []
hue_mode = []
sat_mode = []
val_mode = []
hsd = []
ssd = []
vsd = []
counter = -1
for root, dirs, files in os.walk(input_path):
for file in files:
counter +=1
try:
img = color.rgb2hsv(imread(root+"/"+file))
i_hue = np.mean(img[:,:,0])
hue.append(i_hue)
i_sat = np.mean(img[:,:,1])
sat.append(i_sat)
i_val = np.mean(img[:,:,2])
val.append(i_val)
i_hue_med = np.median(img[:,:,0])
hue_med.append(i_hue_med)
i_sat_med = np.median(img[:,:,1])
sat_med.append(i_sat_med)
i_val_med = np.median(img[:,:,2])
val_med.append(i_val_med)
"""
i_hue_mode = float(mode(img[:,:,0],axis=None)[0])
hue_mode.append(i_hue_mode)
i_sat_mode = float(mode(img[:,:,1],axis=None)[0])
sat_mode.append(i_sat_mode)
i_val_mode = float(mode(img[:,:,2],axis=None)[0])
val_mode.append(i_val_mode)
i_hsd = np.std(img[:,:,0])
hsd.append(i_hsd)
i_ssd = np.std(img[:,:,1])
ssd.append(i_ssd)
i_vsd = np.std(img[:,:,2])
vsd.append(i_vsd)
"""
filename.append(root+"/"+file)
print counter, input_path
except:
print counter,file,'error'
import pandas as pd
df = pd.DataFrame({'filename':filename,
'hue_mean':hue,
'sat_mean':sat,
'val_mean':val,
'hue_med':hue_med,
'sat_med':sat_med,
'val_med':val_med})
#'hue_mode':hue_mode,
#'sat_mode':sat_mode,
#'val_mode':val_mode,
#'hsd':hsd,
#'ssd':ssd,
#'vsd':vsd})
df['base'] = df.filename.apply(os.path.basename)
#df.sort("hue_mode",inplace=True)
df.to_csv(input_path+descriptor+'_metadata.csv',index=False)
#df.to_csv(input_path+descriptor+'_metadata.txt',index=False,sep='\t')