mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-15 11:25:53 +08:00
FIX: doctest of warp_coords
This commit is contained in:
committed by
Johannes Schönberger
parent
c5dc55cd52
commit
e859520872
@@ -717,7 +717,7 @@ def warp_coords(orows, ocols, bands, coord_transform_fn,
|
||||
|
||||
Returns
|
||||
-------
|
||||
coords : (orows * ocols, ) array
|
||||
coords : (3, orows, ocols, bands) array
|
||||
Coordinates for `scipy.ndimage.map_coordinates`, that will yield
|
||||
an image of shape (orows, ocols, bands) by drawing from source
|
||||
points according to the `coord_transform_fn`.
|
||||
@@ -744,12 +744,12 @@ def warp_coords(orows, ocols, bands, coord_transform_fn,
|
||||
... return xy
|
||||
>>>
|
||||
>>> coords = warp_coords(30, 30, 3, shift_right)
|
||||
>>> image = data.camera()
|
||||
>>> warped_image = map_coordinates(coords, image)
|
||||
>>> image = data.lena().astype(np.float32)
|
||||
>>> warped_image = map_coordinates(image, coords)
|
||||
|
||||
"""
|
||||
|
||||
coords = np.empty(np.r_[3, (orows, ocols, bands)], dtype=dtype)
|
||||
coords = np.empty((3, orows, ocols, bands), dtype=dtype)
|
||||
|
||||
# Reshape grid coordinates into a (P, 2) array of (x, y) pairs
|
||||
tf_coords = np.indices((ocols, orows), dtype=dtype).reshape(2, -1).T
|
||||
@@ -833,6 +833,7 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1,
|
||||
def coord_transform_fn(*args):
|
||||
return inverse_map(*args, **map_args)
|
||||
|
||||
|
||||
coords = warp_coords(rows, cols, bands, coord_transform_fn)
|
||||
|
||||
# Prefilter not necessary for order 1 interpolation
|
||||
|
||||
@@ -119,16 +119,13 @@ def test_warp_coords_example():
|
||||
from skimage import data
|
||||
from scipy.ndimage import map_coordinates
|
||||
def shift_right(xy):
|
||||
print 'xyshape', xy.shape
|
||||
xy[:, 0] -= 10
|
||||
return xy
|
||||
|
||||
image = data.lena().astype(np.float32)
|
||||
print 'testing'
|
||||
print image.dtype, image.shape
|
||||
coords = warp_coords(512, 512, 3, shift_right)
|
||||
print 'warp_coords', coords.dtype, coords.shape
|
||||
warped_image = map_coordinates(coords, image)
|
||||
assert 3 == image.shape[2]
|
||||
coords = warp_coords(30, 30, 3, shift_right)
|
||||
warped_image = map_coordinates(image[:, :, 0], coords[:2])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user