Added example and test

This commit is contained in:
Vighnesh Birodkar
2015-03-30 13:22:22 +05:30
parent d30ed25968
commit 29ec5ee3ec
4 changed files with 76 additions and 18 deletions
+28 -9
View File
@@ -1,19 +1,38 @@
"""
============
Seam Carving
============
This example demonstrates how images can be resized using seam carving [1]_.
Resizing often distorts contents in the image. Seam carving tries to resize
images while trying to keep important content intact. In this example we are
using the Sobel filter to signify the importance of each pixel.
.. [1] Shai Avidan and Ariel Shamir
"Seam Carving for Content-Aware Image Resizing"
http://www.cs.jhu.edu/~misha/ReadingSeminar/Papers/Avidan07.pdf
"""
from skimage import io, data
from skimage import transform
from skimage import color, filters
from matplotlib import pyplot as plt
def custom_sobel(img):
if img.ndim == 3:
img = color.rgb2gray(img)
return filters.sobel(img)
img = data.coins()
out = transform.seam_carve(img, 'vertical', 80, energy_func = custom_sobel)
out = transform.seam_carve(out, 'horizontal', 70, energy_func = custom_sobel)
out = transform.seam_carve(img, 'vertical', 80, energy_func = filters.sobel)
out = transform.seam_carve(out, 'horizontal', 70, energy_func = filters.sobel)
resized = transform.resize(img, out.shape)
plt.title('Original Image')
io.imshow(img, plugin='matplotlib')
io.imshow(out)
plt.figure()
io.imshow(img)
plt.title('Resized Image Image')
io.imshow(resized, plugin='matplotlib')
plt.figure()
plt.title('Resized Image Image')
io.imshow(out, plugin='matplotlib')
io.show()