if np.random.rand() > 0.0: if np.random.rand() > 0.5: indepth =…
- User
if np.random.rand() > 0.0: if np.random.rand() > 0.5: in_depth = add_gaussian_noise(in_depth) if np.random.rand() > 0.5: in_depth = add_salt_and_pepper_noise(in_depth) if np.random.rand() > 0.5: in_depth = downsample_image(in_depth) if np.random.rand() > 0.5: in_depth = draw_random_shapes_on_depth(in_depth) if np.random.rand() > 0.5: rndShiftCoef = np.random.rand() rightTemplate = in_depth.copy() rndOfs = random.randint(2, 8) # 1 if rndShiftCoef <= 0.25: rightTemplate[rndOfs:, :] = in_depth[0:-rndOfs, :] elif rndShiftCoef <= 0.5: rightTemplate[0:-rndOfs, :] = in_depth[rndOfs:, :] elif rndShiftCoef <= 0.75: rightTemplate[:, rndOfs:] = in_depth[:, 0:-rndOfs] else: rightTemplate[:, 0:-rndOfs] = in_depth[:, rndOfs:] in_depth = rightTemplate if np.random.rand() > 0.5: kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)) if np.random.rand() > 0.5: in_depth = cv2.erode(in_depth, kernel, iterations=2, borderType=cv2.BORDER_REPLICATE) else: in_depth = cv2.dilate(in_depth, kernel, iterations=2, borderType=cv2.BORDER_REPLICATE)
if np.random.rand() > 0.5: img = img[:, ::-1, :].copy() depth = depth[:, ::-1].copy() in_depth = in_depth[:, ::-1].copy() if np.random.rand() > 0.5: img = img[::-1, :, :].copy() depth = depth[::-1, :].copy() in_depth = in_depth[::-1, :].copy() - Assistant
This code snippet is part of a data augmentation pipeline commonly used for preparing datasets in machine learning, particularly for training models that involve image or depth data. Let's go through the operations being performed:
-
Adding Gaussian Noise: The code conditionally applies Gaussian noise to the depth data, which is useful for making models robust to noise in real-world data.
-
Adding Salt-and-Pepper Noise: Similarly, another common noise type (salt-and-pepper) is conditionally added. This type mimics random black and white pixels in the image.
-
Downsampling the Image: The in-depth image can be downsampled, potentially simulating lower resolution data.
-