Ejemplo n.º 1
0
def binary_hit_or_miss(input, structure1 = None, structure2 = None,
                       output = None, origin1 = 0, origin2 = None):
    """Multi-dimensional binary hit-or-miss transform.
    
    An output array can optionally be provided. The origin parameters
    controls the placement of the structuring elements. If the first
    structuring element is not given one is generated with a squared
    connectivity equal to one. If the second structuring element is
    not provided, it set equal to the inverse of the first structuring
    element. If the origin for the second structure is equal to None
    it is set equal to the origin of the first.
    """
    input = numarray.asarray(input)
    if structure1 is None:
        structure1 = generate_binary_structure(input.rank, 1)
    if structure2 is None:
        structure2 = numarray.logical_not(structure1)
    origin1 = _ni_support._normalize_sequence(origin1, input.rank)
    if origin2 is None:
        origin2 = origin1
    else:
        origin2 = _ni_support._normalize_sequence(origin2, input.rank)

    tmp1 = _binary_erosion(input, structure1, 1, None, None, 0, origin1,
                           0, False)
    inplace = isinstance(output, numarray.NumArray)
    result = _binary_erosion(input, structure2, 1, None, output, 0,
                             origin2, 1, False)
    if inplace:
        numarray.logical_not(output, output)
        numarray.logical_and(tmp1, output, output)
    else:
        numarray.logical_not(result, result)
        return numarray.logical_and(tmp1, result)
Ejemplo n.º 2
0
def binary_fill_holes(input, structure=None, output=None, origin=0):
    """Fill the holes in binary objects.
    
    An output array can optionally be provided. The origin parameter
    controls the placement of the filter. If no structuring element is
    provided an element is generated with a squared connectivity equal
    to one.
    """
    mask = numarray.logical_not(input)
    tmp = numarray.zeros(mask.shape, numarray.Bool)
    inplace = isinstance(output, numarray.NumArray)
    if inplace:
        binary_dilation(tmp, structure, -1, mask, output, 1, origin)
        numarray.logical_not(output, output)
    else:
        output = binary_dilation(tmp, structure, -1, mask, None, 1, origin)
        numarray.logical_not(output, output)
        return output
Ejemplo n.º 3
0
def binary_fill_holes(input, structure = None, output = None, origin = 0):
    """Fill the holes in binary objects.
    
    An output array can optionally be provided. The origin parameter
    controls the placement of the filter. If no structuring element is
    provided an element is generated with a squared connectivity equal
    to one.
    """
    mask = numarray.logical_not(input)
    tmp = numarray.zeros(mask.shape, numarray.Bool)
    inplace = isinstance(output, numarray.NumArray)
    if inplace:
        binary_dilation(tmp, structure, -1, mask, output, 1, origin)
        numarray.logical_not(output, output)
    else:
        output = binary_dilation(tmp, structure, -1, mask, None, 1,
                                 origin)
        numarray.logical_not(output, output)
        return output
Ejemplo n.º 4
0
def MaskToList(mask):

    "Turn a mask into a list of rows to delete"

    mask = numarray.array( mask, numarray.Bool)
    mask = numarray.logical_not(mask)
    xr=numarray.arange( len(mask) )[mask]
    xr=numarray.array(xr)

    res=pybnfits.LongVector(len(xr))
    for i,v in enumerate(xr):
        res[i]=v+1
    return res
Ejemplo n.º 5
0
def binary_hit_or_miss(input,
                       structure1=None,
                       structure2=None,
                       output=None,
                       origin1=0,
                       origin2=None):
    """Multi-dimensional binary hit-or-miss transform.
    
    An output array can optionally be provided. The origin parameters
    controls the placement of the structuring elements. If the first
    structuring element is not given one is generated with a squared
    connectivity equal to one. If the second structuring element is
    not provided, it set equal to the inverse of the first structuring
    element. If the origin for the second structure is equal to None
    it is set equal to the origin of the first.
    """
    input = numarray.asarray(input)
    if structure1 is None:
        structure1 = generate_binary_structure(input.rank, 1)
    if structure2 is None:
        structure2 = numarray.logical_not(structure1)
    origin1 = _ni_support._normalize_sequence(origin1, input.rank)
    if origin2 is None:
        origin2 = origin1
    else:
        origin2 = _ni_support._normalize_sequence(origin2, input.rank)

    tmp1 = _binary_erosion(input, structure1, 1, None, None, 0, origin1, 0,
                           False)
    inplace = isinstance(output, numarray.NumArray)
    result = _binary_erosion(input, structure2, 1, None, output, 0, origin2, 1,
                             False)
    if inplace:
        numarray.logical_not(output, output)
        numarray.logical_and(tmp1, output, output)
    else:
        numarray.logical_not(result, result)
        return numarray.logical_and(tmp1, result)