コード例 #1
0
    def test_distortion_factor_preset_zero_distortion_coefficient(self):
        """Tests distortion_factor at zero distortion coefficient."""
        squared_radii = _get_random_radii() * 2.0

        distortion, mask = quadratic_radial_distortion.distortion_factor(
            squared_radii, 0.0)

        with self.subTest(name='distortion'):
            self.assertAllClose(tf.ones_like(squared_radii), distortion)

        # No overflow when distortion_coefficient = 0.0.
        with self.subTest(name='mask'):
            self.assertAllInSet(mask, (False, ))
コード例 #2
0
    def test_distortion_factor_preset_zero_radius(self):
        """Tests distortion_factor at the corner case of zero radius."""
        squared_radii = _get_zeros_radii()
        distortion_coefficient = _get_random_coefficient() - 0.5

        distortion, mask = quadratic_radial_distortion.distortion_factor(
            squared_radii, distortion_coefficient)

        with self.subTest(name='distortion'):
            self.assertAllClose(np.ones_like(squared_radii), distortion)

        with self.subTest(name='mask'):
            self.assertAllInSet(mask, (False, ))
コード例 #3
0
    def test_distortion_factor_random_positive_distortion_coefficient(self):
        """Tests that distortion_factor produces the expected outputs."""
        squared_radii = _get_random_radii() * 2.0
        distortion_coefficient = _get_random_coefficient() * 2.0

        distortion, mask = quadratic_radial_distortion.distortion_factor(
            squared_radii, distortion_coefficient)

        distortion_coefficient = _make_shape_compatible(distortion_coefficient)
        with self.subTest(name='distortion'):
            self.assertAllClose(1.0 + distortion_coefficient * squared_radii,
                                distortion)

        # No overflow when distortion_coefficient >= 0.0.
        with self.subTest(name='mask'):
            self.assertAllInSet(mask, (False, ))
コード例 #4
0
    def test_distortion_factor_random_negative_distortion_coefficient(self):
        """Tests that distortion_factor produces the expected outputs."""
        squared_radii = _get_random_radii() * 2.0
        distortion_coefficient = _get_random_coefficient() * -0.2

        distortion, mask = quadratic_radial_distortion.distortion_factor(
            squared_radii, distortion_coefficient)
        distortion_coefficient = _make_shape_compatible(distortion_coefficient)
        max_squared_radii = -1.0 / 3.0 / distortion_coefficient
        expected_overflow_mask = squared_radii > max_squared_radii
        valid_mask = np.logical_not(expected_overflow_mask)
        # We assert correctness of the mask, and of all the pixels that are not in
        # overflow.
        actual_distortion_when_valid = self.evaluate(distortion)[valid_mask]
        expected_distortion_when_valid = (
            1.0 + distortion_coefficient * squared_radii)[valid_mask]

        with self.subTest(name='distortion'):
            self.assertAllClose(expected_distortion_when_valid,
                                actual_distortion_when_valid)

        with self.subTest(name='mask'):
            self.assertAllEqual(expected_overflow_mask, mask)