@classmethod<EOL><INDENT>def map_coordinates(cls, image, dx, dy, order=<NUM_LIT:1>, cval=<NUM_LIT:0>, mode="<STR_LIT>"):<DEDENT>
if order == <NUM_LIT:0> and image.dtype.name in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>raise Exception(("<STR_LIT>"<EOL>+ "<STR_LIT>") % (order, image.dtype.name))<EOL><DEDENT>input_dtype = image.dtype<EOL>if image.dtype.name == "<STR_LIT:bool>":<EOL><INDENT>image = image.astype(np.float32)<EOL><DEDENT>elif order == <NUM_LIT:1> and image.dtype.name in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>image = image.astype(np.float64)<EOL><DEDENT>elif order >= <NUM_LIT:2> and image.dtype.name == "<STR_LIT>":<EOL><INDENT>image = image.astype(np.int16)<EOL><DEDENT>elif order >= <NUM_LIT:2> and image.dtype.name == "<STR_LIT>":<EOL><INDENT>image = image.astype(np.float64)<EOL><DEDENT>shrt_max = <NUM_LIT><EOL>backend = "<STR_LIT>"<EOL>if order == <NUM_LIT:0>:<EOL><INDENT>bad_dtype_cv2 = (image.dtype.name in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT:bool>"])<EOL><DEDENT>elif order == <NUM_LIT:1>:<EOL><INDENT>bad_dtype_cv2 = (image.dtype.name in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT:bool>"])<EOL><DEDENT>else:<EOL><INDENT>bad_dtype_cv2 = (image.dtype.name in ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT:bool>"])<EOL><DEDENT>bad_dx_shape_cv2 = (dx.shape[<NUM_LIT:0>] >= shrt_max or dx.shape[<NUM_LIT:1>] >= shrt_max)<EOL>bad_dy_shape_cv2 = (dy.shape[<NUM_LIT:0>] >= shrt_max or dy.shape[<NUM_LIT:1>] >= shrt_max)<EOL>if bad_dtype_cv2 or bad_dx_shape_cv2 or bad_dy_shape_cv2:<EOL><INDENT>backend = "<STR_LIT>"<EOL><DEDENT>ia.do_assert(image.ndim == <NUM_LIT:3>)<EOL>result = np.copy(image)<EOL>height, width = image.shape[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>if backend == "<STR_LIT>":<EOL><INDENT>h, w = image.shape[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>y, x = np.meshgrid(np.arange(h).astype(np.float32), np.arange(w).astype(np.float32), indexing='<STR_LIT>')<EOL>x_shifted = x + (-<NUM_LIT:1>) * dx<EOL>y_shifted = y + (-<NUM_LIT:1>) * dy<EOL>for c in sm.xrange(image.shape[<NUM_LIT:2>]):<EOL><INDENT>remapped_flat = ndimage.interpolation.map_coordinates(<EOL>image[..., c],<EOL>(y_shifted.flatten(), x_shifted.flatten()),<EOL>order=order,<EOL>cval=cval,<EOL>mode=mode<EOL>)<EOL>remapped = remapped_flat.reshape((height, width))<EOL>result[..., c] = remapped<EOL><DEDENT><DEDENT>else:<EOL><INDENT>h, w, nb_channels = image.shape<EOL>y, x = np.meshgrid(np.arange(h).astype(np.float32), np.arange(w).astype(np.float32), indexing='<STR_LIT>')<EOL>x_shifted = x + (-<NUM_LIT:1>) * dx<EOL>y_shifted = y + (-<NUM_LIT:1>) * dy<EOL>if image.dtype.kind == "<STR_LIT:f>":<EOL><INDENT>cval = float(cval)<EOL><DEDENT>else:<EOL><INDENT>cval = int(cval)<EOL><DEDENT>border_mode = cls._MAPPING_MODE_SCIPY_CV2[mode]<EOL>interpolation = cls._MAPPING_ORDER_SCIPY_CV2[order]<EOL>is_nearest_neighbour = (interpolation == cv2.INTER_NEAREST)<EOL>map1, map2 = cv2.convertMaps(x_shifted, y_shifted, cv2.CV_16SC2, nninterpolation=is_nearest_neighbour)<EOL>if nb_channels <= <NUM_LIT:4>:<EOL><INDENT>result = cv2.remap(image, map1, map2, interpolation=interpolation, borderMode=border_mode, borderValue=cval)<EOL>if image.ndim == <NUM_LIT:3> and result.ndim == <NUM_LIT:2>:<EOL><INDENT>result = result[..., np.newaxis]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>current_chan_idx = <NUM_LIT:0><EOL>result = []<EOL>while current_chan_idx < nb_channels:<EOL><INDENT>channels = image[..., current_chan_idx:current_chan_idx+<NUM_LIT:4>]<EOL>result_c =  cv2.remap(channels, map1, map2, interpolation=interpolation, borderMode=border_mode,<EOL>borderValue=cval)<EOL>if result_c.ndim == <NUM_LIT:2>:<EOL><INDENT>result_c = result_c[..., np.newaxis]<EOL><DEDENT>result.append(result_c)<EOL>current_chan_idx += <NUM_LIT:4><EOL><DEDENT>result = np.concatenate(result, axis=<NUM_LIT:2>)<EOL><DEDENT><DEDENT>if result.dtype.name != input_dtype.name:<EOL><INDENT>result = iadt.restore_dtypes_(result, input_dtype)<EOL><DEDENT>return result<EOL>
backend="scipy"

    order=0
        * uint8: yes
        * uint16: yes
        * uint32: yes
        * uint64: no (produces array filled with only 0)
        * int8: yes
        * int16: yes
        * int32: yes
        * int64: no (produces array filled with <min_value> when testing with <max_value>)
        * float16: yes
        * float32: yes
        * float64: yes
        * float128: no (causes: 'data type no supported')
        * bool: yes

    order=1 to 5
        * uint*, int*: yes (rather loose test, to avoid having to re-compute the interpolation)
        * float16 - float64: yes (rather loose test, to avoid having to re-compute the interpolation)
        * float128: no (causes: 'data type no supported')
        * bool: yes

backend="cv2"

    order=0
        * uint8: yes
        * uint16: yes
        * uint32: no (causes: src data type = 6 is not supported)
        * uint64: no (silently converts to int32)
        * int8: yes
        * int16: yes
        * int32: yes
        * int64: no (silently converts to int32)
        * float16: yes
        * float32: yes
        * float64: yes
        * float128: no (causes: src data type = 13 is not supported)
        * bool: no (causes: src data type = 0 is not supported)

    order=1
        * uint8: yes
        * uint16: yes
        * uint32: no (causes: src data type = 6 is not supported)
        * uint64: no (causes: OpenCV(3.4.5) (...)/imgwarp.cpp:1805: error: (-215:Assertion failed) ifunc != 0
          in function 'remap')
        * int8: no (causes: OpenCV(3.4.5) (...)/imgwarp.cpp:1805: error: (-215:Assertion failed) ifunc != 0
          in function 'remap')
        * int16: no (causes: OpenCV(3.4.5) (...)/imgwarp.cpp:1805: error: (-215:Assertion failed) ifunc != 0
          in function 'remap')
        * int32: no (causes: OpenCV(3.4.5) (...)/imgwarp.cpp:1805: error: (-215:Assertion failed) ifunc != 0
          in function 'remap')
        * int64: no (causes: OpenCV(3.4.5) (...)/imgwarp.cpp:1805: error: (-215:Assertion failed) ifunc != 0
          in function 'remap')
        * float16: yes
        * float32: yes
        * float64: yes
        * float128: no (causes: src data type = 13 is not supported)
        * bool: no (causes: src data type = 0 is not supported)

    order=2 to 5:
        as order=1, but int16 supported