mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-02 13:03:48 +08:00
Formatting changes
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
from _seam_carving import _seam_carve_v
|
||||
from ..import filters
|
||||
from .. import util
|
||||
from .._shared import utils
|
||||
import numpy as np
|
||||
|
||||
|
||||
def seam_carve(img, mode, num, energy_func, extra_args = [],
|
||||
extra_kwargs = {}, border=1, force_copy = True):
|
||||
def seam_carve(img, mode, num, energy_func, extra_args=[],
|
||||
extra_kwargs={}, border=1, force_copy=True):
|
||||
""" Carve vertical or horizontal seams off an image.
|
||||
|
||||
Carves out vertical/horizontal seams off an image while using the given
|
||||
@@ -55,25 +54,24 @@ def seam_carve(img, mode, num, energy_func, extra_args = [],
|
||||
http://www.cs.jhu.edu/~misha/ReadingSeminar/Papers/Avidan07.pdf
|
||||
"""
|
||||
|
||||
utils.assert_nD(img, (2,3))
|
||||
utils.assert_nD(img, (2, 3))
|
||||
img = util.img_as_float(img)
|
||||
|
||||
|
||||
if mode == 'horizontal':
|
||||
img = np.ascontiguousarray(img)
|
||||
return _seam_carve_v(img, num, energy_func, extra_args ,extra_kwargs,
|
||||
return _seam_carve_v(img, num, energy_func, extra_args, extra_kwargs,
|
||||
border)
|
||||
elif mode == 'vertical' :
|
||||
elif mode == 'vertical':
|
||||
if img.ndim == 3:
|
||||
img = np.transpose(img, (1, 0, 2))
|
||||
else:
|
||||
img = img.T
|
||||
|
||||
img = np.ascontiguousarray(img)
|
||||
out = _seam_carve_v(img, num, energy_func, extra_args , extra_kwargs,
|
||||
out = _seam_carve_v(img, num, energy_func, extra_args, extra_kwargs,
|
||||
border)
|
||||
|
||||
if img.ndim == 3:
|
||||
return np.transpose(out, (1, 0, 2))
|
||||
return np.transpose(out, (1, 0, 2))
|
||||
else:
|
||||
return out.T
|
||||
|
||||
@@ -2,17 +2,19 @@ from skimage import transform
|
||||
import numpy as np
|
||||
from numpy import testing
|
||||
|
||||
|
||||
def energy(img):
|
||||
if(img.ndim == 3):
|
||||
return np.ascontiguousarray(img[:, :, 0])
|
||||
return (1 - img)
|
||||
|
||||
|
||||
def test_seam_carving():
|
||||
img = np.array([[0, 0, 1, 0, 0],
|
||||
[0, 0, 1, 0, 0],
|
||||
[0, 0, 1, 0, 0],
|
||||
[0, 1, 0, 0, 0],
|
||||
[1, 0 , 0, 0, 0]], dtype = np.float )
|
||||
[1, 0, 0, 0, 0]], dtype=np.float)
|
||||
|
||||
out = transform.seam_carve(img, 'horizontal', 1, energy, border=0)
|
||||
testing.assert_allclose(out, 0)
|
||||
@@ -28,6 +30,5 @@ def test_seam_carving():
|
||||
out = transform.seam_carve(img3, 'horizontal', 1, energy, border=0)
|
||||
testing.assert_allclose(out, 0)
|
||||
|
||||
|
||||
out = transform.seam_carve(img3, 'vertical', 1, energy, border=0)
|
||||
testing.assert_allclose(out, 0)
|
||||
|
||||
Reference in New Issue
Block a user