In [22]:
cd /Users/dharness/dev/seam
In [34]:
%reload_ext autoreload
%autoreload
import matplotlib.animation as animation
import matplotlib.pyplot as plt
from scipy import misc
from scipy.ndimage.filters import gaussian_filter
import numpy as np
from IPython.display import Image
from seam_carver.seam_carver import (
normalize,
compute_eng_grad,
compute_eng_color,
compute_eng,
remove_seam,
add_seam,
find_seams,
get_best_seam,
reduce_width,
reduce_height,
increase_width,
increase_height,
intelligent_resize
)
In [9]:
Image(filename='./demo/cat.png')
Out[9]:
In [10]:
cat_img = misc.imread('./demo/cat.png')
eng = compute_eng_grad(cat_img)
misc.imsave('./demo/cat_eng_grad.png', eng)
Image(filename='./demo/cat_eng_grad.png')
Out[10]:
In [11]:
rgb_weights = [-3, 1, -3]
cat_img = misc.imread('./demo/cat.png')
eng = compute_eng_color(cat_img, rgb_weights)
misc.imsave('./demo/cat_eng_color.png', eng)
Image(filename='./demo/cat_eng_color.png')
Out[11]:
In [12]:
rgb_weights = [-3, 1, -3]
mask_weight = 10
cat_img = misc.imread('./demo/cat.png')
mask = np.zeros(cat_img.shape)
img4 = np.dstack((cat_img, mask))
eng = compute_eng(img4, rgb_weights, mask_weight)
misc.imsave('./demo/cat_eng_total.png', eng)
Image(filename='./demo/cat_eng_total.png')
Out[12]:
In [13]:
%autoreload
rgb_weights = [-3, 1, -3]
mask_weight = 10
cat_img = misc.imread('./demo/cat.png')
dims = (cat_img.shape[0], cat_img.shape[1])
img4 = np.dstack((
cat_img,
np.zeros(dims)
))
eng = compute_eng(img4, rgb_weights, mask_weight)
seam, adjusted_img4, cost, adjusted_eng = increase_width(img4, eng)
%matplotlib inline
plt.imshow(adjusted_eng, cmap='gray')
Out[13]:
In [14]:
%autoreload
rgb_weights = [-3, 1, -3]
mask_weight = 10
cat_img = misc.imread('./demo/cat.png')
dims = (cat_img.shape[0], cat_img.shape[1])
img4 = np.dstack((
cat_img,
np.zeros(dims)
))
eng = compute_eng(img4, rgb_weights, mask_weight)
seam, adjusted_img4, cost, adjusted_eng = increase_height(img4, eng)
%matplotlib inline
plt.imshow(adjusted_eng, cmap='gray')
Out[14]:
In [19]:
%autoreload
rgb_weights = [-3, 1, -3]
mask_weight = 10
cat_img = misc.imread('./demo/cat.png')
mask = np.zeros(cat_img.shape)
resized_img = intelligent_resize(cat_img, 0, -20, rgb_weights, mask, mask_weight)
misc.imsave('./demo/cat_shrunk.png', resized_img)
Image(filename='./demo/cat_shrunk.png')
Out[19]:
In [20]:
%autoreload
resized_img = intelligent_resize(cat_img, 0, 50, rgb_weights, mask, mask_weight)
misc.imsave('./demo/cat_grown.png', resized_img)
Image(filename='./demo/cat_grown.png')
Out[20]: