-
Notifications
You must be signed in to change notification settings - Fork 0
/
featureExtractor.py
73 lines (62 loc) · 1.67 KB
/
featureExtractor.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
from skimage.draw import circle
import numpy as np
import skimage.io
import math
from skimage.viewer import ImageViewer
import csv
import time
import os
def calcRadius(shape):
val = float(min(shape[0],shape[1]))/2
radii = [None]*5
radii[4] = val
for i in range(0,4):
radii[i] = (float(math.sqrt(i+1))*radii[4])/math.sqrt(5)
return radii
directory = '/media/aparna/C6A2E75FA2E7530B/Users/admin/Documents/subset'
images = os.listdir(directory)
csvfile = open('features32.csv', 'wb')
writer = csv.writer(csvfile, delimiter=',')
for imgname in images:
print imgname
img = skimage.io.imread(directory+'/'+imgname)
x,y = np.shape(img)
center = (x/2,y/2)
subimg = [None]*5
subimg[0] = np.array(img[0:center[0],0:center[1]])
subimg[1] = img[0:center[0],center[1]:y]
subimg[2] = img[center[0]:x,0:center[1]]
subimg[3] = img[center[0]:x,center[1]:y]
xl = int(center[0]-float(x)/4)
xr = int(center[0]+float(x)/4)
yu = int(center[1]-float(y)/4)
yd = int(center[1]+float(y)/4)
subimg[4] = img[xl:xr,yu:yd]
shape = np.shape(subimg[0])
radii = calcRadius(shape)
subimx = float(shape[0])/2.0
subimy = float(shape[1])/2.0
points = []
for i in range(0,5):
points.append([])
for k in range(0,5):
rr,cc = circle(subimx, subimy, radii[k])
for i,j in zip(rr,cc):
points[k].append((i,j))
for i in range(4,0,-1):
points[i] = [p for p in points[i] if p not in points[i-1]]
k=1
feat = [None]*41
feat[0]=imgname
for im in subimg:
for pt in points[1:5]:
m=0
std = 0
for t in pt:
m = m + im[t[0]][t[1]]
std = std + (im[t[0]][t[1]])**2
feat[k] = float(m)/len(pt)
feat[k+1] = std - len(pt)*(feat[k]**2)
k = k + 2
writer.writerow(feat)
csvfile.close()