예제 #1
0
 def test_bgr(self, device):
     a_val: float = 1.
     x_rgb = torch.rand(3, 4, 4).to(device)
     x_bgr = kornia.rgb_to_bgr(x_rgb)
     x_rgba = kornia.rgb_to_rgba(x_rgb, a_val)
     x_rgba_new = kornia.bgr_to_rgba(x_bgr, a_val)
     assert_allclose(x_rgba, x_rgba_new)
예제 #2
0
파일: test_rgb.py 프로젝트: zeta1999/kornia
    def test_unit(self, device, dtype, aval):
        data = torch.tensor([[[[1., 1.], [1., 1.]], [[2., 2.], [2., 2.]],
                              [[3., 3.], [3., 3.]]]],
                            device=device,
                            dtype=dtype)  # Bx3x2x2

        expected = torch.tensor(
            [[[[1.0, 1.0], [1.0, 1.0]], [[2.0, 2.0], [2.0, 2.0]],
              [[3.0, 3.0], [3.0, 3.0]], [[aval, aval], [aval, aval]]]],
            device=device,
            dtype=dtype)  # Bx4x2x2

        assert_allclose(kornia.rgb_to_rgba(data, aval), expected)
예제 #3
0
    def test_single(self, device):
        data = torch.tensor([[[1., 1.], [1., 1.]], [[2., 2.], [2., 2.]],
                             [[3., 3.], [3., 3.]]])  # 3x2x2
        data = data.to(device)

        aval: float = 0.4
        expected = torch.tensor([[[1.0, 1.0], [1.0, 1.0]],
                                 [[2.0, 2.0], [2.0, 2.0]],
                                 [[3.0, 3.0], [3.0, 3.0]],
                                 [[0.4, 0.4], [0.4, 0.4]]])  # 4x2x2
        expected = expected.to(device)

        assert_allclose(kornia.rgb_to_rgba(data, aval), expected)
예제 #4
0
    def test_unit_aval_th(self, device, dtype, aval):
        data = torch.tensor(
            [[[[1.0, 1.0], [1.0, 1.0]], [[2.0, 2.0], [2.0, 2.0]],
              [[3.0, 3.0], [3.0, 3.0]]]],
            device=device,
            dtype=dtype)  # Bx3x2x2

        expected = torch.tensor(
            [[
                [[1.0, 1.0], [1.0, 1.0]],
                [[2.0, 2.0], [2.0, 2.0]],
                [[3.0, 3.0], [3.0, 3.0]],
                [[aval, aval], [aval, aval]],
            ]],
            device=device,
            dtype=dtype,
        )  # Bx4x2x2

        aval = torch.full_like(data[:, :1], aval)  # Bx1xHxW
        assert_close(kornia.rgb_to_rgba(data, aval), expected)
예제 #5
0
    def test_batch(self, device):

        data = torch.tensor([[[[1., 1.], [1., 1.]], [[2., 2.], [2., 2.]],
                              [[3., 3.], [3., 3.]]],
                             [[[1., 1.], [1., 1.]], [[2., 2.], [2., 2.]],
                              [[3., 3.], [3., 3.]]]])  # 2x3x2x2
        data = data.to(device)

        aval: float = 45.

        expected = torch.tensor([[[[1.0, 1.0], [1.0, 1.0]],
                                  [[2.0, 2.0], [2.0, 2.0]],
                                  [[3.0, 3.0], [3.0, 3.0]],
                                  [[45., 45.], [45., 45.]]],
                                 [[[1.0, 1.0], [1.0, 1.0]],
                                  [[2.0, 2.0], [2.0, 2.0]],
                                  [[3.0, 3.0], [3.0, 3.0]],
                                  [[45., 45.], [45., 45.]]]])
        expected = expected.to(device)

        assert_allclose(kornia.rgb_to_rgba(data, aval), expected)
예제 #6
0
 def test_back_and_forth_rgb(self, device):
     a_val: float = 1.
     x_rgb = torch.rand(3, 4, 4).to(device)
     x_rgba = kornia.rgb_to_rgba(x_rgb, a_val)
     x_rgb_new = kornia.rgba_to_rgb(x_rgba)
     assert_allclose(x_rgb, x_rgb_new)
예제 #7
0
 def test_smoke(self, device):
     data = torch.rand(3, 4, 4).to(device)
     assert kornia.rgb_to_rgba(data, 0.).shape == (4, 4, 4)