| 102 | |
| 103 | |
| 104 | def crop_and_resave(inputfile, outputdir): |
| 105 | # theoretically, we could try to find the face |
| 106 | # but let's be lazy |
| 107 | # we assume that the middle 108 pixels will contain the face |
| 108 | im = imread(inputfile) |
| 109 | height, width, color = im.shape |
| 110 | edge_h = int( round( (height - 108) / 2.0 ) ) |
| 111 | edge_w = int( round( (width - 108) / 2.0 ) ) |
| 112 | |
| 113 | cropped = im[edge_h:(edge_h + 108), edge_w:(edge_w + 108)] |
| 114 | small = imresize(cropped, (64, 64)) |
| 115 | |
| 116 | filename = inputfile.split('/')[-1] |
| 117 | imsave("%s/%s" % (outputdir, filename), small) |
| 118 | |
| 119 | |
| 120 | def scale_image(im): |