Example #1
0
    def set_clip_image(self, left_up_pos, size):
        from image_inpainting_demo import set_label_image

        show_width, show_height = self.show_image_size
        height, width, bytesPerComponent = self.image_show_data.shape

        # calculate row coordinate
        to_row_width, to_row_height = width / float(
            show_width), height / float(show_height)
        actual_x, actual_y = int(left_up_pos[0] * to_row_width), int(
            left_up_pos[1] * to_row_height)
        actual_width, actual_height = int(size[0] * to_row_width), int(
            size[1] * to_row_height)
        if not actual_width or not actual_height:
            return

        # clip image
        self.clip_pos_size = (actual_x, actual_y, actual_width, actual_height)
        row_image = Image.fromarray(self.image_show_data)
        cp_image = row_image.crop((actual_x, actual_y, actual_x + actual_width,
                                   actual_y + actual_height))
        self.image_clip_data = np.asarray(cp_image)

        # preview
        set_label_image(self.label_image_clip_preview, self.PREVIEW_CLIP_WIDTH,
                        self.image_clip_data)
Example #2
0
    def on_clicked_clear(self):
        from image_inpainting_demo import set_label_image

        self.image_mask_data[:, :] = 0
        set_label_image(self.image_mask_preview, self.PREVIEW_MASK_WIDTH,
                        self.image_mask_data)
        self.refresh_mask_image()
Example #3
0
    def refresh_mask_image(self, x0y0_x1y1=None):
        from image_inpainting_demo import set_label_image

        color = (self.color_pen.red(), self.color_pen.green(),
                 self.color_pen.blue())
        if x0y0_x1y1:
            x1, y1 = x0y0_x1y1[2], x0y0_x1y1[3]
            x0, y0 = x0y0_x1y1[0], x0y0_x1y1[1]
            self.image_draw_data[y0:y1 + 1, x0:x1 + 1] = color
        else:
            self.image_draw_data = np.copy(
                (self.image_mask_data / 255 * color) +
                ((1 - self.image_mask_data / 255) * self.image_clip_data))
            self.image_draw_data = np.array(self.image_draw_data, np.uint8)
        set_label_image(self.image_draw_mask, self.PREVIEW_CLIP_WIDTH,
                        self.image_draw_data)
Example #4
0
 def set_image(self, image_selected_data):
     from image_inpainting_demo import set_label_image
     self.image_show_data = image_selected_data
     self.show_image_size = set_label_image(self.label_image_clip,
                                            self.PREVIEW_SHOW_WIDTH,
                                            self.image_show_data)
     self.label_image_clip.reset()
     self.on_clicked_clear()
     self.parent.setTabEnabled(1, True)
     self.parent.setTabEnabled(2, False)
     self.parent.setTabEnabled(3, False)
Example #5
0
    def set_current_draw(self, item_name):
        from image_inpainting_demo import set_label_image
        self.current_item_name = item_name

        # clip image
        self.image_clip_data = self.item_name_to_clip_image_info[
            self.current_item_name][0]
        set_label_image(self.label_image_clip, self.PREVIEW_CLIP_WIDTH,
                        self.image_clip_data)

        # mask image
        self.image_mask_data = self.item_name_to_mask_image_info[
            self.current_item_name][0]
        set_label_image(self.label_image_mask, self.PREVIEW_MASK_WIDTH,
                        self.image_mask_data)

        # clip mask image
        color = (255, 255, 255)
        self.image_clip_mask_data = np.copy(
            (self.image_mask_data / 255 * color) +
            ((1 - self.image_mask_data / 255) * self.image_clip_data))
        self.image_clip_mask_data = np.array(self.image_clip_mask_data,
                                             np.uint8)
        set_label_image(self.label_image_clip_mask,
                        self.PREVIEW_CLIP_MASK_WIDTH,
                        self.image_clip_mask_data)

        # edge image
        self.image_edge_data = self.item_name_to_result_image_info[item_name][
            0]
        set_label_image(self.label_image_edge, self.PREVIEW_EDGE_WIDTH,
                        self.image_edge_data)

        # result image
        self.image_result_data = self.item_name_to_result_image_info[
            item_name][1]
        set_label_image(self.label_image_result, self.PREVIEW_RESULT_WIDTH,
                        self.image_result_data)

        self.parent.setTabEnabled(3, True)
        self.label_info.setText(self.INFO_READY)
Example #6
0
    def on_clicked_tree_item(self, item, column):
        from image_inpainting_demo import set_label_image

        self.label_image_preview.setText(item.text(column))
        self.item_clicked = item

        # is select image
        if item.checkState(0) == Qt.Checked:
            if self.item_selected_image and self.item_selected_image is not item:
                self.item_selected_image.setCheckState(0, Qt.Unchecked)
            self.item_selected_image = item
            self.item_selected_image.setCheckState(0, Qt.Checked)

            image_path = self.item_selected_image.parent().text(0) + '/' + self.item_selected_image.text(0)
            print('select image path : ', image_path)
            # preview image
            new_img = Image.open(image_path)
            new_img = new_img.convert('RGB')
            self.image_selected_data = np.asarray(new_img)
            set_label_image(self.label_image_preview, self.PREVIEW_WIDTH, self.image_selected_data)
            self.parent.clip_area.set_image(self.image_selected_data)
Example #7
0
    def draw_mask(self, pos):
        from image_inpainting_demo import set_label_image

        show_width, show_height = self.show_image_size
        height, width, bytesPerComponent = self.image_clip_data.shape

        # calculate row coordinate
        to_row_width, to_row_height = width / float(
            show_width), height / float(show_height)
        actual_x, actual_y = int(pos[0] * to_row_width), int(pos[1] *
                                                             to_row_height)

        half_size = int(math.ceil(self.brush_size / 2.0))
        x1, y1 = min(actual_x + half_size, width), min(actual_y + half_size,
                                                       width)
        x0, y0 = max(actual_x - (self.brush_size - half_size),
                     0), max(actual_y - (self.brush_size - half_size), 0)

        self.image_mask_data[y0:y1 + 1, x0:x1 + 1] = 255
        set_label_image(self.image_mask_preview, self.PREVIEW_MASK_WIDTH,
                        self.image_mask_data)
        self.refresh_mask_image((x0, y0, x1, y1))
Example #8
0
    def set_current_draw(self, item_name):
        from image_inpainting_demo import set_label_image
        self.current_item_name = item_name

        # show preview
        self.image_clip_data = self.item_name_to_clip_image_info[
            self.current_item_name][0]

        # create mask
        self.image_mask_data = self.item_name_to_mask_image_info[
            self.current_item_name][0]
        set_label_image(self.image_mask_preview, self.PREVIEW_MASK_WIDTH,
                        self.image_mask_data)

        # draw image
        color = (self.color_pen.red(), self.color_pen.green(),
                 self.color_pen.blue())
        self.image_draw_data = np.copy((self.image_mask_data / 255 * color) + (
            (1 - self.image_mask_data / 255) * self.image_clip_data))
        self.image_draw_data = np.array(self.image_draw_data, np.uint8)
        self.show_image_size = set_label_image(self.image_draw_mask,
                                               self.PREVIEW_CLIP_WIDTH,
                                               self.image_draw_data)