/
create_feature.py
45 lines (40 loc) · 1.24 KB
/
create_feature.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
from feature_moments import getShapeFeatures
from feature_gabor import *
from feature_color import getColorFeature
from img_seg import *
def createFeature(img):
'''
Creates the feature vector of the image using the three features -
color, texture, and shape features
'''
feature = []
areaFruit, binaryImg, colourImg, areaSkin, fruitContour, pix_to_cm_multiplier = getAreaOfFood(img)
color = getColorFeature(colourImg)
texture = getTextureFeature(colourImg)
shape = getShapeFeatures(binaryImg)
for i in color:
feature.append(i)
for i in texture:
feature.append(i)
for i in shape:
feature.append(i)
M = max(feature)
m = min(feature)
feature = map(lambda x: x * 2, feature)
feature = (feature - M - m)/(M - m);
mean=np.mean(feature)
dev=np.std(feature)
feature = (feature - mean)/dev;
return feature, areaFruit, areaSkin, fruitContour, pix_to_cm_multiplier
def readFeatureImg(filename):
'''
Reads an input image when the filename is given,
and creates the feature vector of the image.
'''
img = cv2.imread(filename)
f, farea, skinarea, fcont, pix_to_cm = createFeature(img)
return f, farea, skinarea, fcont, pix_to_cm
if __name__ == '__main__':
import sys
f = readFeatureImg(sys.argv[1])
print f, len(f)