rotate.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:py-data-augmentation 作者: taoyizhi68 项目源码 文件源码
def rotate(images, x_max_rotation, y_max_rotation, z_max_rotation, img_rows, img_cols):
    assert(x_max_rotation >= 0)
    assert(y_max_rotation >= 0)
    assert(z_max_rotation >= 0)
    for i in xrange(images.shape[0]):
        x_rotation = np.random.uniform(-x_max_rotation, x_max_rotation) * np.pi / 180
        y_rotation = np.random.uniform(-y_max_rotation, y_max_rotation) * np.pi / 180
        z_rotation = np.random.uniform(-z_max_rotation, z_max_rotation) * np.pi / 180

        center_matrix1 = np.array([[1, 0, -img_cols/2.], 
                                  [0, 1, -img_rows/2.],
                                  [0, 0, 1]])

        R = np.dot(np.dot(z_matirx(z_rotation), y_matrix(y_rotation)), x_matrix(x_rotation))
        rotate_matrix = np.array([[R[0][0], R[0][1], 0], 
                                  [R[1][0], R[1][1], 0],
                                  [0,       0,       1]])
        #print rotate_matrix
        center_matrix2 = np.array([[1, 0, img_cols/2.], 
                                  [0, 1, img_rows/2.],
                                  [0, 0, 1]]) 

        center_trans1 = transform.AffineTransform(center_matrix1)
        rotate_trans = transform.AffineTransform(rotate_matrix)
        center_trans2 = transform.AffineTransform(center_matrix2)

        affine_trans = center_trans1 + rotate_trans + center_trans2
        images[i] = transform.warp(images[i], affine_trans, mode='edge')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号