mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-17 11:32:45 +08:00
add support for using transformation objects in warp function
This commit is contained in:
@@ -495,10 +495,12 @@ def warp(image, reverse_map=None, map_args={}, output_shape=None, order=1,
|
||||
----------
|
||||
image : 2-D array
|
||||
Input image.
|
||||
reverse_map : callable xy = f(xy, **kwargs)
|
||||
Reverse coordinate map. A function that transforms a Px2 array of
|
||||
reverse_map : transformation object, callable xy = f(xy, **kwargs)
|
||||
Reverse coordinate map. A function that transforms a Px2 array of
|
||||
``(x, y)`` coordinates in the *output image* into their corresponding
|
||||
coordinates in the *source image*. Also see examples below.
|
||||
coordinates in the *source image*. In case of a transformation object
|
||||
its `reverse` method will be used as transformation function. Also see
|
||||
examples below.
|
||||
map_args : dict, optional
|
||||
Keyword arguments passed to `reverse_map`.
|
||||
output_shape : tuple (rows, cols)
|
||||
@@ -548,6 +550,8 @@ def warp(image, reverse_map=None, map_args={}, output_shape=None, order=1,
|
||||
|
||||
# Map each (x, y) pair to the source image according to
|
||||
# the user-provided mapping
|
||||
if callable(getattr(reverse_map, 'reverse', None)):
|
||||
reverse_map = reverse_map.reverse
|
||||
tf_coords = reverse_map(tf_coords, **map_args)
|
||||
|
||||
# Reshape back to a (2, M, N) coordinate grid
|
||||
|
||||
@@ -2,10 +2,9 @@ import numpy as np
|
||||
from numpy.testing import assert_array_almost_equal
|
||||
|
||||
from skimage.transform.geometric import _stackcopy
|
||||
from skimage.transform import estimate_transformation, \
|
||||
SimilarityTransformation, AffineTransformation, ProjectiveTransformation, \
|
||||
PolynomialTransformation
|
||||
from skimage.transform import homography, fast_homography
|
||||
from skimage.transform import estimate_transformation, homography, warp, \
|
||||
fast_homography, SimilarityTransformation, AffineTransformation, \
|
||||
ProjectiveTransformation, PolynomialTransformation
|
||||
from skimage import transform as tf, data, img_as_float
|
||||
from skimage.color import rgb2gray
|
||||
|
||||
@@ -142,8 +141,23 @@ def test_union():
|
||||
assert_array_almost_equal(tform.rotation, rotation1 + rotation2)
|
||||
|
||||
|
||||
def test_warp():
|
||||
x = np.zeros((5, 5), dtype=np.uint8)
|
||||
x[2, 2] = 255
|
||||
x = img_as_float(x)
|
||||
theta = -np.pi/2
|
||||
tform = SimilarityTransformation()
|
||||
tform.from_params(1, theta, (0, 4))
|
||||
|
||||
x90 = warp(x, tform, order=1)
|
||||
assert_array_almost_equal(x90, np.rot90(x))
|
||||
|
||||
x90 = warp(x, tform.reverse, order=1)
|
||||
assert_array_almost_equal(x90, np.rot90(x))
|
||||
|
||||
|
||||
def test_homography():
|
||||
x = np.zeros((5,5), dtype=np.uint8)
|
||||
x = np.zeros((5, 5), dtype=np.uint8)
|
||||
x[1, 1] = 255
|
||||
x = img_as_float(x)
|
||||
theta = -np.pi/2
|
||||
|
||||
Reference in New Issue
Block a user