Exemplo n.º 1
0
def test_rotate_interpolation(interpolation):
    image = np.random.randint(low=0, high=256, size=(100, 100, 3), dtype=np.uint8)
    mask = np.random.randint(low=0, high=2, size=(100, 100), dtype=np.uint8)
    aug = A.Rotate(limit=(45, 45), interpolation=interpolation, p=1)
    data = aug(image=image, mask=mask)
    expected_image = F.rotate(image, 45, interpolation=interpolation, border_mode=cv2.BORDER_REFLECT_101)
    expected_mask = F.rotate(mask, 45, interpolation=cv2.INTER_NEAREST, border_mode=cv2.BORDER_REFLECT_101)
    assert np.array_equal(data["image"], expected_image)
    assert np.array_equal(data["mask"], expected_mask)
Exemplo n.º 2
0
def test_maybe_process_in_chunks():
    image = np.random.randint(0, 256, (100, 100, 6), np.uint8)

    for i in range(1, image.shape[-1] + 1):
        before = image[:, :, :i]
        after = F.rotate(before, angle=1)
        assert before.shape == after.shape
Exemplo n.º 3
0
 def apply(self, image, mask, rand_h, rand_w, angle, **params):
     image_masked = image.copy()
     h, w = image_masked.shape[:2]
     mask = F.rotate(mask, angle) if self.rotate[1] > 0 else mask
     mask = mask[:, :, np.newaxis] if image_masked.ndim == 3 else mask
     image_masked *= mask[rand_h:rand_h + h,
                          rand_w:rand_w + w].astype(image_masked.dtype)
     return image_masked
Exemplo n.º 4
0
def test_compare_rotate_float_and_shift_scale_rotate_float(float_image):
    rotated_img_1 = F.rotate(float_image, angle=60)
    rotated_img_2 = F.shift_scale_rotate(float_image,
                                         angle=60,
                                         scale=1,
                                         dx=0,
                                         dy=0)
    assert np.array_equal(rotated_img_1, rotated_img_2)
Exemplo n.º 5
0
 def apply(self, image, mask, rand_h, rand_w, angle, **params):
     h, w = image.shape[:2]
     if self.fill_value == 255: image = 255 - image
     mask = F.rotate(mask, angle) if self.rotate[1] > 0 else mask
     mask = mask[:, :, np.newaxis] if image.ndim == 3 else mask
     print(np.mean(mask))
     image *= mask[rand_h:rand_h + h, rand_w:rand_w + w].astype(image.dtype)
     return 255 - image if self.fill_value == 255 else image
Exemplo n.º 6
0
    def apply(self, image, mask, rand_h, rand_w, angle, **params):
        h, w = image.shape[:2]
#         print(f'h : {h}, w :{w}')
        mask = F.rotate(mask, angle) if self.rotate[1] > 0 else mask
        mask = mask[:,:,np.newaxis] if image.ndim == 3 else mask
#         print('mask shape : ', mask[rand_h:rand_h+h, rand_w:rand_w+w].astype(image.dtype).shape)
#         print('img shape : ', image.shape)
        try:
            image *= mask[rand_h:rand_h+h, rand_w:rand_w+w].astype(image.dtype)
        except :
            pass
        return image
Exemplo n.º 7
0
    def apply(self, image, **params):
        h, w = image.shape[:2]

        if self.masks is None: self.init_masks(h, w)

        mask = rng.choice(self.masks)
        rand_h = np.random.randint(self.hh - h)
        rand_w = np.random.randint(self.hh - w)
        angle = np.random.randint(self.rotate[0],
                                  self.rotate[1]) if self.rotate[1] > 0 else 0

        mask = F.rotate(mask, angle) if self.rotate[1] > 0 else mask
        mask = mask[:, :, np.newaxis] if image.ndim == 3 else mask
        image *= mask[rand_h:rand_h + h, rand_w:rand_w + w].astype(image.dtype)
        return image
Exemplo n.º 8
0
 def apply(self, image, mask, rand_h, rand_w, angle, **params):
     h, w = image.shape[:2]
     mask = F.rotate(mask, angle) if self.rotate[1] > 0 else mask
     mask = mask[:, :, np.newaxis] if image.ndim == 3 else mask
     # image = np.maximum( image, mask[rand_h : rand_h +h, rand_w: rand_w + w].astype(image.dtype) )
     bool_arr = np.random.randint(0, 2, size=image.shape, dtype=bool)
     if self.mode != 1:
         for i in range(bool_arr.shape[2]):
             bool_arr[:, :, i] = np.squeeze(mask[rand_h:rand_h + h,
                                                 rand_w:rand_w +
                                                 w] == self.fill_val)
     else:
         for i in range(bool_arr.shape[2]):
             bool_arr[:, :, i] = np.squeeze(mask[rand_h:rand_h + h,
                                                 rand_w:rand_w +
                                                 w] == self.fill_val)
     image[bool_arr] = self.fill_val
     return image
Exemplo n.º 9
0
    def apply(self, image, mask, rand_h, rand_w, angle, **params):

        mask = F.rotate(mask, angle) if self.rotate[1] > 0 else mask

        if (image.shape[2] == 3) | (image.shape[2] == 1):  #channel last
            h, w = image.shape[:2]
            mask = mask[:, :, np.newaxis]
            image *= mask[rand_h:rand_h + h,
                          rand_w:rand_w + w].astype(image.dtype)

        else:  # channel first
            h, w = image.shape[1:]
            mask = mask[np.newaxis, :, :]
            image *= mask[:, rand_h:rand_h + h,
                          rand_w:rand_w + w].astype(image.dtype)

#         h, w = image.shape[:2]
#         mask = F.rotate(mask, angle) if self.rotate[1] > 0 else mask
#         mask = mask[:,:,np.newaxis] if image.ndim == 3 else mask
#         mask = mask[:, :, np.newaxis] if (image.shape[2]==3) & (image.shape[2]==1) else mask[np.newaxis, :, :]
#         image *= mask[rand_h:rand_h+h, rand_w:rand_w+w].astype(image.dtype)
        return image
Exemplo n.º 10
0
 def albumentations(self, img):
     return albumentations.rotate(img, angle=-45)
def test_compare_rotate_and_shift_scale_rotate(image):
    rotated_img_1 = F.rotate(image, angle=60)
    rotated_img_2 = F.shift_scale_rotate(image, angle=60, scale=1, dx=0, dy=0)
    assert np.array_equal(rotated_img_1, rotated_img_2)
Exemplo n.º 12
0
 def apply(self, img, **params):
     return [F.rotate(img, angle) for angle in self.angles]
Exemplo n.º 13
0
 def albumentations(self, img):
     return albumentations.rotate(img, angle=-45)
Exemplo n.º 14
0
 def apply(self, image, mask, rand_h, rand_w, angle, **kwargs):
     h, w = image.shape[:2]
     mask = F.rotate(mask, angle) if self.rotate[1] > 0 else mask
     mask = mask[..., np.newaxis] if image.ndim == 3 else mask
     image *= mask[rand_h:rand_h + h, rand_w:rand_w + w].astype(image.dtype)
     return image
Exemplo n.º 15
0
 def apply_to_mask(self, img, **params):
     return functional.rotate(img, self.angle, cv2.INTER_NEAREST,
                              self.border_mode, self.mask_value)
Exemplo n.º 16
0
 def apply(self, img, interpolation=cv2.INTER_LINEAR, **params):
     return functional.rotate(img, self.angle, interpolation,
                              self.border_mode, self.value)