def test_rotate_image_90_180(): image = Image(np.array([[1., 2., 3., 4.], [5., 6., 7., 8.], [9., 10., 11., 12.]])) image.landmarks['temp'] = PointCloud(np.array([[1., 1.], [1., 2.], [2., 1.], [2., 2.]])) # rotate 90 degrees rotated_img = image.rotate_ccw_about_centre(theta=90, order=0) rotated_img.landmarks['temp'] = rotated_img.landmarks['temp'].constrain_to_bounds( rotated_img.bounds()) assert_allclose(rotated_img.pixels, np.array([[[4., 8., 12.], [3., 7., 11.], [2., 6., 10.], [1., 5., 9.]]])) assert_almost_equal(rotated_img.landmarks['temp'].points, np.array([[2., 1.], [1., 1.], [2., 2.], [1., 2.]])) # rotate 180 degrees rotated_img = image.rotate_ccw_about_centre(theta=180, order=0) rotated_img.landmarks['temp'] = rotated_img.landmarks['temp'].constrain_to_bounds( rotated_img.bounds()) assert_allclose(rotated_img.pixels, np.array([[[12., 11., 10., 9.], [8., 7., 6., 5.], [4., 3., 2., 1.]]])) assert_almost_equal(rotated_img.landmarks['temp'].points, np.array([[1., 2.], [1., 1.], [0., 2.], [0., 1.]]))
def test_rotate_image_90_180(): image = Image( np.array([[1., 2., 3., 4.], [5., 6., 7., 8.], [9., 10., 11., 12.]])) image.landmarks['temp'] = PointCloud( np.array([[1., 1.], [1., 2.], [2., 1.], [2., 2.]])) # rotate 90 degrees rotated_img = image.rotate_ccw_about_centre(theta=90, order=0) rotated_img.landmarks['temp'] = rotated_img.landmarks[ 'temp'].lms.constrain_to_bounds(rotated_img.bounds()) assert_allclose( rotated_img.pixels, np.array([[[4., 8., 12.], [3., 7., 11.], [2., 6., 10.], [1., 5., 9.]]])) assert_almost_equal(rotated_img.landmarks['temp'].lms.points, np.array([[2., 1.], [1., 1.], [2., 2.], [1., 2.]])) # rotate 180 degrees rotated_img = image.rotate_ccw_about_centre(theta=180, order=0) rotated_img.landmarks['temp'] = rotated_img.landmarks[ 'temp'].lms.constrain_to_bounds(rotated_img.bounds()) assert_allclose( rotated_img.pixels, np.array([[[12., 11., 10., 9.], [8., 7., 6., 5.], [4., 3., 2., 1.]]])) assert_almost_equal(rotated_img.landmarks['temp'].lms.points, np.array([[1., 2.], [1., 1.], [0., 2.], [0., 1.]]))
def test_rotate_image_45(): image = Image( np.array( [ [1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0], [9.0, 10.0, 11.0, 12.0], [13.0, 14.0, 15.0, 16.0], ] ) ) image.landmarks["temp"] = PointCloud( np.array([[1.0, 1.0], [1.0, 2.0], [2.0, 1.0], [2.0, 2.0]]) ) rotated_img = image.rotate_ccw_about_centre(theta=45, order=0) assert_allclose( rotated_img.pixels, np.array( [ [ [0.0, 0.0, 4.0, 0.0, 0.0], [0.0, 3.0, 7.0, 8.0, 0.0], [1.0, 6.0, 7.0, 11.0, 16.0], [0.0, 5.0, 10.0, 15.0, 15.0], [0.0, 0.0, 13.0, 14.0, 0.0], ] ] ), ) assert_almost_equal( rotated_img.landmarks["temp"].points, np.array([[2.121, 1.414], [1.414, 2.121], [2.828, 2.121], [2.121, 2.828]]), decimal=3, )
def test_rotate_image_90_180(): image = Image( np.array([[1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0], [9.0, 10.0, 11.0, 12.0]]) ) image.landmarks["temp"] = PointCloud( np.array([[1.0, 1.0], [1.0, 2.0], [2.0, 1.0], [2.0, 2.0]]) ) # rotate 90 degrees rotated_img = image.rotate_ccw_about_centre(theta=90, order=1, mode="nearest") rotated_img.landmarks["temp"] = rotated_img.landmarks["temp"].constrain_to_bounds( rotated_img.bounds() ) assert_allclose( rotated_img.pixels, np.array( [[[4.0, 8.0, 12.0], [3.0, 7.0, 11.0], [2.0, 6.0, 10.0], [1.0, 5.0, 9.0]]] ), ) assert_almost_equal( rotated_img.landmarks["temp"].points, np.array([[2.0, 1.0], [1.0, 1.0], [2.0, 2.0], [1.0, 2.0]]), ) # rotate 180 degrees rotated_img = image.rotate_ccw_about_centre(theta=180, order=1, mode="nearest") rotated_img.landmarks["temp"] = rotated_img.landmarks["temp"].constrain_to_bounds( rotated_img.bounds() ) assert_allclose( rotated_img.pixels, np.array( [[[12.0, 11.0, 10.0, 9.0], [8.0, 7.0, 6.0, 5.0], [4.0, 3.0, 2.0, 1.0]]] ), ) assert_almost_equal( rotated_img.landmarks["temp"].points, np.array([[1.0, 2.0], [1.0, 1.0], [0.0, 2.0], [0.0, 1.0]]), )
def test_rotate_image_45(): image = Image( np.array([[1., 2., 3., 4.], [5., 6., 7., 8.], [9., 10., 11., 12.], [13., 14., 15., 16.]])) image.landmarks['temp'] = PointCloud( np.array([[1., 1.], [1., 2.], [2., 1.], [2., 2.]])) rotated_img = image.rotate_ccw_about_centre(theta=45, order=0) assert_allclose( rotated_img.pixels, np.array([[[0., 0., 4., 0., 0.], [0., 3., 7., 8., 0.], [1., 6., 7., 11., 16.], [0., 5., 10., 15., 15.], [0., 0., 13., 14., 0.]]])) assert_almost_equal(rotated_img.landmarks['temp'].lms.points, np.array([[2.121, 1.414], [1.414, 2.121], [2.828, 2.121], [2.121, 2.828]]), decimal=3)
def test_rotate_image_45(): image = Image(np.array([[1., 2., 3., 4.], [5., 6., 7., 8.], [9., 10., 11., 12.], [13., 14., 15., 16.]])) image.landmarks['temp'] = PointCloud(np.array([[1., 1.], [1., 2.], [2., 1.], [2., 2.]])) rotated_img = image.rotate_ccw_about_centre(theta=45, order=0) assert_allclose(rotated_img.pixels, np.array([[[0., 0., 4., 0., 0.], [0., 3., 7., 8., 0.], [1., 6., 7., 11., 16.], [0., 5., 10., 15., 15.], [0., 0., 13., 14., 0.]]])) assert_almost_equal(rotated_img.landmarks['temp'].points, np.array([[2.121, 1.414], [1.414, 2.121], [2.828, 2.121], [2.121, 2.828]]), decimal=3)