Exemple #1
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
Exemple #2
0
 def handle_loadsource(self, event=None, image_path=None):
     if not image_path:
         image_path = filedialog.askopenfilename()
     if image_path:
         _log.info("Loading source image file: %s", repr(image_path))
         im = imread(image_path)
         self.fusion.set_source_image(im)
         self.source_canvas.draw_numpy(im)
         self.source_canvas.bind("<Button-1>", self.handle_anchor)
         self.source_canvas.config(cursor="crosshair")
Exemple #3
0
 def handle_loadtarget(self, event=None, image_path=None):
     if not image_path:
         image_path = filedialog.askopenfilename()
     if image_path:
         _log.info("Loading target image file: %s", repr(image_path))
         im = imread(image_path)
         h, w, channels = im.shape
         self.fusion.set_target_image(im)
         self.mask_ndarray = np.zeros((h, w), dtype=np.bool)
         self.target_canvas.bind("<Button-1>", self.handle_brush_start)
         self.target_canvas.bind("<B1-Motion>", self.handle_brush_motion)
         self.target_canvas.draw_numpy(self.fusion.get_fusion())