def execute(self, image, mask):
     x, y, z, _ = image.shape
     image = image.reshape((x, y, z))
     mask = np.argmax(mask, axis=-1)
     newx = x + int(scale_truncated_norm(self.std))
     newy = y + int(scale_truncated_norm(self.std))
     newz = z + int(scale_truncated_norm(self.std))
     image = scale3d(image, newx, newy, newz, cv2.INTER_CUBIC)
     mask = scale3d(mask, newx, newy, newz, cv2.INTER_NEAREST)
     image = image.reshape(image.shape + (1,))
     mask = to_channels(mask)
     return image, mask
    def execute(self, image, mask):
        x, y, z, _ = image.shape
        dx, dy, dz = abs(int(scale_truncated_norm(self.std))),  abs(
            int(scale_truncated_norm(self.std))),  abs(int(scale_truncated_norm(self.std)))
        newx = x - dx
        newy = y - dy
        newz = z - dz
        sx, sy, sz = np.random.choice(range(dx)), np.random.choice(
            range(dy)), np.random.choice(range(dz))

        image = image[sx: sx + newx, sy: sy + newy, sz: sz + newz, :]
        mask = mask[sx: sx + newx, sy: sy + newy, sz: sz + newz, :]

        return image, mask
 def random_affine_warp_fn(self, vertex_percentage_std):
     source_points = [[0, 0, 0], [0, 100, 0], [0, 0, 100], [100, 0, 0]]
     dest_points = np.array(
         [[v + scale_truncated_norm(vertex_percentage_std)[0] for v in p]
          for p in source_points])
     return lambda img, is_mask: self.affine_warp(img, source_points,
                                                  dest_points, is_mask)
Пример #4
0
 def apply_variability(value, std):
     res = value + scale_truncated_norm(std)[0]
     if res > 1:
         res = 1
     if res < 0:
         res = 0
     return res
 def random_elastic_deform_fn(self, sigma_std, possible_points):
     sigma = scale_truncated_norm(sigma_std)
     points = np.random.choice(possible_points)
     return lambda img, mask: self.elastic_deform(img, mask, sigma, points)
 def random_swirl_fn(self, strength_std, r):
     ax = random.choice(AXES)
     s = scale_truncated_norm(strength_std)
     return lambda img, is_mask: self.swirl(img, ax, s, r, is_mask)
Пример #7
0
 def random_shift_fn(self, shift_stds):
     shifts = [scale_truncated_norm(s) for s in shift_stds]
     return lambda img, is_mask: self.shift(img, shifts, is_mask)
 def random_uniaxial_rotation_fn(self, std):
     d = scale_truncated_norm(std)
     a = random.choice(AXES)
     return lambda img, is_mask: self.rotate(img, d, a, is_mask)
def random_linear_gradient_fn(stds):
    gx, gy, gz = [scale_truncated_norm(s)[0] for s in stds]
    return lambda img, is_mask: apply_gradient(
        img, lambda x, y, z: gx * x + gy * y + gz * z, is_mask)