def augment(self,im):
"""
augmentation includes: mean subtract, random crop, random mirror, random rotation
"""
#random rotation
if self.rot != 0:
rot_ang = np.random.randint(self.rot[0], high = self.rot[1]+1)
im = ndimage.rotate(im.astype(np.uint8), rot_ang, \
cval=255,reshape = False)
#mean subtract and scaling
im = np.float32(im)
im -= self.mean
im *= self.scale
#random flip
flip = np.random.choice(2)*2-1
im = im[:, ::flip]
#random crop
y_offset = np.random.randint(im.shape[0] - self.outshape[0] - 8)
x_offset = np.random.randint(im.shape[1] - self.outshape[1] - 8)
return im[4+y_offset:4+self.outshape[0]+y_offset,
4+x_offset:4+self.outshape[1]+x_offset]
#return im
评论列表
文章目录