def do_augmentation(array): """Augmentation for the training data. :array: A numpy array of size [c, x, y, z] :returns: augmented image and the corresponding mask """ # normalize image to range [0, 1], then apply this transform patch_size = np.asarray(array.shape)[1:] augmented = noise_transforms.augment_gaussian_noise(array, noise_variance=(0, .015)) # need to become [bs, c, x, y, z] before augment_spatial augmented = augmented[None, ...] # mask = mask[None, None, ...] r_range = (0, (3 / 360.) * 2 * np.pi) cval = 0. augmented, _ = spatial_transforms.augment_spatial( augmented, patch_size=patch_size, seg=None, do_rotation=True, angle_x=r_range, angle_y=r_range, angle_z=r_range, do_scale=True, scale=(.9, 1.1), border_mode_data='constant', border_cval_data=cval, order_data=3, p_scale_per_sample=.5, p_rot_per_sample=.5, random_crop=False) return augmented[0]
def do_augmentation(self, array, mask): #array = array[None, ...] patch_size = np.asarray(array.shape) augmented = noise_transforms.augment_gaussian_noise( array, noise_variance=(0, .015)) # need to become [bs, c, x, y, z] before augment_spatial augmented = augmented[None, None, ...] mask = mask[None, None, ...] r_range = (0, (15 / 360.) * 2 * np.pi) r_range2 = (0, (3 / 360.) * 2 * np.pi) cval = 0. augmented, mask = spatial_transforms.augment_spatial( augmented, seg=mask, patch_size=patch_size, do_elastic_deform=True, alpha=(0., 100.), sigma=(8., 13.), do_rotation=True, angle_x=r_range2, angle_y=r_range2, angle_z=r_range, do_scale=True, scale=(.9, 1.1), border_mode_data='constant', border_cval_data=cval, order_data=1, p_el_per_sample=0.5, p_scale_per_sample=.5, p_rot_per_sample=.5, random_crop=False) mask = mask[0] augmented = (augmented[0, 0, :, :, :]).astype(np.uint8) return augmented, mask