def _binary_op(func, input, structure=None, iterations=1, mask=None, origin=0, brute_force=False, **kwargs): input = (input != 0) structure = _utils._get_structure(input, structure) iterations = _utils._get_iterations(iterations) mask = _utils._get_mask(input, mask) origin = _utils._get_origin(structure.shape, origin) brute_force = _utils._get_brute_force(brute_force) depth = _utils._get_depth(structure.shape, origin) depth, boundary = _utils._get_depth_boundary(structure.ndim, depth, "none") result = input for i in irange(iterations): iter_result = result.map_overlap(func, depth=depth, boundary=boundary, dtype=bool, structure=structure, origin=origin, **kwargs) result = _where(mask, iter_result, result) return result
def binary_opening(input, structure=None, iterations=1, origin=0): input = (input != 0) structure = _utils._get_structure(input, structure) iterations = _utils._get_iterations(iterations) origin = _utils._get_origin(structure.shape, origin) result = input result = binary_erosion(result, structure=structure, iterations=iterations, origin=origin) result = binary_dilation(result, structure=structure, iterations=iterations, origin=origin) return result
def test__get_iterations(expected, iterations): assert expected == _utils._get_iterations(iterations)
def test_errs__get_iterations(err_type, iterations): with pytest.raises(err_type): _utils._get_iterations(iterations)