예제 #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")
예제 #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")
예제 #3
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")
예제 #4
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")
예제 #5
0
def fastSKIZ3D(imIn, imOut, grid=m3D.DEFAULT_GRID3D):
    """
    Fast skeleton by zones of influence of binary 3D image 'imIn'. Result is
    put in binary 3D image 'imOut'. The transformation is faster as it uses
    the watershed transform by hierarchical queues.
    """

    imWrk = m3D.image3DMb(imIn, 8)
    m3D.convertByMask3D(imIn, imWrk, 1, 0)
    markerControlledWatershed3D(imWrk, imIn, imWrk, grid=grid)
    m3D.threshold3D(imWrk, imOut, 0, 0)
예제 #6
0
def fastSKIZ3D(imIn, imOut, grid=m3D.DEFAULT_GRID3D):
    """
    Fast skeleton by zones of influence of binary 3D image 'imIn'. Result is
    put in binary 3D image 'imOut'. The transformation is faster as it uses
    the watershed transform by hierarchical queues.
    """
    
    imWrk = m3D.image3DMb(imIn, 8)
    m3D.convertByMask3D(imIn, imWrk, 1, 0)
    markerControlledWatershed3D(imWrk, imIn, imWrk, grid=grid)
    m3D.threshold3D(imWrk, imOut, 0, 0)
예제 #7
0
def minPartialBuild3D(imIn, imMask, imOut, grid=m3D.DEFAULT_GRID3D):
    """
    Performs the partial reconstruction of 'imIn' with its minima which are
    contained in the binary mask 'imMask'. The result is put in 'imOut'.
    
    'imIn' and 'imOut' must be different and greyscale images.
    """
    
    imWrk = m3D.image3DMb(imIn, 1)
    minima3D(imIn, imWrk, 1, grid=grid)
    m3D.logic3D(imMask, imWrk, imWrk, "inf")
    m3D.convertByMask3D(imWrk, imOut, mamba.computeMaxRange(imIn[0])[1], 0)
    m3D.logic3D(imIn, imOut, imOut, "sup")
    m3D.dualBuild3D(imIn, imOut)
예제 #8
0
def minPartialBuild3D(imIn, imMask, imOut, grid=m3D.DEFAULT_GRID3D):
    """
    Performs the partial reconstruction of 'imIn' with its minima which are
    contained in the binary mask 'imMask'. The result is put in 'imOut'.
    
    'imIn' and 'imOut' must be different and greyscale images.
    """

    imWrk = m3D.image3DMb(imIn, 1)
    minima3D(imIn, imWrk, 1, grid=grid)
    m3D.logic3D(imMask, imWrk, imWrk, "inf")
    m3D.convertByMask3D(imWrk, imOut, mamba.computeMaxRange(imIn[0])[1], 0)
    m3D.logic3D(imIn, imOut, imOut, "sup")
    m3D.dualBuild3D(imIn, imOut)
예제 #9
0
def simpleLevelling3D(imIn, imMask, imOut, grid=m3D.DEFAULT_GRID3D):
    """
    Performs a simple levelling of 3D image 'imIn' controlled by image 'imMask'
    and puts the result in 'imOut'. This operation is composed of two
    geodesic reconstructions. This filter tends to level regions in the 
    image of homogeneous grey values.
    """

    imWrk1 = m3D.image3DMb(imIn)
    imWrk2 = m3D.image3DMb(imIn)
    mask_im = m3D.image3DMb(imIn, 1)
    m3D.logic3D(imIn, imMask, imWrk1, "inf")
    m3D.build3D(imIn, imWrk1, grid=grid)
    m3D.logic3D(imIn, imMask, imWrk2, "sup")
    m3D.dualBuild3D(imIn, imWrk2, grid=grid)
    m3D.generateSupMask3D(imIn, imMask, mask_im, False)
    m3D.convertByMask3D(mask_im, imOut, 0, m3D.computeMaxRange3D(imIn)[1])
    m3D.logic3D(imOut, imWrk1, imWrk1, "inf")
    m3D.negate3D(imOut, imOut)
    m3D.logic3D(imOut, imWrk2, imOut, "inf")
    m3D.logic3D(imWrk1, imOut, imOut, "sup")
예제 #10
0
def simpleLevelling3D(imIn, imMask, imOut, grid=m3D.DEFAULT_GRID3D):
    """
    Performs a simple levelling of 3D image 'imIn' controlled by image 'imMask'
    and puts the result in 'imOut'. This operation is composed of two
    geodesic reconstructions. This filter tends to level regions in the 
    image of homogeneous grey values.
    """
    
    imWrk1 = m3D.image3DMb(imIn)
    imWrk2 = m3D.image3DMb(imIn)
    mask_im = m3D.image3DMb(imIn, 1)
    m3D.logic3D(imIn, imMask, imWrk1, "inf")
    m3D.build3D(imIn, imWrk1, grid=grid)
    m3D.logic3D(imIn, imMask, imWrk2, "sup")
    m3D.dualBuild3D(imIn, imWrk2, grid=grid)
    m3D.generateSupMask3D(imIn, imMask, mask_im, False)
    m3D.convertByMask3D(mask_im, imOut, 0, m3D.computeMaxRange3D(imIn)[1])
    m3D.logic3D(imOut, imWrk1, imWrk1, "inf")
    m3D.negate3D(imOut, imOut)
    m3D.logic3D(imOut, imWrk2, imOut, "inf")
    m3D.logic3D(imWrk1, imOut, imOut, "sup")