예제 #1
0
def reduceHeight (im, energyImage):
    cum_energy = cumulative_minimum_energy_map(energyImage, "HORIZONTAL")
    hSeam = find_optimal_horizontal_seam(cum_energy)
    new_im = np.empty_like(im)
    crop_im = new_im[:(im.shape[0]-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[:(energyImage.shape[0]-1), :]        
#    print "crop_energy_map size is" 
#    print crop_energy_map.shape
      
    for col in range(im.shape[1]):
        for row in range(im.shape[0]):
                if( row < hSeam[col]):
                    #print "Col is %d and hSeam[col] is %d" % (col, hSeam[col])
                    crop_im[row][col] = im[row][col]
                    crop_energy_map[row][col] = energyImage[row][col]
                elif(row == hSeam[col]):
                    pass                    
                else:
                    crop_im[row-1][col] = im[row][col]
                    crop_energy_map[row-1][col] = energyImage[row][col]
#    imsave("crop_output.jpg", crop_im)
    return crop_im, crop_energy_map
def reduceHeight(im, energyImage):
    mapH = cumulative_minimum_energy_map(energyImage, "HORIZONTAL")
    seam = find_optimal_horizontal_seam(mapH)

    newIm = np.zeros((im.shape[0] - 1, im.shape[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 reduceHeight(im, energyImage):
    m, n = im.shape[: 2]
    
    cumulativeMinimumEnergyMap = cumulative_minimum_energy_map(energyImage,'HORIZONTAL')
    horizontal_seam = find_optimal_horizontal_seam(cumulativeMinimumEnergyMap)
    
    reducedColorImage = np.zeros((m-1,n,3),dtype = np.uint8)
    reducedEnergyImage = np.zeros((m-1,n),dtype = np.float64)

    for col in range(n):
        imageCopy = im[:,col,:]
        mask = np.ones(m,dtype = bool)
        mask[horizontal_seam[col]] = False
        reducedColorImage[:,col,:] = imageCopy[mask]
    
    reducedEnergyImage = energy_image(reducedColorImage)
        
    return [reducedColorImage,reducedEnergyImage]
def reduceHeight(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 height reduced by one pixel
        reducedEnergyImage: 2D matrix same as the inputenergyImage, but with its height reduced by one pixel
    """
    row = np.size(energyImage, 0)
    col = np.size(energyImage, 1)
    cumap = cumulative_minimum_energy_map(energyImage, 'HORIZONTAL')
    seam = find_optimal_horizontal_seam(cumap)
    reducedColorImage = np.zeros((row - 1, col, 3), dtype=np.uint8)
    reducedEnergyImage = np.zeros((row - 1, col), dtype=np.double)
    for i in range(col):
        reducedColorImage[0:seam[i], i, :] = im[0:seam[i], i, :]
        reducedEnergyImage[0:seam[i], i] = energyImage[0:seam[i], i]
        reducedColorImage[seam[i]:row - 1, i, :] = im[seam[i] + 1:row, i, :]
        reducedEnergyImage[seam[i]:row - 1, i] = energyImage[seam[i] + 1:row,
                                                             i]
    return reducedColorImage, reducedEnergyImage
예제 #5
0
def reduceHeight(im, energyImage):
    input_color_image = im
    input_image_nth_row, input_image_nth_col, input_image_nth_channel = input_color_image.shape

    reducedColorImage = np.zeros((input_image_nth_row - 1, input_image_nth_col,
                                  input_image_nth_channel),
                                 dtype=np.uint8)
    horizontalSeam = find_optimal_horizontal_seam(
        cumulative_minimum_energy_map(energyImage, 'HORIZONTAL'))

    for ith_col in xrange(0, input_image_nth_col):
        reducedColorImage[:, ith_col,
                          0] = np.delete(input_color_image[:, ith_col, 0],
                                         horizontalSeam[ith_col])
        reducedColorImage[:, ith_col,
                          1] = np.delete(input_color_image[:, ith_col, 1],
                                         horizontalSeam[ith_col])
        reducedColorImage[:, ith_col,
                          2] = np.delete(input_color_image[:, ith_col, 2],
                                         horizontalSeam[ith_col])

    reducedEnergyImage = energy_image(reducedColorImage)

    return reducedColorImage, reducedEnergyImage
예제 #6
0
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)

for i in range(1):
    img, en_image = reduceWidth(img, en_image)
plt.subplot(122)
### 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
energyImage = energy_image(img)
plt.imshow(energyImage, cmap=plt.get_cmap('gray'))
# plt.savefig('./energyImagePrague.png')