Random rotate spherical projection of point cloud
| 93 | |
| 94 | |
| 95 | class SphRandomRotate: |
| 96 | '''Random rotate spherical projection of point cloud''' |
| 97 | def __init__(self, p, img_size): |
| 98 | assert 0 < p <= 1, 'probability must be in (0, 1] range)!' |
| 99 | self.p = p |
| 100 | self.grid = get_projection_grid(b=(int)(img_size[0]/2.0)) |
| 101 | |
| 102 | def __call__(self, sph_img): |
| 103 | #* conver from PIL.Image into numpy.array |
| 104 | signals = np.expand_dims(np.array(sph_img), axis=0) |
| 105 | #* generate random rotation along all three axis |
| 106 | rot = rand_rotation_matrix(deflection=1) |
| 107 | #* generate random rotation along z-axis |
| 108 | # rot_angle = 2*np.pi*random.uniform(1) |
| 109 | # cosval = np.cos(rot_angle) |
| 110 | # sinval = np.sin(rot_angle) |
| 111 | # rot = np.array([[cosval, -sinval, 0], |
| 112 | # [sinval, cosval, 0], |
| 113 | # [0, 0, 1]]) |
| 114 | rotated_grid = rotate_grid(rot, self.grid) |
| 115 | rot_sph_img = project_2d_on_sphere(signals, rotated_grid, projection_origin=[0,0,0.00001]) |
| 116 | rot_sph_img = np.squeeze(rot_sph_img) |
| 117 | return rot_sph_img |
| 118 | |
| 119 | |
| 120 | class RandomFlip: |