Пример #1
0
    def test_angle_vs_angle_plus_180(self):
        """ Test that the result of reflection() is the same for any angle and angle + 180 """
        im = np.random.random((256, 256))
        reflected1 = reflection(im, angle=15)
        reflected2 = reflection(im, angle=195)  # + 180

        self.assertTrue(np.allclose(reflected1, reflected2))
Пример #2
0
    def test_no_side_effects(self):
        """ Test that reflection() does not modify the input image and mask """
        im = np.empty((128, 128), dtype=np.float)
        mask = np.zeros_like(im, dtype=np.bool)

        im.setflags(write=False)
        mask.setflags(write=False)

        rot = reflection(im, center=(67, 93), angle=35, mask=mask)
Пример #3
0
    def test_correctness_angle90(self):
        """ Test that reflection() correctly symmetrizes around the y-axis. """

        im = np.zeros((256, 256), dtype=np.float)
        im[:, 0:10] = 1

        reflected = reflection(im, angle=90)

        expected = np.array(im, copy=True)
        expected[:, 0:10] = 0.5
        expected[:, 246:256] = 0.5

        self.assertTrue(np.allclose(expected, reflected))
Пример #4
0
    def test_output_range(self):
        """ Test that reflection() does not modify the value range """
        im = 1000 * np.random.random(size=(256, 256))
        mask = np.random.choice([True, False], size=im.shape)

        with catch_warnings():
            simplefilter("ignore")
            rot = reflection(im, center=(100, 150), angle=5, mask=mask)

        self.assertLessEqual(rot.max(), im.max())
        # In the case of a mask that overlaps with itself when rotated,
        # the average will be zero due to nan_to_num
        self.assertGreaterEqual(rot.min(), min(im.min(), 0))
Пример #5
0
def test_reflection_correctness_angle0():
    """ Test that reflection() correctly symmetrizes around the x-axis. """

    im = np.zeros((256, 256), dtype=float)
    im[0:10, :] = 1

    reflected = reflection(im, angle=0)

    expected = np.array(im, copy=True)
    expected[0:10, :] = 0.5
    expected[246:256, :] = 0.5

    assert np.allclose(expected, reflected)
Пример #6
0
 def test_trivial(self):
     """ Test the reflection symmetry of an image of zeroes """
     im = np.zeros((256, 256))
     ref = reflection(im, angle=-15.3)
     self.assertTrue(np.allclose(ref, im))
Пример #7
0
def test_reflection_trivial():
    """ Test the reflection symmetry of an image of zeroes """
    im = np.zeros((256, 256))
    ref = reflection(im, angle=-15.3)
    assert np.allclose(ref, im)