Debian Codegraph @

dask_image/ndfilters/_generic.py

raw
1 # -*- coding: utf-8 -*-
2
3 import numpy as np
4 import scipy.ndimage
5
6 from ..dispatch._dispatch_ndfilters import dispatch_generic_filter
7 from . import _utils
8
9 __all__ = [
10 "generic_filter",
11 ]
12
13
14 @_utils._update_wrapper(scipy.ndimage.generic_filter)
15 def generic_filter(image,
16 function,
17 size=None,
18 footprint=None,
19 mode='reflect',
20 cval=0.0,
21 origin=0,
22 extra_arguments=tuple(),
23 extra_keywords=dict()):
24 footprint = _utils._get_footprint(image.ndim, size, footprint)
25 origin = _utils._get_origin(footprint.shape, origin)
26 depth = _utils._get_depth(footprint.shape, origin)
27 depth, boundary = _utils._get_depth_boundary(footprint.ndim, depth, "none")
28
29 if type(image._meta) is np.ndarray:
30 kwargs = {"extra_arguments": extra_arguments,
31 "extra_keywords": extra_keywords}
32 else: # pragma: no cover
33 # cupy generic_filter doesn't support extra_arguments or extra_keywords
34 kwargs = {}
35
36 result = image.map_overlap(
37 dispatch_generic_filter(image),
38 depth=depth,
39 boundary=boundary,
40 dtype=image.dtype,
41 meta=image._meta,
42 function=function,
43 footprint=footprint,
44 mode=mode,
45 cval=cval,
46 origin=origin,
47 **kwargs
48 )
49
50 return result