def mosaicGradient3D(imIn, imOut, grid=m3D.DEFAULT_GRID3D): """ Builds the mosaic-gradient 3D image of 'imIn' and puts the result in 'imOut'. The mosaic-gradient image is built by computing the differences of two mosaic images generated from 'imIn', the first one having its watershed lines valued by the suprema of the adjacent catchment basins values, the second one been valued by the infima. """ imWrk1 = m3D.image3DMb(imIn) imWrk2 = m3D.image3DMb(imIn) imWrk3 = m3D.image3DMb(imIn) imWrk4 = m3D.image3DMb(imIn) imWrk5 = m3D.image3DMb(imIn) mosaic3D(imIn, imWrk2, imWrk3, grid=grid) m3D.sub3D(imWrk2, imWrk3, imWrk1) m3D.logic3D(imWrk2, imWrk3, imWrk2, "sup") m3D.negate3D(imWrk2, imWrk2) se = m3D.structuringElement3D(m3D.getDirections3D(grid), grid) while m3D.computeVolume3D(imWrk3) != 0: m3D.dilate3D(imWrk1, imWrk4, 2, se=se) m3D.dilate3D(imWrk2, imWrk5, 2, se=se) m3D.logic3D(imWrk4, imWrk3, imWrk4, "inf") m3D.logic3D(imWrk5, imWrk3, imWrk5, "inf") m3D.logic3D(imWrk1, imWrk4, imWrk1, "sup") m3D.logic3D(imWrk2, imWrk5, imWrk2, "sup") m3D.erode3D(imWrk3, imWrk3, 2, se=se) m3D.negate3D(imWrk2, imWrk2) m3D.sub3D(imWrk1, imWrk2, imOut)
def supBlackTopHat3D(imIn, imOut, n, grid=m3D.DEFAULT_GRID3D): """ Performs a black Top Hat operation with the infimum of directional openings on 'imIn' and puts the result in 'imOut'. This operator partly extracts from 'imIn' the dark objects whose extension in at least one direction of 'grid' is smaller than 'n'. """ imWrk = m3D.image3DMb(imIn) m3D.infClose3D(imIn, imWrk, n, grid=grid) m3D.sub3D(imWrk, imIn, imOut)
def blackTopHat3D(imIn, imOut, n, se=m3D.CUBOCTAHEDRON1): """ Performs a black Top Hat operation on 'imIn' and puts the result in 'imOut'. This operator extracts from 'imIn' the dark objects thinner than 2*'n'+1. The structuring element used is defined by 'se' ('CUBOCTAHEDRON1' by default). """ imWrk = m3D.image3DMb(imIn) m3D.closing3D(imIn, imWrk, n, se=se) m3D.sub3D(imWrk, imIn, imOut)
def gradient3D(imIn, imOut, n=1, se=m3D.CUBOCTAHEDRON1): """ Computes the morphological gradient of 3D image 'imIn' and puts the result in 'imOut'. The thickness can be controlled using parameter 'n' (1 by default). The structuring element used by the erosion and dilation is defined by 'se' (CUBOCTAHEDRON1 by default). """ imWrk = m3D.image3DMb(imIn) m3D.erode3D(imIn, imWrk, n, se=se) m3D.dilate3D(imIn, imOut, n, se=se) m3D.sub3D(imOut, imWrk, imOut)
def maxima3D(imIn, imOut, h=1, grid=m3D.DEFAULT_GRID3D): """ Computes the maxima of 'imIn' using a build operation and puts the result in 'imOut'. 'h' can be used to define the maxima height. Grid used by the build operation can be specified by 'grid'. Only works with 8-bit or 32-bit as input. 'imOut' must be binary. """ imWrk = m3D.image3DMb(imIn) m3D.subConst3D(imIn, h, imWrk) m3D.build3D(imIn, imWrk, grid=grid) m3D.sub3D(imIn, imWrk, imWrk) m3D.threshold3D(imWrk, imOut, 1, mamba.computeMaxRange(imIn[0])[1])
def maxDynamics3D(imIn, imOut, h, grid=m3D.DEFAULT_GRID3D): """ Extracts the maxima of 'imIn' with a dynamics higher or equal to 'h' and puts the result in 'imOut'. Grid used by the dual build operation can be specified by 'grid'. Only works with 8-bit or 32-bit images as input. 'imOut' must be binary. """ imWrk = m3D.image3DMb(imIn) if imIn.getDepth() == 8: m3D.subConst3D(imIn, h, imWrk) m3D.build3D(imIn, imWrk, grid=grid) m3D.sub3D(imIn, imWrk, imWrk) else: m3D.floorSubConst3D(imIn, h, imWrk) m3D.build3D(imIn, imWrk, grid=grid) m3D.floorSub3D(imIn, imWrk, imWrk) m3D.threshold3D(imWrk, imOut, h, mamba.computeMaxRange(imIn[0])[1])
def halfGradient3D(imIn, imOut, type="intern", n=1, se=m3D.CUBOCTAHEDRON1): """ Computes the half morphological gradient of 3D image 'imIn' ond puts the result in 'imOut'. 'type' indicates if the half gradient should be internal or external. Possible values are : "extern" : dilation(imIn) - imIn "intern" : imIn - erosion(imIn) The thickness can be controlled using parameter 'n' (1 by default). The structuring element used by the erosion or the dilation is defined by 'se'. """ imWrk = m3D.image3DMb(imIn) if type=="extern": m3D.dilate3D(imIn, imWrk, n, se=se) m3D.sub3D(imWrk, imIn, imOut) else: m3D.erode3D(imIn, imWrk, n, se=se) m3D.sub3D(imIn, imWrk, imOut)