diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index 0e590487..2fd2a694 100644 --- a/skimage/transform/_geometric.py +++ b/skimage/transform/_geometric.py @@ -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 diff --git a/skimage/transform/tests/test_warps.py b/skimage/transform/tests/test_warps.py index 28350ff6..3cde47ac 100644 --- a/skimage/transform/tests/test_warps.py +++ b/skimage/transform/tests/test_warps.py @@ -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__":