Esempio n. 1
0
def upperGeodesicDilate3D(imIn, imMask, imOut, n=1, se=m3D.CUBOCTAHEDRON1):
    """
    Performs a upper geodesic dilation of 3D image 'imIn' above 'imMask'.
    The result is put inside 'imOut', 'n' controls the size of the dilation.
    'se' specifies the type of structuring element used to perform the 
    computation (CUBOCTAHEDRON by default). 
    
    Warning! 'imMask' and 'imOut' must be different.
    """
    
    m3D.logic3D(imIn, imMask, imOut, "sup")
    if imIn.getDepth() == 1:
        for i in range(n):
            m3D.diff3D(imOut, imMask, imOut)
            m3D.dilate3D(imOut, imOut, se=se)
            m3D.logic3D(imMask, imOut, imOut, "sup")
    else:
        imWrk1 = m3D.image3DMb(imIn)
        imWrk2 = m3D.image3DMb(imIn, 1)
        for i in range(n):
            m3D.generateSupMask3D(imOut, imMask, imWrk2, True)
            m3D.convertByMask3D(imWrk2, imWrk1, 0, m3D.computeMaxRange3D(imWrk1)[1])
            m3D.logic3D(imOut, imWrk1, imOut, "inf")
            m3D.dilate3D(imOut, imOut, se=se)
            m3D.logic3D(imOut, imMask, imOut, "sup")
Esempio n. 2
0
def lowerGeodesicErode3D(imIn, imMask, imOut, n=1, se=m3D.CUBOCTAHEDRON1):
    """
    Performs a lower geodesic erosion of 3D image 'imIn' under 'imMask'.
    The result is put inside 'imOut', 'n' controls the size of the erosion.
    'se' specifies the type of structuring element used to perform the 
    computation (CUBOCTAHEDRON by default).

    The binary lower geodesic erosion is realised using the fact that the
    dilation is the dual operation of the erosion.
    
    Warning! 'imMask' and 'imOut' must be different.
    """
    
    if imIn.getDepth() == 1:
        m3D.diff3D(imMask, imIn, imOut)
        lowerGeodesicDilate3D(imOut, imMask, imOut, n, se=se)
        m3D.diff3D(imMask, imOut, imOut)
    else:
        imWrk1 = m3D.image3DMb(imIn)
        imWrk2 = m3D.image3DMb(imIn, 1)
        m3D.logic3D(imIn, imMask, imOut, "inf")
        for i in range(n):
            m3D.generateSupMask3D(imOut, imMask, imWrk2, False)
            m3D.convertByMask3D(imWrk2, imWrk1, 0, m3D.computeMaxRange3D(imWrk1)[1])
            m3D.logic3D(imOut, imWrk1, imOut, "sup")
            m3D.erode3D(imOut, imOut, se=se)
            m3D.logic3D(imOut, imMask, imOut, "inf")
Esempio n. 3
0
def upperGeodesicDilate3D(imIn, imMask, imOut, n=1, se=m3D.CUBOCTAHEDRON1):
    """
    Performs a upper geodesic dilation of 3D image 'imIn' above 'imMask'.
    The result is put inside 'imOut', 'n' controls the size of the dilation.
    'se' specifies the type of structuring element used to perform the 
    computation (CUBOCTAHEDRON by default). 
    
    Warning! 'imMask' and 'imOut' must be different.
    """

    m3D.logic3D(imIn, imMask, imOut, "sup")
    if imIn.getDepth() == 1:
        for i in range(n):
            m3D.diff3D(imOut, imMask, imOut)
            m3D.dilate3D(imOut, imOut, se=se)
            m3D.logic3D(imMask, imOut, imOut, "sup")
    else:
        imWrk1 = m3D.image3DMb(imIn)
        imWrk2 = m3D.image3DMb(imIn, 1)
        for i in range(n):
            m3D.generateSupMask3D(imOut, imMask, imWrk2, True)
            m3D.convertByMask3D(imWrk2, imWrk1, 0,
                                m3D.computeMaxRange3D(imWrk1)[1])
            m3D.logic3D(imOut, imWrk1, imOut, "inf")
            m3D.dilate3D(imOut, imOut, se=se)
            m3D.logic3D(imOut, imMask, imOut, "sup")
Esempio n. 4
0
def lowerGeodesicErode3D(imIn, imMask, imOut, n=1, se=m3D.CUBOCTAHEDRON1):
    """
    Performs a lower geodesic erosion of 3D image 'imIn' under 'imMask'.
    The result is put inside 'imOut', 'n' controls the size of the erosion.
    'se' specifies the type of structuring element used to perform the 
    computation (CUBOCTAHEDRON by default).

    The binary lower geodesic erosion is realised using the fact that the
    dilation is the dual operation of the erosion.
    
    Warning! 'imMask' and 'imOut' must be different.
    """

    if imIn.getDepth() == 1:
        m3D.diff3D(imMask, imIn, imOut)
        lowerGeodesicDilate3D(imOut, imMask, imOut, n, se=se)
        m3D.diff3D(imMask, imOut, imOut)
    else:
        imWrk1 = m3D.image3DMb(imIn)
        imWrk2 = m3D.image3DMb(imIn, 1)
        m3D.logic3D(imIn, imMask, imOut, "inf")
        for i in range(n):
            m3D.generateSupMask3D(imOut, imMask, imWrk2, False)
            m3D.convertByMask3D(imWrk2, imWrk1, 0,
                                m3D.computeMaxRange3D(imWrk1)[1])
            m3D.logic3D(imOut, imWrk1, imOut, "sup")
            m3D.erode3D(imOut, imOut, se=se)
            m3D.logic3D(imOut, imMask, imOut, "inf")
Esempio n. 5
0
def thin3D(imIn, imOut, dse, edge=mamba.EMPTY):
    """
    Elementary thinning operator with 'dse' double structuring element.
    'imIn' and 'imOut' are binary 3D images.
    
    'edge' is set to EMPTY by default.
    """

    imWrk = m3D.image3DMb(imIn)
    hitOrMiss3D(imIn, imWrk, dse, edge=edge)
    m3D.diff3D(imIn, imWrk, imOut)
Esempio n. 6
0
def thin3D(imIn, imOut, dse, edge=mamba.EMPTY):
    """
    Elementary thinning operator with 'dse' double structuring element.
    'imIn' and 'imOut' are binary 3D images.
    
    'edge' is set to EMPTY by default.
    """
        
    imWrk = m3D.image3DMb(imIn)
    hitOrMiss3D(imIn, imWrk, dse, edge=edge)
    m3D.diff3D(imIn, imWrk, imOut)
Esempio n. 7
0
def removeEdgeParticles3D(imIn, imOut, grid=m3D.DEFAULT_GRID3D):
    """
    Removes particles (connected components) touching the edge in 3D image
    'imIn'. The resulting image is put in image 'imOut'.
    Although this operator may be used with greytone images, it should be
    considered with caution.
    """
    
    imWrk = m3D.image3DMb(imIn)
    se = m3D.structuringElement3D(m3D.getDirections3D(grid), grid)
    m3D.dilate3D(imWrk, imWrk, se=se, edge=mamba.FILLED)
    m3D.logic3D(imIn, imWrk, imWrk, "inf")
    build3D(imIn, imWrk, grid=grid)
    m3D.diff3D(imIn, imWrk, imOut)
Esempio n. 8
0
def removeEdgeParticles3D(imIn, imOut, grid=m3D.DEFAULT_GRID3D):
    """
    Removes particles (connected components) touching the edge in 3D image
    'imIn'. The resulting image is put in image 'imOut'.
    Although this operator may be used with greytone images, it should be
    considered with caution.
    """

    imWrk = m3D.image3DMb(imIn)
    se = m3D.structuringElement3D(m3D.getDirections3D(grid), grid)
    m3D.dilate3D(imWrk, imWrk, se=se, edge=mamba.FILLED)
    m3D.logic3D(imIn, imWrk, imWrk, "inf")
    build3D(imIn, imWrk, grid=grid)
    m3D.diff3D(imIn, imWrk, imOut)