示例#1
0
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
示例#2
0
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
示例#3
0
def test__get_structure(expected, input, structure):
    result = _utils._get_structure(input, structure)

    assert expected.dtype.type == result.dtype.type
    assert numpy.array((expected == result).all())[()]
示例#4
0
def test_errs__get_structure(err_type, input, structure):
    with pytest.raises(err_type):
        _utils._get_structure(input, structure)