Exemplo n.º 1
0
    def test_apply_transformation_to_image(self):

        counter = 0
        self.image_transformer.modified_image = self.image_transformer.create_new_image(
        )

        for original_face_idx, original_face in self.image_transformer.original_face_to_vts.items(
        ):
            original_image_points, modified_image_points = self.image_transformer.get_all_image_points(
                original_face_idx)
            matrix_computer = MatrixComputer(original_image_points,
                                             modified_image_points)
            sections = matrix_computer.get_transforming_triangles()
            matrices = matrix_computer.get_transformations(sections)

            for triangles, matrix in zip(sections, matrices):
                source_triangle, destination_triangle = triangles
                self.image_transformer.apply_transformation_to_image(
                    source_triangle, destination_triangle, matrix)
                filename = self.get_apply_transformation_filename(counter)
                self.image_transformer.modified_image.save(filename)
                counter += 1

        for step_number in self.transformations:
            expected = self.get_expected_applied_filename(step_number)
            actual = self.get_apply_transformation_filename(step_number)
            self.assertTrue(
                self.image_equal(expected, actual),
                "transformation_" + str(step_number) + ".pngs are not equal ")

        self.teardown_apply_transformation_to_image()
Exemplo n.º 2
0
class MatrixComputerTest(unittest.TestCase):
    def setUp(self):
        #the points are picked because they're a simple translation
        source_pts = [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)]
        destination_pts = [(1.0, 0.0), (2.0, 0.0), (2.0, 1.0), (1.0, 1.0)]

        self.computer = MatrixComputer(source_pts, destination_pts)

    def test_get_transforming_triangles(self):
        results = self.computer.get_transforming_triangles()
        expected_results = [([(0.0, 0.0),
                              (1.0, 0.0), (1.0, 1.0)], [(1.0, 0.0), (2.0, 0.0),
                                                        (2.0, 1.0)]),
                            ([(1.0, 1.0),
                              (0.0, 1.0), (0.0, 0.0)], [(2.0, 1.0), (1.0, 1.0),
                                                        (1.0, 0.0)])]
        assert results == expected_results
        assert len(results) == 2

    def test_compute_transformation_matrix(self):
        source_point = ((0.0, 0.0), (1.0, 0.0), (1.0, 1.0))
        destination_point = ((1.0, 0.0), (2.0, 0.0), (2.0, 1.0))
        result = self.computer.compute_transformation_matrix(
            source_point, destination_point)

        #the transformation maxtrix should be a column matrix:
        # [1.0
        # 0
        # -1.0
        # 0
        # 1.0
        # 0]

        assert result[0] == 1.0
        assert result[1] == 0.0
        assert result[2] == -1.0
        assert result[3] == 0
        assert result[4] == 1.0
        assert result[5] == 0

    def test_get_transformations(self):
        transforming_triangles = [([(0.0, 0.0), (1.0, 0.0),
                                    (1.0, 1.0)], [(1.0, 0.0), (2.0, 0.0),
                                                  (2.0, 1.0)]),
                                  ([(1.0, 1.0), (0.0, 1.0),
                                    (0.0, 0.0)], [(2.0, 1.0), (1.0, 1.0),
                                                  (1.0, 0.0)])]
        transformations = self.computer.get_transformations(
            transforming_triangles)

        assert len(transforming_triangles) == len(transformations)
Exemplo n.º 3
0
class MatrixComputerTest(unittest.TestCase):
    def setUp(self):
        # the points are picked because they're a simple translation
        source_pts = [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)]
        destination_pts = [(1.0, 0.0), (2.0, 0.0), (2.0, 1.0), (1.0, 1.0)]

        self.computer = MatrixComputer(source_pts, destination_pts)

    def test_get_transforming_triangles(self):
        results = self.computer.get_transforming_triangles()
        expected_results = [
            ([(0.0, 0.0), (1.0, 0.0), (1.0, 1.0)], [(1.0, 0.0), (2.0, 0.0), (2.0, 1.0)]),
            ([(1.0, 1.0), (0.0, 1.0), (0.0, 0.0)], [(2.0, 1.0), (1.0, 1.0), (1.0, 0.0)]),
        ]
        assert results == expected_results
        assert len(results) == 2

    def test_compute_transformation_matrix(self):
        source_point = ((0.0, 0.0), (1.0, 0.0), (1.0, 1.0))
        destination_point = ((1.0, 0.0), (2.0, 0.0), (2.0, 1.0))
        result = self.computer.compute_transformation_matrix(source_point, destination_point)

        # the transformation maxtrix should be a column matrix:
        # [1.0
        # 0
        # -1.0
        # 0
        # 1.0
        # 0]

        assert result[0] == 1.0
        assert result[1] == 0.0
        assert result[2] == -1.0
        assert result[3] == 0
        assert result[4] == 1.0
        assert result[5] == 0

    def test_get_transformations(self):
        transforming_triangles = [
            ([(0.0, 0.0), (1.0, 0.0), (1.0, 1.0)], [(1.0, 0.0), (2.0, 0.0), (2.0, 1.0)]),
            ([(1.0, 1.0), (0.0, 1.0), (0.0, 0.0)], [(2.0, 1.0), (1.0, 1.0), (1.0, 0.0)]),
        ]
        transformations = self.computer.get_transformations(transforming_triangles)

        assert len(transforming_triangles) == len(transformations)
    def test_apply_transformation_to_image(self):

        counter = 0
        self.image_transformer.modified_image = self.image_transformer.create_new_image()

        for original_face_idx, original_face in self.image_transformer.original_face_to_vts.items():
            original_image_points, modified_image_points = self.image_transformer.get_all_image_points(original_face_idx)
            matrix_computer = MatrixComputer(original_image_points, modified_image_points)
            sections = matrix_computer.get_transforming_triangles()
            matrices = matrix_computer.get_transformations(sections)

            for triangles, matrix in zip(sections, matrices):
                source_triangle, destination_triangle = triangles
                self.image_transformer.apply_transformation_to_image(source_triangle, destination_triangle, matrix)
                filename = self.get_apply_transformation_filename(counter)
                self.image_transformer.modified_image.save(filename)
                counter += 1

        for step_number in self.transformations:
            expected = self.get_expected_applied_filename(step_number)
            actual = self.get_apply_transformation_filename(step_number)
            self.assertTrue(self.image_equal(expected, actual), "transformation_" + str(step_number) + ".pngs are not equal ")

        self.teardown_apply_transformation_to_image()
Exemplo n.º 5
0
    def setUp(self):
        # the points are picked because they're a simple translation
        source_pts = [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)]
        destination_pts = [(1.0, 0.0), (2.0, 0.0), (2.0, 1.0), (1.0, 1.0)]

        self.computer = MatrixComputer(source_pts, destination_pts)
Exemplo n.º 6
0
    def setUp(self):
        #the points are picked because they're a simple translation
        source_pts = [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)]
        destination_pts = [(1.0, 0.0), (2.0, 0.0), (2.0, 1.0), (1.0, 1.0)]

        self.computer = MatrixComputer(source_pts, destination_pts)