Debian Codegraph @

dask_image/ndmorph/_ops.py

raw
1 # -*- coding: utf-8 -*-
2
3
4 import dask.array as da
5
6 from . import _utils
7
8
9 def _binary_op(func,
10 image,
11 structure=None,
12 iterations=1,
13 mask=None,
14 origin=0,
15 brute_force=False,
16 **kwargs):
17 image = (image != 0)
18
19 structure = _utils._get_structure(image, structure)
20 iterations = _utils._get_iterations(iterations)
21 mask = _utils._get_mask(image, mask)
22 origin = _utils._get_origin(structure.shape, origin)
23 brute_force = _utils._get_brute_force(brute_force)
24 depth = _utils._get_depth(structure.shape, origin)
25 depth, boundary = _utils._get_depth_boundary(structure.ndim, depth, "none")
26
27 result = image
28 for i in range(iterations):
29 iter_result = result.map_overlap(
30 func,
31 depth=depth,
32 boundary=boundary,
33 dtype=bool,
34 meta=image._meta,
35 structure=structure,
36 origin=origin,
37 **kwargs
38 )
39 result = da.where(mask, iter_result, result)
40 result._meta = image._meta.astype(bool)
41
42 return result