mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-18 12:30:14 +08:00
Added example and test
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user