Exemple #1
0
    def __init__(self, algorithm="reference", algorithm_kwargs=None):
        """This is the View that renders the main editor window."""
        if algorithm_kwargs is None:
            algorithm_kwargs = {}

        self.root = tk.Tk()
        self.root.wm_title("Streaming Gradient Domain Fusion")
        self.frame = EditorViewFrame(self.root)

        # Set up editor canvas
        self.target_canvas = EditorViewCanvas(self.frame, background="#009900",
                                              highlightthickness=0)
        self.target_canvas.bind("<Button-1>", self.handle_loadtarget)
        self.source_canvas = EditorViewCanvas(self.frame, background="#00477d",
                                              highlightthickness=0)
        self.source_canvas.bind("<Button-1>", self.handle_loadsource)
        self.frame.register_canvas_set(self.target_canvas, self.source_canvas)
        self.target_canvas.grid(row=0, column=1)
        self.source_canvas.grid(row=0, column=2)

        # Set up editor menu
        menu_items = OrderedDict()
        menu_items["File"] = [("Load target image", self.handle_loadtarget, (SUPER, "o")),
                              ("Load source image", self.handle_loadsource, (SUPER, SHIFT, "o")),
                              ("Save canvas", self.handle_save, (SUPER, "s")),
                              (),
                              ("Close", self.handle_quit, (SUPER, "w"))]
        menu_items["Edit"] = [("Undo", self.handle_unimplemented, (SUPER, "z"))]
        menu_items["Brush"] = [("Square",
                                lambda: self.set_brush_circular(False), (SUPER, "1")),
                               ("Circle",
                                lambda: self.set_brush_circular(True), (SUPER, "2")),
                               ("Feathered",
                                lambda: self.set_brush_feathered(True), (SUPER, "3")),
                               ("Not Feathered",
                                lambda: self.set_brush_feathered(False), (SUPER, "4")),
                               (),
                               ("Increase brush size", self.increase_brush_size, (CONTROL, "bracketright")),
                               ("Decrease brush size", self.decrease_brush_size, (CONTROL, "bracketleft"))]
        menu_items["Help"] = []
        self.menu = MenuBuilder(items=menu_items)
        self.menu.render(self.root)

        # Set up editor window
        self.frame.pack(fill=tk.BOTH, expand=tk.YES)
        self.root.geometry("1200x500")
        self.fusion = get_fusion_algorithm(algorithm)(**algorithm_kwargs)
        self.mask_ndarray = None
        self.source_anchor = None
        self.target_anchor = None

        # Set up brush properties
        self.brush_radius = 12
        self.brush_circular = False
        self.brush_feathered = False    # TODO: How to make brush actually feathered?
Exemple #2
0
def fusion_from_file(algorithm, source_path, target_path, mask_path, offset=None, output_path=None,
                     algorithm_kwargs=None):
    if offset is None:
        offset = np.array([0, 0])
    if algorithm_kwargs is None:
        algorithm_kwargs = {}
    fusion = get_fusion_algorithm(algorithm)(**algorithm_kwargs)
    mask = to_mask(imread(mask_path))
    im_source = imread(source_path)
    im_target = imread(target_path)
    fusion.set_target_image(im_target)
    fusion.set_source_image(im_source)
    fusion.set_anchor_points(np.array([0, 0]), np.array(offset))
    fusion.update_blend(mask)
    im_result = (fusion.get_fusion() * 255.).astype(np.uint8)
    if output_path:
        imsave(output_path, im_result)
    return im_result