示例#1
0
def cellsBuild(imIn, imInOut, grid=mamba.DEFAULT_GRID):
    """
    Geodesic reconstruction of the cells of the partition image 'imIn' which
    are marked by the image 'imInOut'. The marked cells take the value of
    their corresponding marker. Note that the background cells (labelled by 0)
    are also modified if they are marked.
    The result is stored in 'imInOut'.
    The images can be 8-bit or 32-bit images.
    'grid' can be set to HEXAGONAL or SQUARE.
    """
    
    imWrk1 = mamba.imageMb(imIn)
    imWrk2 = mamba.imageMb(imIn)
    imWrk3 = mamba.imageMb(imIn, 1)
    vol = 0
    prec_vol = -1
    dirs = mamba.getDirections(grid)[1:]
    while (prec_vol!=vol):
        prec_vol = vol
        for d in dirs:
            ed = 1<<d
            mamba.copy(imIn, imWrk1)
            mamba.copy(imIn, imWrk2)
            mamba.supNeighbor(imWrk1, imWrk1, ed, grid=grid)
            mamba.infNeighbor(imWrk2, imWrk2, ed, grid=grid)
            mamba.generateSupMask(imWrk2, imWrk1, imWrk3, False)
            mamba.convertByMask(imWrk3, imWrk1, 0, mamba.computeMaxRange(imIn)[1])
            mamba.linearDilate(imInOut, imWrk2, d, 1, grid=grid)
            mamba.logic(imWrk2, imWrk1, imWrk2, "inf")
            v = mamba.buildNeighbor(imWrk1, imWrk2, d, grid=grid)
            mamba.logic(imWrk2, imInOut, imInOut, "sup")
        vol = mamba.computeVolume(imInOut)
示例#2
0
def cellsBuild(imIn, imInOut, grid=mamba.DEFAULT_GRID):
    """
    Geodesic reconstruction of the cells of the partition image 'imIn' which
    are marked by the image 'imInOut'. The marked cells take the value of
    their corresponding marker. Note that the background cells (labelled by 0)
    are also modified if they are marked.
    The result is stored in 'imInOut'.
    The images can be 8-bit or 32-bit images.
    'grid' can be set to HEXAGONAL or SQUARE.
    """

    imWrk1 = mamba.imageMb(imIn)
    imWrk2 = mamba.imageMb(imIn)
    imWrk3 = mamba.imageMb(imIn, 1)
    vol = 0
    prec_vol = -1
    dirs = mamba.getDirections(grid)[1:]
    while (prec_vol != vol):
        prec_vol = vol
        for d in dirs:
            ed = 1 << d
            mamba.copy(imIn, imWrk1)
            mamba.copy(imIn, imWrk2)
            mamba.supNeighbor(imWrk1, imWrk1, ed, grid=grid)
            mamba.infNeighbor(imWrk2, imWrk2, ed, grid=grid)
            mamba.generateSupMask(imWrk2, imWrk1, imWrk3, False)
            mamba.convertByMask(imWrk3, imWrk1, 0,
                                mamba.computeMaxRange(imIn)[1])
            mamba.linearDilate(imInOut, imWrk2, d, 1, grid=grid)
            mamba.logic(imWrk2, imWrk1, imWrk2, "inf")
            v = mamba.buildNeighbor(imWrk1, imWrk2, d, grid=grid)
            mamba.logic(imWrk2, imInOut, imInOut, "sup")
        vol = mamba.computeVolume(imInOut)
示例#3
0
def buildNeighbor3D(imMask, imInOut, d, grid=m3D.DEFAULT_GRID3D):
    """
    Builds  3D image 'imInout' in direction 'd' according to 'grid' using 'imMask'
    as a mask (the propagation is performed only in 'd' direction).
    
    The function also returns the volume of the image 'imInout' after the
    build operation.
    
    'grid' value can be any 3D grid.
    """

    (width, height, length) = imInOut.getSize()
    if length != len(imMask):
        mamba.raiseExceptionOnError(core.MB_ERR_BAD_SIZE)
    grid2D = grid.get2DGrid()
    scan = grid.convertFromDir(d, 0)[0]
    volume = 0
    if scan == 0:
        for i in range(length):
            vol = mamba.buildNeighbor(imMask[i], imInOut[i], d, grid2D)
            volume += vol
    else:
        if scan == 1:
            startPlane, endPlane = 0, length - 1
        else:
            startPlane, endPlane = length - 1, 0
        for i in range(startPlane, endPlane, scan):
            mamba.logic(imInOut[i], imMask[i], imInOut[i], "inf")
            vol = mamba.computeVolume(imInOut[i])
            volume += vol
            td = grid.getTranDir(d)
            dh = grid.convertFromDir(td, i + scan)[1]
            mamba.supNeighbor(imInOut[i], imInOut[i + scan], 1 << dh, grid2D)
        mamba.logic(imInOut[endPlane], imMask[endPlane], imInOut[endPlane],
                    "inf")
        vol = mamba.computeVolume(imInOut[endPlane])
        volume += vol
    return volume
示例#4
0
def buildNeighbor3D(imMask, imInOut, d, grid=m3D.DEFAULT_GRID3D):
    """
    Builds  3D image 'imInout' in direction 'd' according to 'grid' using 'imMask'
    as a mask (the propagation is performed only in 'd' direction).
    
    The function also returns the volume of the image 'imInout' after the
    build operation.
    
    'grid' value can be any 3D grid.
    """
    
    (width, height, length) = imInOut.getSize()
    if length!=len(imMask):
        mamba.raiseExceptionOnError(core.MB_ERR_BAD_SIZE)
    grid2D = grid.get2DGrid()
    scan = grid.convertFromDir(d,0)[0]
    volume = 0
    if scan == 0:
        for i in range(length):
            vol = mamba.buildNeighbor(imMask[i], imInOut[i], d, grid2D)
            volume += vol
    else:
        if scan == 1:
            startPlane, endPlane = 0, length - 1
        else:
            startPlane, endPlane = length - 1, 0
        for i in range(startPlane, endPlane, scan):
            mamba.logic(imInOut[i], imMask[i], imInOut[i], "inf")
            vol = mamba.computeVolume(imInOut[i])
            volume += vol
            td = grid.getTranDir(d)
            dh = grid.convertFromDir(td,i+scan)[1]
            mamba.supNeighbor(imInOut[i], imInOut[i+scan], 1<<dh, grid2D)
        mamba.logic(imInOut[endPlane], imMask[endPlane], imInOut[endPlane], "inf")
        vol = mamba.computeVolume(imInOut[endPlane])
        volume += vol
    return volume