Example #1
0
def test_shift_scale_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.ShiftScaleRotate(shift_limit=(0.2, 0.2),
                             scale_limit=(1.1, 1.1),
                             rotate_limit=(45, 45),
                             interpolation=interpolation,
                             p=1)
    data = aug(image=image, mask=mask)
    expected_image = FGeometric.shift_scale_rotate(
        image,
        angle=45,
        scale=2.1,
        dx=0.2,
        dy=0.2,
        interpolation=interpolation,
        border_mode=cv2.BORDER_REFLECT_101)
    expected_mask = FGeometric.shift_scale_rotate(
        mask,
        angle=45,
        scale=2.1,
        dx=0.2,
        dy=0.2,
        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)
Example #2
0
def test_shift_scale_separate_shift_x_shift_y(image, mask):
    aug = A.ShiftScaleRotate(shift_limit=(0.3, 0.3),
                             shift_limit_y=(0.4, 0.4),
                             scale_limit=0,
                             rotate_limit=0,
                             p=1)
    data = aug(image=image, mask=mask)
    expected_image = FGeometric.shift_scale_rotate(
        image,
        angle=0,
        scale=1,
        dx=0.3,
        dy=0.4,
        interpolation=cv2.INTER_LINEAR,
        border_mode=cv2.BORDER_REFLECT_101)
    expected_mask = FGeometric.shift_scale_rotate(
        mask,
        angle=0,
        scale=1,
        dx=0.3,
        dy=0.4,
        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)
Example #3
0
def test_compare_rotate_float_and_shift_scale_rotate_float(float_image):
    rotated_img_1 = FGeometric.rotate(float_image, angle=60)
    rotated_img_2 = FGeometric.shift_scale_rotate(float_image,
                                                  angle=60,
                                                  scale=1,
                                                  dx=0,
                                                  dy=0)
    assert np.array_equal(rotated_img_1, rotated_img_2)
Example #4
0
def test_scale_from_shift_scale_rotate(target):
    img = np.array(
        [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]],
        dtype=np.uint8)
    expected = np.array(
        [[6, 7, 7, 8], [10, 11, 11, 12], [10, 11, 11, 12], [14, 15, 15, 16]],
        dtype=np.uint8)
    img, expected = convert_2d_to_target_format([img, expected], target=target)
    scaled_img = FGeometric.shift_scale_rotate(img,
                                               angle=0,
                                               scale=2,
                                               dx=0,
                                               dy=0,
                                               interpolation=cv2.INTER_NEAREST,
                                               border_mode=cv2.BORDER_CONSTANT)
    assert np.array_equal(scaled_img, expected)
Example #5
0
def test_scale_float_from_shift_scale_rotate(target):
    img = np.array(
        [[0.01, 0.02, 0.03, 0.04], [0.05, 0.06, 0.07, 0.08],
         [0.09, 0.10, 0.11, 0.12], [0.13, 0.14, 0.15, 0.16]],
        dtype=np.float32,
    )
    expected = np.array(
        [[0.06, 0.07, 0.07, 0.08], [0.10, 0.11, 0.11, 0.12],
         [0.10, 0.11, 0.11, 0.12], [0.14, 0.15, 0.15, 0.16]],
        dtype=np.float32,
    )
    img, expected = convert_2d_to_target_format([img, expected], target=target)
    scaled_img = FGeometric.shift_scale_rotate(img,
                                               angle=0,
                                               scale=2,
                                               dx=0,
                                               dy=0,
                                               interpolation=cv2.INTER_NEAREST,
                                               border_mode=cv2.BORDER_CONSTANT)
    assert_array_almost_equal_nulp(scaled_img, expected)
Example #6
0
 def albumentations(self, img):
     return shift_scale_rotate(img, angle=-45, scale=2, dx=0.2, dy=0.2)