示例#1
0
def directionalErode(imIn,
                     imOut,
                     d,
                     size,
                     grid=mamba.DEFAULT_GRID,
                     edge=mamba.FILLED):
    """
    General directional erosion of image 'imIn', result in 'imOut'. The images
    can have any format. The direction 'd' is coded clockwise from 1 to 12 or
    16. Direction 1 corresponds to 60 degrees on the hexagonal grid and 90
    degrees on the square grid. 'size' corresponds to twice the normal size
    when standard directions are used. 'edge' is set to FILLED by default.
    """

    if (d & 1) == 0:
        conjugateDirectionalErode(imIn,
                                  imOut,
                                  d / 2,
                                  size,
                                  grid=grid,
                                  edge=edge)
    else:
        mamba.linearErode(imIn,
                          imOut, (d + 1) / 2,
                          size * 2,
                          grid=grid,
                          edge=edge)
示例#2
0
def conjugateDirectionalErode(imIn, imOut, d, size, grid=mamba.DEFAULT_GRID, edge=mamba.FILLED):
    """
    Performs the erosion of image 'imIn' in the conjugate direction 'd' of the
    grid and puts the result in image 'imOut'. The images can be binary, greyscale
    or 32-bit images. 'size' is a multiple of the distance between two adjacent
    points in the conjugate directions. 'edge' is set to FILLED by default (can
    be changed).
    Note that this operator is not equivalent to successive erosions by a doublet
    of points.
    """

    imWrk1 = mamba.imageMb(imIn)
    imWrk2 = mamba.imageMb(imIn)
    mamba.copy(imIn, imOut)

    j3 = mamba.transposeDirection(d, grid=grid)
    j2 = mamba.rotateDirection(d, grid=grid)
    j1 = mamba.transposeDirection(j2, grid=grid)
    val = mamba.computeMaxRange(imIn)[1] * int(edge == mamba.FILLED)
    for i in range(size):
        mamba.copy(imOut, imWrk1)
        mamba.copy(imOut, imWrk2)
        mamba.linearErode(imWrk1, imWrk1, d, n=1, grid=grid, edge=edge)
        mamba.shift(imWrk1, imWrk1, j1, 1, val, grid=grid)
        mamba.logic(imWrk1, imOut, imWrk1, "inf")
        mamba.linearErode(imWrk2, imWrk2, j2, n=1, grid=grid, edge=edge)
        mamba.shift(imWrk2, imWrk2, j3, 1, val, grid=grid)
        mamba.logic(imWrk2, imOut, imWrk2, "inf")
        mamba.logic(imWrk1, imWrk2, imOut, "sup")
示例#3
0
def conjugateDirectionalErode(imIn,
                              imOut,
                              d,
                              size,
                              grid=mamba.DEFAULT_GRID,
                              edge=mamba.FILLED):
    """
    Performs the erosion of image 'imIn' in the conjugate direction 'd' of the
    grid and puts the result in image 'imOut'. The images can be binary, greyscale
    or 32-bit images. 'size' is a multiple of the distance between two adjacent
    points in the conjugate directions. 'edge' is set to FILLED by default (can
    be changed).
    Note that this operator is not equivalent to successive erosions by a doublet
    of points.
    """

    imWrk1 = mamba.imageMb(imIn)
    imWrk2 = mamba.imageMb(imIn)
    mamba.copy(imIn, imOut)

    j3 = mamba.transposeDirection(d, grid=grid)
    j2 = mamba.rotateDirection(d, grid=grid)
    j1 = mamba.transposeDirection(j2, grid=grid)
    val = mamba.computeMaxRange(imIn)[1] * int(edge == mamba.FILLED)
    for i in range(size):
        mamba.copy(imOut, imWrk1)
        mamba.copy(imOut, imWrk2)
        mamba.linearErode(imWrk1, imWrk1, d, n=1, grid=grid, edge=edge)
        mamba.shift(imWrk1, imWrk1, j1, 1, val, grid=grid)
        mamba.logic(imWrk1, imOut, imWrk1, "inf")
        mamba.linearErode(imWrk2, imWrk2, j2, n=1, grid=grid, edge=edge)
        mamba.shift(imWrk2, imWrk2, j3, 1, val, grid=grid)
        mamba.logic(imWrk2, imOut, imWrk2, "inf")
        mamba.logic(imWrk1, imWrk2, imOut, "sup")
示例#4
0
def linearOpen(imIn, imOut, dir, n, grid=mamba.DEFAULT_GRID, edge=mamba.FILLED):
    """
    Performs an opening by a segment of size 'n' in direction 'dir'.
    
    'edge' is set to 'FILLED' by default. 
    """
    
    mamba.linearErode(imIn, imOut, dir, n, edge=edge, grid=grid)
    mamba.linearDilate(imOut, imOut, mamba.transposeDirection(dir, grid=grid), n, grid=grid)
示例#5
0
def directionalErode(imIn, imOut, d, size, grid=mamba.DEFAULT_GRID, edge=mamba.FILLED):
    """
    General directional erosion of image 'imIn', result in 'imOut'. The images
    can have any format. The direction 'd' is coded clockwise from 1 to 12 or
    16. Direction 1 corresponds to 60 degrees on the hexagonal grid and 90
    degrees on the square grid. 'size' corresponds to twice the normal size
    when standard directions are used. 'edge' is set to FILLED by default.
    """

    if (d & 1) == 0:
        conjugateDirectionalErode(imIn, imOut, d / 2, size, grid=grid, edge=edge)
    else:
        mamba.linearErode(imIn, imOut, (d + 1) / 2, size * 2, grid=grid, edge=edge)
示例#6
0
def linearClose(imIn, imOut, dir, n, grid=mamba.DEFAULT_GRID, edge=mamba.FILLED):
    """
    Performs a closing by a segment of size 'n' in direction 'dir'.
    
    If 'edge' is set to 'EMPTY', the operation must be modified to remain extensive.
    """
    
    imWrk = mamba.imageMb(imIn)
    if edge==mamba.EMPTY:
        mamba.copy(imIn, imWrk)
    mamba.linearDilate(imIn, imOut, dir, n, grid=grid)
    mamba.linearErode(imOut, imOut, mamba.transposeDirection(dir, grid=grid), n, edge=edge, grid=grid)
    if edge==mamba.EMPTY:
        mamba.logic(imOut, imWrk, imOut, "sup")
示例#7
0
def linearOpen(imIn,
               imOut,
               dir,
               n,
               grid=mamba.DEFAULT_GRID,
               edge=mamba.FILLED):
    """
    Performs an opening by a segment of size 'n' in direction 'dir'.
    
    'edge' is set to 'FILLED' by default. 
    """

    mamba.linearErode(imIn, imOut, dir, n, edge=edge, grid=grid)
    mamba.linearDilate(imOut,
                       imOut,
                       mamba.transposeDirection(dir, grid=grid),
                       n,
                       grid=grid)
示例#8
0
def linearClose(imIn,
                imOut,
                dir,
                n,
                grid=mamba.DEFAULT_GRID,
                edge=mamba.FILLED):
    """
    Performs a closing by a segment of size 'n' in direction 'dir'.
    
    If 'edge' is set to 'EMPTY', the operation must be modified to remain extensive.
    """

    imWrk = mamba.imageMb(imIn)
    if edge == mamba.EMPTY:
        mamba.copy(imIn, imWrk)
    mamba.linearDilate(imIn, imOut, dir, n, grid=grid)
    mamba.linearErode(imOut,
                      imOut,
                      mamba.transposeDirection(dir, grid=grid),
                      n,
                      edge=edge,
                      grid=grid)
    if edge == mamba.EMPTY:
        mamba.logic(imOut, imWrk, imOut, "sup")
示例#9
0
def feretDiameterLabelling(imIn, imOut, direc):
    """
    The Feret diameter of each connected component of the binary image or the
    partition image 'imIn' is computed and its value labels the corresponding
    component. The labelled image is stored in the 32-bit image 'imOut'.
    If 'direc' is "vertical", the vertical Feret diameter is computed. If it is
    set to "horizontal", the corresponding diameter is used.    
    """
    
    imWrk1 = mamba.imageMb(imIn, 1)
    imWrk2 = mamba.imageMb(imIn, 32)
    imWrk3 = mamba.imageMb(imIn, 32)
    imWrk4 = mamba.imageMb(imIn, 32)
    
    imWrk1.fill(1)
    if direc == "horizontal":
        dir = 7    
    elif direc == "vertical":
        dir = 1
    else:
        mamba.raiseExceptionOnError(core.MB_ERR_BAD_DIRECTION)
        # The above statement generates an error ('direc' is not horizontal or 
        # vertical.
    # An horizontal or vertical distance function is generated.
    mamba.linearErode(imWrk1, imWrk1, dir, grid=mamba.SQUARE, edge=mamba.EMPTY)
    mamba.computeDistance(imWrk1, imOut, grid=mamba.SQUARE, edge=mamba.FILLED)
    mamba.addConst(imOut, 1, imOut)
    if imIn.getDepth() == 1:
	    # Each particle is valued with the distance.
        mamba.convertByMask(imIn, imWrk2, 0, mamba.computeMaxRange(imWrk3)[1])
        mamba.logic(imOut, imWrk2, imWrk3, "inf")
        # The valued image is preserved.
        mamba.copy(imWrk3, imWrk4)
        # Each component is labelled by the maximal coordinate.
        mamba.build(imWrk2, imWrk3)
        # Using the dual reconstruction, we label the particles with the
        # minimal ccordinate.
        mamba.negate(imWrk2, imWrk2)
        mamba.logic(imWrk2, imWrk4, imWrk4, "sup")
        mamba.dualBuild(imWrk2, imWrk4)
        # We subtract 1 because the selected coordinate must be outside the particle.
        mamba.subConst(imWrk4, 1, imWrk4)
        mamba.negate(imWrk2, imWrk2)
        mamba.logic(imWrk2, imWrk4, imWrk4, "inf")
        # Then, the subtraction gives the Feret diameter.
        mamba.sub(imWrk3, imWrk4, imOut)
    else:
        mamba.copy(imOut, imWrk3)
        if imIn.getDepth() == 32:
            mamba.copy(imIn, imWrk2)
        else:
            mamba.convert(imIn, imWrk2)
	# Using the cells builds (direct and dual to label the cells with the maximum
        # and minimum distance.
        mamba.cellsBuild(imWrk2, imWrk3)
        mamba.cellsBuild(imWrk2, imWrk3)
        mamba.negate(imOut, imOut)
        mamba.cellsBuild(imWrk2, imOut)
        mamba.negate(imOut, imOut)
        # Subtracting 1...
        mamba.subConst(imOut, 1, imOut)
        # ... and getting the final result.
        mamba.sub(imWrk3, imOut, imOut)
示例#10
0
def feretDiameterLabelling(imIn, imOut, direc):
    """
    The Feret diameter of each connected component of the binary image or the
    partition image 'imIn' is computed and its value labels the corresponding
    component. The labelled image is stored in the 32-bit image 'imOut'.
    If 'direc' is "vertical", the vertical Feret diameter is computed. If it is
    set to "horizontal", the corresponding diameter is used.    
    """

    imWrk1 = mamba.imageMb(imIn, 1)
    imWrk2 = mamba.imageMb(imIn, 32)
    imWrk3 = mamba.imageMb(imIn, 32)
    imWrk4 = mamba.imageMb(imIn, 32)

    imWrk1.fill(1)
    if direc == "horizontal":
        dir = 7
    elif direc == "vertical":
        dir = 1
    else:
        mamba.raiseExceptionOnError(core.MB_ERR_BAD_DIRECTION)
        # The above statement generates an error ('direc' is not horizontal or
        # vertical.
    # An horizontal or vertical distance function is generated.
    mamba.linearErode(imWrk1, imWrk1, dir, grid=mamba.SQUARE, edge=mamba.EMPTY)
    mamba.computeDistance(imWrk1, imOut, grid=mamba.SQUARE, edge=mamba.FILLED)
    mamba.addConst(imOut, 1, imOut)
    if imIn.getDepth() == 1:
        # Each particle is valued with the distance.
        mamba.convertByMask(imIn, imWrk2, 0, mamba.computeMaxRange(imWrk3)[1])
        mamba.logic(imOut, imWrk2, imWrk3, "inf")
        # The valued image is preserved.
        mamba.copy(imWrk3, imWrk4)
        # Each component is labelled by the maximal coordinate.
        mamba.build(imWrk2, imWrk3)
        # Using the dual reconstruction, we label the particles with the
        # minimal ccordinate.
        mamba.negate(imWrk2, imWrk2)
        mamba.logic(imWrk2, imWrk4, imWrk4, "sup")
        mamba.dualBuild(imWrk2, imWrk4)
        # We subtract 1 because the selected coordinate must be outside the particle.
        mamba.subConst(imWrk4, 1, imWrk4)
        mamba.negate(imWrk2, imWrk2)
        mamba.logic(imWrk2, imWrk4, imWrk4, "inf")
        # Then, the subtraction gives the Feret diameter.
        mamba.sub(imWrk3, imWrk4, imOut)
    else:
        mamba.copy(imOut, imWrk3)
        if imIn.getDepth() == 32:
            mamba.copy(imIn, imWrk2)
        else:
            mamba.convert(imIn, imWrk2)

# Using the cells builds (direct and dual to label the cells with the maximum
# and minimum distance.
        mamba.cellsBuild(imWrk2, imWrk3)
        mamba.cellsBuild(imWrk2, imWrk3)
        mamba.negate(imOut, imOut)
        mamba.cellsBuild(imWrk2, imOut)
        mamba.negate(imOut, imOut)
        # Subtracting 1...
        mamba.subConst(imOut, 1, imOut)
        # ... and getting the final result.
        mamba.sub(imWrk3, imOut, imOut)