Esempio n. 1
0
def main(black_image, white_image, mask, out_path, min_depth=MIN_DEPTH):
    """Apply pyramid blending to each color channel of the input images """

    # Convert to double and normalize the mask to the range [0..1]
    # to avoid arithmetic overflow issues
    black_image = np.atleast_3d(black_image).astype(np.float)
    white_image = np.atleast_3d(white_image).astype(np.float)
    mask_img = np.atleast_3d(mask).astype(np.float) / 255.

    shape = mask_img.shape[1::-1]
    min_size = min(black_image.shape[:2])
    depth = int(np.log2(min_size)) - min_depth

    gauss_pyr_mask = [gaussPyramid(ch, depth) for ch in np.rollaxis(mask_img, -1)]
    gauss_pyr_black = [gaussPyramid(ch, depth) for ch in np.rollaxis(black_image, -1)]
    gauss_pyr_white = [gaussPyramid(ch, depth) for ch in np.rollaxis(white_image, -1)]
    viz_pyramid(gauss_pyr_mask, shape, path.join(out_path, 'gauss_pyr_mask'), norm=True)
    viz_pyramid(gauss_pyr_black, shape, path.join(out_path, 'gauss_pyr_black'))
    viz_pyramid(gauss_pyr_white, shape, path.join(out_path, 'gauss_pyr_white'))

    lapl_pyr_black = [laplPyramid(ch) for ch in gauss_pyr_black]
    lapl_pyr_white = [laplPyramid(ch) for ch in gauss_pyr_white]
    viz_pyramid(lapl_pyr_black, shape, path.join(out_path, 'lapl_pyr_black'), norm=True)
    viz_pyramid(lapl_pyr_white, shape, path.join(out_path, 'lapl_pyr_white'), norm=True)

    outpyr = [blend(*x) for x in zip(lapl_pyr_white, lapl_pyr_black, gauss_pyr_mask)]
    outimg = [[collapse(x)] for x in outpyr]
    viz_pyramid(outpyr, shape, path.join(out_path, 'outpyr'), norm=True)
    viz_pyramid(outimg, shape, path.join(out_path, 'outimg'))
Esempio n. 2
0
    def test_lapl_pyramid(self):
        gauss_pyr = blend.gaussPyramid(self.black_img, 4)
        for i in range(len(gauss_pyr)):
            cv2.imwrite("gauss_pyr_" + str(i) + ".png", gauss_pyr[i])

        lapl_pyr = blend.laplPyramid(gauss_pyr)
        for i in range(len(lapl_pyr)):
            cv2.imwrite("lapl_pyr_" + str(i) + ".png", lapl_pyr[i])

        for i in range(len(gauss_pyr)):
            self.assertTrue(gauss_pyr[i].shape == lapl_pyr[i].shape)
Esempio n. 3
0
def run_blend(black_image, white_image, mask):
    """Compute the blend of two images along the boundaries of the mask.

    Assume all images are float dtype, and return a float dtype.
    """

    # Automatically figure out the size; at least 16x16 at the highest level
    min_size = min(black_image.shape)
    depth = int(np.log2(min_size)) - 4

    gauss_pyr_mask = blend.gaussPyramid(mask, depth)
    gauss_pyr_black = blend.gaussPyramid(black_image, depth)
    gauss_pyr_white = blend.gaussPyramid(white_image, depth)

    lapl_pyr_black = blend.laplPyramid(gauss_pyr_black)
    lapl_pyr_white = blend.laplPyramid(gauss_pyr_white)

    outpyr = blend.blend(lapl_pyr_white, lapl_pyr_black, gauss_pyr_mask)
    img = blend.collapse(outpyr)

    return (gauss_pyr_black, gauss_pyr_white, gauss_pyr_mask, lapl_pyr_black,
            lapl_pyr_white, outpyr, [img])
def multiresolution(img_stack, weight_map):
    """This function implements the multiresolution method described in "Exposure Fusion" by T. Mertens et al.
    It uses the laplacian and gaussian pyramids for blending the input images according to their weight maps
    (instead of the mask) to produces seamless final artifacts.
    """

    no_images = len(img_stack)
    img_list = []
    weight_list = []
    new_img_list = []
    new_weight_list = []
    outpyr = []

    for f in range(no_images):

        img = np.atleast_3d(img_stack[f]).astype(np.float)
        weight = np.atleast_3d(weight_map[f]).astype(np.float)
        shape = weight.shape[1::-1]
        min_size = min(img.shape[:2])
        depth = int(np.log2(min_size)) - MIN_DEPTH

        gauss_pyr_weight = [gaussPyramid(ch, depth) for ch in np.rollaxis(weight, -1)]
        gauss_pyr = [gaussPyramid(ch, depth) for ch in np.rollaxis(img, -1)]
        lapl_pyr = [laplPyramid(ch) for ch in gauss_pyr]

        img_list.append(lapl_pyr)
        weight_list.append(gauss_pyr_weight)

        viz_pyramid(gauss_pyr_weight, shape, path.join(OUT_FOLDER, 'gauss_pyr_weight' + str(f)), norm=True)
        viz_pyramid(lapl_pyr, shape, path.join(OUT_FOLDER, 'lapl_pyr_img' + str(f)), norm=True)

    """ This 'for' changes (no_images X no_channels X no_layers) order to (no_channels X no_images X no_layers) 
    so that the already implemented blend function can be used for all the three channels."""
    for ch in range(3):

        new_img_list.append([])
        new_weight_list.append([])

        for img in range(no_images):

            new_img_list[ch].append(img_list[img][ch][:])
            new_weight_list[ch].append(weight_list[img][0][:])

        outpyr.append(blend(new_img_list[ch], new_weight_list[ch]))

    outimg = [[collapse(x)] for x in outpyr]

    viz_pyramid(outpyr, shape, path.join(OUT_FOLDER, 'outpyr'), norm=True)
    viz_pyramid(outimg, shape, path.join(OUT_FOLDER, 'outimg'))