Add nearest mode for positions outside image

This commit is contained in:
Johannes Schönberger
2012-08-30 12:08:21 +02:00
parent 4dfdc7f74f
commit 4cd1f8798b
4 changed files with 25 additions and 23 deletions
+2 -5
View File
@@ -832,11 +832,8 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1,
ishape = np.array(image.shape)
bands = ishape[2]
# use fast Cython version for specific parameters
fast_modes = ('constant', 'reflect', 'wrap')
fast_orders = (0, 1, 3)
if order in fast_orders and mode in fast_modes and not map_args:
# use fast Cython version for specific interpolation orders
if order in (0, 1, 3) and not map_args:
matrix = None
if isinstance(inverse_map, HOMOGRAPHY_TRANSFORMS):
matrix = inverse_map._matrix
+2 -2
View File
@@ -86,9 +86,9 @@ def _warp_fast(np.ndarray image, np.ndarray H, output_shape=None, int order=1,
cdef np.ndarray[dtype=np.double_t, ndim=2, mode="c"] M = \
np.ascontiguousarray(H)
if mode not in ('constant', 'wrap', 'reflect'):
if mode not in ('constant', 'wrap', 'reflect', 'nearest'):
raise ValueError("Invalid mode specified. Please use "
"`constant`, `wrap` or `reflect`.")
"`constant`, `nearest`, `wrap` or `reflect`.")
cdef char mode_c = ord(mode[0].upper())
cdef int out_r, out_c
+1 -1
View File
@@ -58,7 +58,7 @@ def test_fast_homography():
coords = warp_coords(tform.inverse, (img.shape[0], img.shape[1]))
for order in range(4):
for mode in ('constant', 'reflect', 'wrap'):
for mode in ('constant', 'reflect', 'wrap', 'nearest'):
p0 = map_coordinates(img, coords, mode=mode, order=order)
p1 = warp(img, tform, mode=mode, order=order)