diff options
| author | Vasil Zlatanov <v@skozl.com> | 2018-10-17 10:48:48 +0100 | 
|---|---|---|
| committer | Vasil Zlatanov <v@skozl.com> | 2018-10-17 10:48:48 +0100 | 
| commit | be452fa1d003e6126d9407959d4cdecad3f77a4c (patch) | |
| tree | 617903657e7b9961d98acc987fa27912b56da180 | |
| download | vz215_np1915-be452fa1d003e6126d9407959d4cdecad3f77a4c.tar.gz vz215_np1915-be452fa1d003e6126d9407959d4cdecad3f77a4c.tar.bz2 vz215_np1915-be452fa1d003e6126d9407959d4cdecad3f77a4c.zip | |
Add script which converts images to vectors
| -rwxr-xr-x | image-to-array | 36 | 
1 files changed, 36 insertions, 0 deletions
| diff --git a/image-to-array b/image-to-array new file mode 100755 index 0000000..2c865f9 --- /dev/null +++ b/image-to-array @@ -0,0 +1,36 @@ +#!/usr/bin/env python +import numpy as np +import sys, os +import getopt + +from PIL import Image; + +def jpg_image_to_array(image_path): +  """ +  Loads JPEG image into 3D Numpy array of shape  +  (width, height, channels) +  """ +  with Image.open(image_path) as image:          +    im_arr = np.frombuffer(image.tobytes(), dtype=np.uint8) +    # im_arr = im_arr.reshape((image.size[1], image.size[0], 3))                                    +  return im_arr + +def main(files): +   for i in range(0, len(files)): +       inputfile = files[i] +       print(inputfile); + +       if not os.path.exists(inputfile): +           sys.exit('ERROR: File %s was not found!' % inputfile) + +       print(jpg_image_to_array(inputfile)) + +if __name__ == "__main__": +   if len(sys.argv) > 1: +       main(sys.argv[1:]) +   else: +       print("%s: You must specify files to convert to vectors" % sys.argv[0]) + +# def compute_average_vector + +# def compute_covariance_of_normalised_faces | 
