Ejemplo n.º 1
0
def test_displaySeam():
    image_path = "inputSeamCarvingPrague.jpg"
    im = imageio.imread(image_path)
    energy = energy_image(im)
    # Horizontal
    cum_map_h = cumulative_minimum_energy_map(energy, 'HORIZONTAL')
    # view_heat_map(cum_map_h)
    Lh = find_optimal_horizontal_seam(cum_map_h)
    # displaySeam(image_path, Lh, 'HORIZONTAL')
    # Vertical
    cum_map_v = cumulative_minimum_energy_map(energy, 'VERTICAL')
    # view_heat_map(cum_map_v)
    Lv = find_optimal_vertical_seam(cum_map_v)
    # displaySeam(image_path, Lv, 'VERTICAL')
    # Display both
    displayBothSeam(image_path, Lh, Lv)
Ejemplo n.º 2
0
def reduceWidth(im, energyImage):
    cols = find_optimal_vertical_seam(cumulative_minimum_energy_map(energyImage, VER_DIR))
    m, n, d = im.shape
    mask = np.ones(im.shape, dtype=bool)
    mask[np.arange(m), cols, :] = False
    reducedColorImage = im[mask].reshape((m, n - 1, d))
    reducedEnergyImage = energy_image(reducedColorImage)
    return reducedColorImage, reducedEnergyImage
Ejemplo n.º 3
0
def test_find_optimal_vertical_seam():
    image_path = "inputSeamCarvingPrague.jpg"
    im = imageio.imread(image_path)
    energy = energy_image(im)
    cum_map = cumulative_minimum_energy_map(energy, 'VERTICAL')
    # view_heat_map(cum_map)
    L = find_optimal_vertical_seam(cum_map)
    print (L)
Ejemplo n.º 4
0
def test_find_optimal_horizontal_seam():
    image_path = "inputSeamCarvingPrague.jpg"
    im = imageio.imread(image_path)
    energy = energy_image(im)
    cum_map = cumulative_minimum_energy_map(energy, 'HORIZONTAL')
    view_heat_map(cum_map)
    L = find_optimal_horizontal_seam(cum_map)
    print(len(L))
    print(L)
Ejemplo n.º 5
0
def reduceHeight(im, energyImage):
    rows = np.array(
        find_optimal_horizontal_seam(
            cumulative_minimum_energy_map(energyImage, HOR_DIR)))
    im = np.rot90(im, 1, (1, 0))
    m, n, d = im.shape
    mask = np.ones(im.shape, dtype=bool)
    mask[np.arange(m), n - rows, :] = False
    reducedColorImage = im[mask].reshape((m, n - 1, d))
    reducedColorImage = np.rot90(reducedColorImage, 1, (0, 1))
    reducedEnergyImage = energy_image(reducedColorImage)
    return reducedColorImage, reducedEnergyImage
Ejemplo n.º 6
0
def reduceHeight(im, energyImage):
    """Reduced the heigh of an image by remove the optimal horizontal seam
    Parameters
    ----------
    im : np.array (np.uint8)
        The image matrix
    energyImage :np.array (np.float64/double)
        Energy of the image
    Returns
    -------
    reducedImage : np.array (np.uint8)
        The reduced width image
    reducedEnergyImage : np.array (np.float64/double)
        The reduced width energy image
    """
    im_trans = np.transpose(im, axes=[1, 0, 2])
    h, w, c = im_trans.shape
    # Compute the cumulative horizontal energy of the image
    cumulativeEnergyMap = cumulative_minimum_energy_map(
        energyImage, 'HORIZONTAL')
    # Compute the optimal horizontal seam
    seam = find_optimal_horizontal_seam(cumulativeEnergyMap)
    # Generate Index list to delete
    xs = seam
    ys = [i for i in range(h)]
    # Removing seam from image
    mask = np.ones(im_trans.shape, dtype=bool)
    mask[ys, xs, :] = False
    reducedColorImage = im_trans[mask]
    reducedImage = np.transpose(reducedColorImage.reshape(h, w - 1, c),
                                axes=[1, 0, 2])
    # Computing new energy map
    reducedEnergyImage = energy_image(reducedImage)
    # Return the value
    return [reducedImage, reducedEnergyImage]


# Uncomment lines from here for testing
# Test functions
# def test_reduceHeight():
#     image_path = "inputSeamCarvingPrague.jpg"
#     im = imageio.imread(image_path)
#     energy = energy_image(im)
#     new_im, new_energy = reduceHeight(im, energy)
#     view_image(im)
#     view_image(new_im)
#     view_image(energy)
# if __name__=="__main__":
#     test_reduceHeight();