def test_p_cut_NWp_white_Wp_cut(self):
        img_depart = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1,
                                           0], [0, 1, 1, 0, 1, 0],
                      [0, 1, 0, 1, 0, 0], [0, 1, 1, 1, 0, 0],
                      [0, 0, 0, 0, 0, 0]]

        img_soluce = [[0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1,
                                           0], [0, 1, 1, 0, 0, 0],
                      [0, 1, 0, 1, 0, 0], [0, 1, 1, 1, 0, 0],
                      [0, 0, 0, 0, 0, 0]]

        binary_image = BinaryImage.create_img_from_array(
            img_depart, BLACK_CONNEXITY, WHITE_CONNEXITY)

        solver = B8W8_Solver(
            binary_image, BinaryImage.create_img_vertical(binary_image.size))

        solver.resolve_image(binary_image)

        self.assertEqual(
            img_soluce, binary_image.convert_pixels_to_img(),
            "In case of p cut vertex and NW(p) is white and W(p) is cut vertex"
            " the interchange should be <p, NW(p)>")
        self.assertEqual(1, len(solver.array_interchange),
                         "The number interchange should be 1")
Exemplo n.º 2
0
    def statistics_from_random_images(self,
                                      black_connexity=4,
                                      white_connexity=4,
                                      nb_iter=10,
                                      initial_size_image=50,
                                      nb_tick=5,
                                      incr_size_image=10,
                                      seed_min=0,
                                      seed_max=500000):
        size_image = initial_size_image
        for i in range(nb_iter):
            total_interchange = 0
            seeds = []
            for j in range(nb_tick):
                seed = random.randint(seed_min, seed_max)
                binary_image = BinaryImage.create_random_img(
                    n=size_image,
                    black_connexity=black_connexity,
                    white_connexity=white_connexity,
                    seed=seed)
                solver = None

                if black_connexity == white_connexity == 4:
                    solver = B4W4_Solver(
                        binary_image,
                        BinaryImage.create_img_vertical(binary_image.size))
                elif black_connexity == 4 and white_connexity == 8:
                    solver = B4W8_Solver(
                        binary_image,
                        BinaryImage.create_img_vertical(binary_image.size))
                elif black_connexity == 8 and white_connexity == 4:
                    solver = B8W4_Solver(
                        binary_image,
                        BinaryImage.create_img_vertical(binary_image.size))
                elif black_connexity == white_connexity == 8:
                    solver = B8W8_Solver(
                        binary_image,
                        BinaryImage.create_img_vertical(binary_image.size))

                nb_interchange = solver.solve()
                total_interchange += nb_interchange
                seeds.append(seed)

            average_tick_interchange = total_interchange / nb_tick

            self.dic_interchanges[size_image] = [
                seeds, average_tick_interchange
            ]
            size_image += incr_size_image

        print("Total average for solver B", black_connexity, "W",
              white_connexity, " is ", self.dic_interchanges)
Exemplo n.º 3
0
    def statistics_spiral(self,
                          black_connexity=4,
                          white_connexity=4,
                          nb_iter=10,
                          initial_size_image=50,
                          nb_tick=5,
                          incr_size_image=10):
        size_image = initial_size_image
        for i in range(nb_iter):
            total_interchange = 0
            for j in range(nb_tick):
                begin = time.time()
                binary_image = BinaryImage.create_img_spiral(
                    size_image=size_image,
                    black_connexity=black_connexity,
                    white_connexity=white_connexity)
                solver = None

                if black_connexity == white_connexity == 4:
                    solver = B4W4_Solver(
                        binary_image,
                        BinaryImage.create_img_vertical(binary_image.size))
                elif black_connexity == 4 and white_connexity == 8:
                    solver = B4W8_Solver(
                        binary_image,
                        BinaryImage.create_img_vertical(binary_image.size))
                elif black_connexity == 8 and white_connexity == 4:
                    solver = B8W4_Solver(
                        binary_image,
                        BinaryImage.create_img_vertical(binary_image.size))
                elif black_connexity == white_connexity == 8:
                    solver = B8W8_Solver(
                        binary_image,
                        BinaryImage.create_img_vertical(binary_image.size))

                nb_interchange = solver.solve()
                total_interchange += nb_interchange
                print("size : ", size_image, ", timer : ", time.time() - begin)

            self.dic_interchanges[size_image] = [i, total_interchange]
            size_image += incr_size_image

        print("Total average for solver B", black_connexity, "W",
              white_connexity, " is ", self.dic_interchanges)
Exemplo n.º 4
0
def main_b8_w8() -> int:
    image = BinaryImage.create_img_spiral(50, 8, 8)
    image_final = BinaryImage.create_img_vertical(image.size, 8, 8)

    displayer = BinaryImageDisplayer(show_legend=True)

    solver = B8W8_Solver(image, image_final)

    displayer.show(solver.imageStart, subtitle="Image de départ")

    nb_interchange = solver.solve()

    print("Nb interchange = ", nb_interchange)
    print("len interchange = ", len(solver.array_interchange))

    displayer.show(solver.imageStart, subtitle="Image de fin")

    displayer.create_gif(image=solver.get_image_save(),
                         array_interchage=solver.array_interchange, speed=1000, name="B8_W8.gif")

    return 0