def image_deformation(self,image):
random_shear_angl = np.random.random() * np.pi/6 - np.pi/12
random_rot_angl = np.random.random() * np.pi/6 - np.pi/12 - random_shear_angl
random_x_scale = np.random.random() * .4 + .8
random_y_scale = np.random.random() * .4 + .8
random_x_trans = np.random.random() * image.shape[0] / 4 - image.shape[0] / 8
random_y_trans = np.random.random() * image.shape[1] / 4 - image.shape[1] / 8
dx = image.shape[0]/2. \
- random_x_scale * image.shape[0]/2 * np.cos(random_rot_angl)\
+ random_y_scale * image.shape[1]/2 * np.sin(random_rot_angl + random_shear_angl)
dy = image.shape[1]/2. \
- random_x_scale * image.shape[0]/2 * np.sin(random_rot_angl)\
- random_y_scale * image.shape[1]/2 * np.cos(random_rot_angl + random_shear_angl)
trans_mat = AffineTransform(rotation=random_rot_angl,
translation=(dx + random_x_trans,
dy + random_y_trans),
shear = random_shear_angl,
scale = (random_x_scale,random_y_scale))
return warp(image,trans_mat.inverse,output_shape=image.shape)
评论列表
文章目录