def mosaic3D(imIn, imOut, imWts, grid=m3D.DEFAULT_GRID3D): """ Builds the mosaic 3D image of 'imIn' and puts the results into 'imOut'. The watershed line (pixel values set to 255) is stored in the greytone 3D image 'imWts'. A mosaic image is a simple image made of various tiles of uniform grey values. It is built using the watershed of 'imIn' gradient and original markers made of gradient minima which are labelled by the maximum value of 'imIn' pixels inside them. """ imWrk1 = m3D.image3DMb(imIn, 1) imWrk2 = m3D.image3DMb(imIn) m3D.copy3D(imIn, imWrk2) im_mark = m3D.image3DMb(imIn, 32) se = m3D.structuringElement3D(m3D.getDirections3D(grid), grid) m3D.gradient3D(imIn, imOut, se=se) m3D.minima3D(imOut, imWrk1, grid=grid) m3D.add3D(im_mark, imWrk1, im_mark) imWrk1.convert(8) m3D.build3D(imWrk1, imWrk2, grid=grid) m3D.add3D(im_mark, imWrk2, im_mark) m3D.watershedSegment3D(imOut, im_mark, grid=grid) m3D.copyBytePlane3D(im_mark, 3, imWts) m3D.subConst3D(im_mark, 1, im_mark) m3D.copyBytePlane3D(im_mark, 0, imOut)
def buildOpen3D(imIn, imOut, n=1, se=m3D.CUBOCTAHEDRON1): """ Performs an opening by reconstruction operation on 3D image 'imIn' and puts the result in 'imOut'. 'n' controls the size of the opening. """ imWrk = m3D.image3DMb(imIn) m3D.copy3D(imIn, imWrk) m3D.erode3D(imIn, imOut, n, se=se) m3D.build3D(imWrk, imOut, grid=se.getGrid())
def maxPartialBuild3D(imIn, imMask, imOut, grid=m3D.DEFAULT_GRID3D): """ Performs the partial reconstruction of 'imIn' with its maxima 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) maxima3D(imIn, imWrk, 1, grid=grid) m3D.logic3D(imMask, imWrk, imWrk, "inf") m3D.convertByMask3D(imWrk, imOut, 0, mamba.computeMaxRange(imIn[0])[1]) m3D.logic3D(imIn, imOut, imOut, "inf") m3D.build3D(imIn, 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 highMaxima3D(imIn, imOut, h, grid=m3D.DEFAULT_GRID3D): """ Computes the maxima of the reconstruction of image 'imIn' by imIn - h and puts the result in 'imOut'. Grid used by the 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) else: m3D.floorSubConst3D(imIn, h, imWrk) m3D.build3D(imIn, imWrk, grid=grid) m3D.maxima3D(imWrk, imOut, 1, grid=grid)
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 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")
def strongLevelling3D(imIn, imOut, n, eroFirst, grid=m3D.DEFAULT_GRID3D): """ Strong levelling of 'imIn', result in 'imOut'. 'n' defines the size of the erosion and dilation of 'imIn' in the operation. If 'eroFirst' is true, the operation starts with an erosion, it starts with a dilation otherwise. This filter is stronger (more efficient) that simpleLevelling3D. However, the order of the initial operations (erosion and dilation) matters. """ imWrk = m3D.image3DMb(imIn) se = m3D.structuringElement3D(m3D.getDirections3D(grid), grid) if eroFirst: m3D.erode3D(imIn, imWrk, n, se=se) m3D.build3D(imIn, imWrk, grid=grid) m3D.dilate3D(imIn, imOut, n, se=se) m3D.dualBuild3D(imWrk, imOut, grid=grid) else: m3D.dilate3D(imIn, imWrk, n, se=se) m3D.dualBuild3D(imIn, imWrk, grid=grid) m3D.erode3D(imIn, imOut, n, se=se) m3D.build3D(imWrk, imOut, grid=grid)