示例#1
0
    def inpaint(self, picture: Picture) -> Picture:
        picture = picture.copy()

        # Initialisation de la barre de progression
        number_of_pixels_to_process = len(picture.pixels[picture.pixels == self.value_missing_pixel]) // 3
        progress_bar_widgets = ["Inpainting: processed ", Counter(), "/{} pixels [".format(number_of_pixels_to_process),
                                Percentage(), "], ", Timer(), ", ", ETA()]
        progress_bar = ProgressBar(widgets=progress_bar_widgets,
                                   minval=0,
                                   maxval=number_of_pixels_to_process)
        progress_bar.start()

        # On récupère le dictionnaire
        dictionary = picture.get_dictionnaire(self.patch_size, self.step, max_missing_pixel=0)

        while self.value_missing_pixel in picture.pixels:
            # On récupère le prochain patch à traiter
            next_pixel = self._get_next_patch(picture, self.patch_size, self.value_out_of_bounds,
                                              self.value_missing_pixel)

            # On reconstruit le patch selectionné
            next_patch = picture.get_patch(*next_pixel, self.patch_size)

            self.fit(dictionary, next_patch)
            for x, y in iter_patch_empty(picture.pixels, *next_pixel, self.patch_size):
                next_pixel_value = self.predict(x - next_pixel[0] + (self.patch_size // 2),
                                                y - next_pixel[1] + (self.patch_size // 2),
                                                dictionary)
                picture.pixels[x, y] = next_pixel_value
                progress_bar.update(progress_bar.value + 1)

        progress_bar.finish()
        return picture
示例#2
0
def main_outdoor():
    # Load picture
    original_picture = Picture(picture_path=OUTDOOR, color_model=COLOR_MODEL)

    # Add a rectangle of noise
    noisy_picture = original_picture.copy()
    noisy_picture.add_rectangle(288, 497, 190, 80)

    main_inpainting(original_picture, noisy_picture)
示例#3
0
def main_castle():
    # Load picture
    original_picture = Picture(picture_path=CASTLE, color_model=COLOR_MODEL)

    # Add a rectangle of noise
    noisy_picture = original_picture.copy()
    noisy_picture.add_rectangle(400, 380, 50, 20)

    main_inpainting(original_picture, noisy_picture)
示例#4
0
def main_outdoor():
    # Chargement de l'image
    original_picture = Picture(picture_path=OUTDOOR, codage=CODAGE)

    # Ajout du bruit
    noisy_picture = original_picture.copy()
    noisy_picture.add_rectangle(288, 497, 190, 80)

    main_inpainting(original_picture, noisy_picture)
示例#5
0
def main_castle():
    # Chargement de l'image
    original_picture = Picture(picture_path=CASTLE, codage=CODAGE)

    # Ajout du bruit
    noisy_picture = original_picture.copy()  # Ajout du bruit
    noisy_picture.add_rectangle(400, 380, 50, 20)

    main_inpainting(original_picture, noisy_picture)
示例#6
0
def main_lena():
    # Chargement de l'image
    original_picture = Picture(picture_path=LENA_COLOR_512, codage=CODAGE)

    # Ajout du bruit
    noisy_picture = original_picture.copy()
    noisy_picture.add_noise(0.005)

    main_inpainting(original_picture, noisy_picture)
示例#7
0
def main_lena():
    # Load picture
    original_picture = Picture(picture_path=LENA_COLOR_512,
                               color_model=COLOR_MODEL)

    # Add noise
    noisy_picture = original_picture.copy()
    noisy_picture.add_noise(0.005)

    main_inpainting(original_picture, noisy_picture)
示例#8
0
    def inpaint(self, picture: Picture) -> Picture:
        picture = picture.copy()

        # Init progressbar
        number_of_pixels_to_process = len(
            picture.pixels[picture.pixels == self.value_missing_pixel]) // 3
        progress_bar_widgets = [
            "Inpainting: processed ",
            Counter(), "/{} pixels [".format(number_of_pixels_to_process),
            Percentage(), "], ",
            Timer(), ", ",
            ETA()
        ]

        # Retrieve the picture's dictionary
        print("Computing picture's dictionary")
        dictionary = picture.get_dictionary(self.patch_size,
                                            self.step,
                                            max_missing_pixel=0)

        with ProgressBar(widgets=progress_bar_widgets,
                         minval=0,
                         maxval=number_of_pixels_to_process) as progress_bar:
            progress_bar.start()
            while self.value_missing_pixel in picture.pixels:
                # Retrieve the next patch containing missing values
                next_pixel = self._get_next_patch(picture, self.patch_size,
                                                  self.value_out_of_bounds,
                                                  self.value_missing_pixel)

                # Inpaint the selected patch
                next_patch = picture.get_patch(*next_pixel, self.patch_size)

                self.fit(dictionary, next_patch)
                for x, y in iter_patch_empty(picture.pixels, *next_pixel,
                                             self.patch_size):
                    next_pixel_value = self.predict(
                        x - next_pixel[0] + (self.patch_size // 2),
                        y - next_pixel[1] + (self.patch_size // 2), dictionary)
                    picture.pixels[x, y] = next_pixel_value
                    progress_bar.update(progress_bar.value + 1)
            return picture