点云数据增强方法

1 随机剔除(Dropout)代码实现:

def random_point_dropout(point,max_dropout_ratio=0.875):
    '''
    point:batch*1024*3,numpy类型
    随机剔除
    随机选取一部分点来用第一个点代替
    '''
    for batch in range(point.shape[0]):
        dropout_ratio=np.random.random()*max_dropout_ratio  # 0~0.875
        # 获取随机剔除的点的索引
        drop_idx=np.where(np.random.random((point.shape[1]))<=dropout_ratio)[0]
        if len(drop_idx)>0:
            point[batch,drop_idx,:]=point[batch,0,:]
    return point 
  1. 随机缩放

    物体随机缩放,点云数据的每个点的(x,y,z)数值大小在[scale_low,scale_high]之间随机改变,

def random_point_scale(point,scale_low=0.8,scale_high=1.25):
    '''
    point: Batch*N*3,numpy类型
    随机缩放
    每个点的数值大小在scale_low~scale_high之间随机改变
    '''
    B,N,C=point.shape
    scales=np.random.uniform(scale_low,scale_high,B)
    for batch in range(B):
        point[batch,:,:] *= scales[batch]
    return point 
  1. 随机平移

点云数据所有点的坐标值(x,y,z)同时加(减)一个数,实现物体的平移

def random_point_shift(point,shift_range=0.1):
    '''
    point:Batch*N*3,numpy类型
    随机平移
    每个点的数值随机加()范围为(-shift_range,shift_range)的随机数
    '''
    B,N,C=point.shape
    shifts=np.random.uniform(-shift_range,shift_range,(B,3))
    for batch in range(B):
        point[batch,:,:] += shifts[batch,:]
    return point 

4 在XYZ上加高斯噪声

def jitter_point(point, sigma=0.01, clip=0.05):
    assert(clip > 0)
    point = np.array(point)
    point = point.reshape(-1,3)
    Row, Col = point.shape
    jittered_point = np.clip(sigma * np.random.randn(Row, Col), -1*clip, clip)
    jittered_point += point
    return jittered_point

5 绕Z轴旋转

def rotate_point(point, rotation_angle):
    point = np.array(point)
    cos_theta = np.cos(rotation_angle)
    sin_theta = np.sin(rotation_angle)
    rotation_matrix = np.array([[cos_theta, sin_theta, 0],
                                [-sin_theta, cos_theta, 0],
                                [0, 0, 1]])
    rotated_point = np.dot(point.reshape(-1, 3), rotation_matrix)
    return rotated_point