def normalize_bitmap(bitmap):
# pad the bitmap to make it squared
pad_size = abs(bitmap.shape[0]-bitmap.shape[1]) // 2
if bitmap.shape[0] < bitmap.shape[1]:
pad_dims = ((pad_size, pad_size), (0, 0))
else:
pad_dims = ((0, 0), (pad_size, pad_size))
bitmap = np.lib.pad(bitmap, pad_dims, mode='constant', constant_values=255)
# rescale and add empty border
bitmap = scipy.misc.imresize(bitmap, (64 - 4*2, 64 - 4*2))
bitmap = np.lib.pad(bitmap, ((4, 4), (4, 4)), mode='constant', constant_values=255)
assert bitmap.shape == (64, 64)
bitmap = np.expand_dims(bitmap, axis=0)
assert bitmap.shape == (1, 64, 64)
return bitmap
评论列表
文章目录