forked from danijar/seminar-knowledge-mining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeatures.py
39 lines (33 loc) · 1.49 KB
/
features.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
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from helper.plot import plot_image
from helper.extraction import feature_names, feature_vector, get_inputs
def print_features(names, features):
print(len(names), 'features extracted:')
for name, feature in zip(names, features):
print('{name: <25} {feature: >8.4f}'.format(**locals()))
if __name__ == '__main__':
parser = ArgumentParser(description='Extract feature vector of an image.',
formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('filename',
help='Path to the image to extract features from')
parser.add_argument('-o', '--original', action='store_true',
help='Whether to show the original image')
parser.add_argument('-p', '--proprocessed', action='store_true',
help='Whether to show the proprocessed image')
parser.add_argument('-b', '--blobs', action='store_true',
help='Whether to show the extracted blobs')
parser.add_argument('-g', '--gradients', action='store_true',
help='Whether to show the extracted gradients')
args = parser.parse_args()
inputs = get_inputs(args.filename)
if args.original:
plot_image(inputs['original'])
if args.proprocessed:
plot_image(inputs['image'])
if args.blobs:
BlobFeature(**inputs).show()
if args.gradients:
GradientFeature(**inputs).show()
names = feature_names()
features = feature_vector(args.filename)
print_features(names, features)