def test_shift_rgb(shift_params, expected): img = np.ones((100, 100, 3), dtype=np.uint8) * 127 r_shift, g_shift, b_shift = shift_params img = F.shift_rgb(img, r_shift=r_shift, g_shift=g_shift, b_shift=b_shift) expected_r, expected_g, expected_b = expected assert img.dtype == np.dtype("uint8") assert (img[:, :, 0] == expected_r).all() assert (img[:, :, 1] == expected_g).all() assert (img[:, :, 2] == expected_b).all()
def test_shift_rgb(shift_params, expected): img = np.ones((100, 100, 3), dtype=np.uint8) * 127 r_shift, g_shift, b_shift = shift_params img = F.shift_rgb(img, r_shift=r_shift, g_shift=g_shift, b_shift=b_shift) expected_r, expected_g, expected_b = expected assert img.dtype == np.dtype('uint8') assert (img[:, :, 0] == expected_r).all() assert (img[:, :, 1] == expected_g).all() assert (img[:, :, 2] == expected_b).all()
def test_shift_rgb_float(shift_params, expected): img = np.ones((100, 100, 3), dtype=np.float32) * 0.4 r_shift, g_shift, b_shift = shift_params img = F.shift_rgb(img, r_shift=r_shift, g_shift=g_shift, b_shift=b_shift) expected_r, expected_g, expected_b = [np.ones((100, 100), dtype=np.float32) * channel_value for channel_value in expected] assert img.dtype == np.dtype('float32') assert_array_almost_equal_nulp(img[:, :, 0], expected_r) assert_array_almost_equal_nulp(img[:, :, 1], expected_g) assert_array_almost_equal_nulp(img[:, :, 2], expected_b)
def albumentations(self, img): return albumentations.shift_rgb(img, r_shift=100, g_shift=100, b_shift=100)
def apply_r(self, image, r_shift_r=0, g_shift_r=0, b_shift_r=0, **params): return F.shift_rgb(image, r_shift_r, g_shift_r, b_shift_r)
def apply_l(self, image, r_shift_l=0, g_shift_l=0, b_shift_l=0, **params): return F.shift_rgb(image, r_shift_l, g_shift_l, b_shift_l)
def albumentations_fn(self, image, arg): return F.shift_rgb(image, r_shift=arg[0], g_shift=arg[1], b_shift=arg[2])
def apply(self, image, shift=0, **params): return F.shift_rgb(image, shift, shift, shift)