mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-18 12:30:14 +08:00
Add nearest mode for positions outside image
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user