MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / crop_and_resave

Function crop_and_resave

unsupervised_class3/util.py:104–117  ·  view source on GitHub ↗
(inputfile, outputdir)

Source from the content-addressed store, hash-verified

102
103
104def 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
120def scale_image(im):

Callers 1

get_celebFunction · 0.85

Calls 3

imreadFunction · 0.85
imresizeFunction · 0.85
imsaveFunction · 0.85

Tested by

no test coverage detected