def reduceWidth (im, energyImage):
    cum_energy = cumulative_minimum_energy_map(energyImage, "VERTICAL")
    vSeam = find_optimal_vertical_seam(cum_energy)
    
    #new_im = np.zeros(im.shape[0], im.shape[1]-1)
    #new_energy_map = np.empty_like(energyImage)    
    new_im = np.empty_like(im)
    crop_im = new_im[:, :(im.shape[1]-1)]
#    print "crop_im size is"
#    print crop_im.shape
    new_energy_map = np.empty_like(energyImage)
#    print "new_energy_map size is"
#    print new_energy_map.shape
    crop_energy_map = new_energy_map[:, :(new_energy_map.shape[1]-1)]        
#    print "crop_energy_map size is" 
#    print crop_energy_map.shape
    
    for row in range(im.shape[0]):
        for col in range(im.shape[1]):
                if( col < vSeam[row]):
                    #print "Col is %d and vSeam[row] is %d" % (col, vSeam[row])
                    crop_im[row][col] = im[row][col]
                    crop_energy_map[row][col] = energyImage[row][col]
                elif(col == vSeam[row]):
                    pass
                else:
                    crop_im[row][col-1] = im[row][col]
                    crop_energy_map[row][col-1] = energyImage[row][col]
    return crop_im, crop_energy_map
Example #2
0
def reduceWidth(im, energyImage):
    mapV = cumulative_minimum_energy_map(energyImage, "VERTICAL")
    seam = find_optimal_vertical_seam(mapV)

    newIm = np.zeros((im.shape[0], im.shape[1] - 1, im.shape[2])).astype(int)

    for i in xrange(len(seam)):
        newIm[i] = np.delete(im[i], seam[i], 0)

    return [newIm, energy_image(newIm)]
def reduceWidth(im, energyImage):
    m, n = im.shape[:2]

    cumulativeMinimumEnergyMap = cumulative_minimum_energy_map(
        energyImage, 'VERTICAL')
    verticalSeam = find_optimal_vertical_seam(cumulativeMinimumEnergyMap)

    reducedColorImage = np.zeros((m, n - 1, 3), dtype=np.uint8)
    reducedEnergyImage = np.zeros((m, n - 1), dtype=np.float64)

    for rows in range(m):
        imageCopy = im[rows, :, :]
        mask = np.ones(n, dtype=bool)
        mask[verticalSeam[rows]] = False
        reducedColorImage[rows, :, :] = imageCopy[mask]

    reducedEnergyImage = energy_image(reducedColorImage)

    return [reducedColorImage, reducedEnergyImage]
Example #4
0
def reduceWidth(im, energyImage):

    map = cumulative_minimum_energy_map(energyImage, 'VERTICAL')
    x = find_optimal_vertical_seam(map)
    y = np.arange(im.shape[0])
    height, width, channels = im.shape
    e_height, e_width = energyImage.shape

    final_im = np.zeros((height, width - 1, channels), dtype=np.uint8)
    energy_im = np.zeros((e_height, e_width - 1), dtype=float)

    for y_index in range(0, height):
        left = im[y_index][:x[y_index]][:]
        right = im[y_index][x[y_index] + 1:][:]
        total = np.concatenate((left, right), axis=0)
        final_im[y_index] = total

        left_e = energyImage[y_index][:x[y_index]]
        right_e = energyImage[y_index][x[y_index] + 1:]
        total_e = np.concatenate((left_e, right_e), axis=0)
        energy_im[y_index] = total_e

    return (final_im, energy_im)
def reduceWidth(im, energyImage):
    """
    Args:
        energyImage: 2D matrix of datatype double
        im: MxNx3 matrix of datatype uint8
        
    Returns:
        reducedColorImage: 3D matrix same as the input image but with its width reduced by one pixel
        reducedEnergyImage: 2D matrix same as the inputenergyImage, but with its width reduced by one pixel
    """
    row=np.size(energyImage,0)
    col=np.size(energyImage,1)
    cumap=cumulative_minimum_energy_map(energyImage, 'VERTICAL')
    seam=find_optimal_vertical_seam(cumap)
    reducedColorImage=np.zeros((row,col-1,3),dtype=np.uint8)
    reducedEnergyImage=np.zeros((row,col-1),dtype=np.double)
    for i in range(row):
        reducedColorImage[i,0:seam[i],:]=im[i,0:seam[i],:]
        reducedEnergyImage[i,0:seam[i]]=energyImage[i,0:seam[i]]
        reducedColorImage[i,seam[i]:col-1,:]=im[i,seam[i]+1:col,:]
        reducedEnergyImage[i,seam[i]:col-1]=energyImage[i,seam[i]+1:col]
    return reducedColorImage, reducedEnergyImage
    
Example #6
0
plt.figure()
plt.title('Cumulative Vertical Intensity')
plt.imshow(v_cum_min_energy)
plt.show()
h_cum_min_energy = cumulative_minimum_energy_map(en_image, 'HORIZONTAL')
plt.figure()
plt.title('Cumulative Horizontal Intensity')
plt.imshow(h_cum_min_energy)
plt.show()

plt.figure()
plt.title('Original Image')
plt.imshow(img)
plt.show()

displaySeam(img, find_optimal_vertical_seam(v_cum_min_energy), 'VERTICAL')


displaySeam(img, find_optimal_horizontal_seam(h_cum_min_energy), 'HORIZONTAL')
"""

#vSeam = find_optimal_horizontal_seam(cum_min_energy)
vSeam = find_optimal_vertical_seam(cum_min_energy)
#print find_optimal_horizontal_seam(w)
displaySeam(img, vSeam, 'VERTICAL')
plt.figure(2)
plt.hold(False)
plt.subplot(121)
plt.title('Display after seam')
plt.imshow(img)
plt.imshow(energyImage, cmap=plt.get_cmap('gray'))
# plt.savefig('./energyImagePrague.png')
plt.show()

### cumulative energy map
mapV = cumulative_minimum_energy_map(energyImage, "VERTICAL")
mapH = cumulative_minimum_energy_map(energyImage, "HORIZONTAL")
plt.imshow(mapV, cmap=plt.get_cmap('gray'))
# plt.savefig('./verticalCumulativeEnergyMapPrague.png')
plt.show()
plt.imshow(mapH, cmap=plt.get_cmap('gray'))
# plt.savefig('./horizontalCumulativeEnergyMapPrague.png')
plt.show()

### vertical seam
vSeam = find_optimal_vertical_seam(mapV)

### horizontal seam
hSeam = find_optimal_horizontal_seam(mapH)

### display seam
displaySeam(img, vSeam, "VERTICAL")
displaySeam(img, hSeam, "HORIZONTAL")

### mall
img = mpimg.imread('./inputSeamCarvingMall.jpg')
plt.imshow(img)
# plt.savefig('./energyImagePrague.png')
plt.show()

### energyImage