Esempio n. 1
0
    def test_square_crop_image(self, image_preprocessor_instance_class):
        x = convert_array_to_image(np.random.randint(255,
                                                     size=(1000, 2000, 3)))

        cropped_image = image_preprocessor_instance_class.square_crop_image(x)

        assert x.size[0] != x.size[1]
        assert cropped_image.size[0] == cropped_image.size[1]
        assert cropped_image.size[
            0] == image_preprocessor_instance_class.size_of_crop
Esempio n. 2
0
    def test_resize_keep_aspect_ratio(self, image_preprocessor_instance_class):
        x = convert_array_to_image(
            np.random.randint(
                255,
                size=(image_preprocessor_instance_class.size_of_resizing + 100,
                      image_preprocessor_instance_class.size_of_resizing + 2,
                      3)))
        resized_image = image_preprocessor_instance_class.resize_keep_aspect_ratio(
            x)

        assert x.size[0] < x.size[1]
        assert resized_image.size[
            0] == image_preprocessor_instance_class.size_of_resizing
Esempio n. 3
0
    def test_convert_black_and_white(self, image_preprocessor_black_and_white):
        x = np.random.randint(
            255,
            size=(image_preprocessor_black_and_white.size_of_crop,
                  image_preprocessor_black_and_white.size_of_crop, 3))

        assert (x[:, :, 0] != x[:, :, 1]).any()

        y = image_preprocessor_black_and_white.convert_black_and_white(
            convert_array_to_image(x))
        y = convert_to_numpy(y)

        assert (y[:, :, 0] == y[:, :, 1]).all()
Esempio n. 4
0
    def test_create_puzzle_permutation(self,
                                       image_preprocessor_instance_class):
        x = convert_array_to_image(
            np.random.randint(
                255,
                size=(image_preprocessor_instance_class.size_of_crop,
                      image_preprocessor_instance_class.size_of_crop, 3)))

        puzzle_1 = image_preprocessor_instance_class.create_puzzle(
            x, random_seed=10)

        puzzle_2 = image_preprocessor_instance_class.create_puzzle(
            x,
            permutation=np.array([1, 0, 2, 3, 4, 5, 6, 7, 8]),
            random_seed=10)

        assert (puzzle_1[0] == puzzle_2[1]).all()
        assert (puzzle_1[0] != puzzle_2[0]).any()
Esempio n. 5
0
    def test_create_puzzle_colour_normalisation(
            self, image_preprocessor_instance_class,
            image_preprocessor_normalize_false):
        x = convert_array_to_image(
            np.random.randint(
                255,
                size=(image_preprocessor_instance_class.size_of_crop,
                      image_preprocessor_instance_class.size_of_crop, 3)))

        puzzle_1 = image_preprocessor_instance_class.create_puzzle(x)
        puzzle_2 = image_preprocessor_normalize_false.create_puzzle(x)

        for puzzle in puzzle_2:
            assert np.mean(puzzle) > 1
            assert np.abs(np.std(puzzle)) > 1

        for puzzle in puzzle_1:
            assert np.abs(np.mean(puzzle) - 1) < 10**(-10)
            assert np.abs(np.std(puzzle) - 1) < 100**(-5)
Esempio n. 6
0
    def test_create_image_from_permutation(self,
                                           image_preprocessor_normalize_false,
                                           image):
        image_np = convert_to_numpy(image)
        size_square = min(image_np.shape[0], image_np.shape[1])
        image = convert_array_to_image(image_np[:size_square, :size_square, :])
        puzzle = image_preprocessor_normalize_false.create_puzzle(image)
        puzzle = np.moveaxis(puzzle, -1, 1)

        new_image = image_preprocessor_normalize_false.create_image_np(
            puzzle, np.array([0, 1, 2, 3, 4, 5, 6, 7, 8]))
        new_image = np.moveaxis(new_image, 0, -1)
        save_array_to_image(new_image, "test_2.png")

        #assert (convert_to_numpy(image) == new_image).all()

        puzzle = image_preprocessor_normalize_false.create_puzzle(
            image, np.array([1, 0, 2, 3, 4, 5, 6, 7, 8]))
        puzzle = np.moveaxis(puzzle, -1, 1)
        new_image = image_preprocessor_normalize_false.create_image_np(
            puzzle, np.array([0, 1, 2, 3, 4, 5, 6, 7, 8]))
        new_image = np.moveaxis(new_image, 0, -1)
        save_array_to_image(new_image, "test.png")