def computeConnectivityNumber(imIn, grid=mamba.DEFAULT_GRID): """ Computes the connectivity number (Euler_Poincare constant) of image 'ImIn'. The result is an integer number. Beware, if the input image 'imIn' is not a binary image, the function raises an error. """ if imIn.getDepth() != 1: mamba.raiseExceptionOnError(core.MB_ERR_BAD_DEPTH) imWrk = mamba.imageMb(imIn) if grid == mamba.HEXAGONAL: dse = mamba.doubleStructuringElement([1,6],[0],mamba.HEXAGONAL) mamba.hitOrMiss(imIn, imWrk, dse) n = mamba.computeVolume(imWrk) dse = mamba.doubleStructuringElement([1],[0,2],mamba.HEXAGONAL) mamba.hitOrMiss(imIn, imWrk, dse) n = n - mamba.computeVolume(imWrk) else: dse = mamba.doubleStructuringElement([3,4,5],[0],mamba.SQUARE) mamba.hitOrMiss(imIn, imWrk, dse) n = mamba.computeVolume(imWrk) dse = mamba.doubleStructuringElement([4],[0,3,5],mamba.SQUARE) mamba.hitOrMiss(imIn, imWrk, dse) n = n - mamba.computeVolume(imWrk) dse = mamba.doubleStructuringElement([3,5],[0,4],mamba.SQUARE) mamba.hitOrMiss(imIn, imWrk, dse) n = n + mamba.computeVolume(imWrk) return n
def computeConnectivityNumber(imIn, grid=mamba.DEFAULT_GRID): """ Computes the connectivity number (Euler_Poincare constant) of image 'ImIn'. The result is an integer number. Beware, if the input image 'imIn' is not a binary image, the function raises an error. """ if imIn.getDepth() != 1: mamba.raiseExceptionOnError(core.MB_ERR_BAD_DEPTH) imWrk = mamba.imageMb(imIn) if grid == mamba.HEXAGONAL: dse = mamba.doubleStructuringElement([1, 6], [0], mamba.HEXAGONAL) mamba.hitOrMiss(imIn, imWrk, dse) n = mamba.computeVolume(imWrk) dse = mamba.doubleStructuringElement([1], [0, 2], mamba.HEXAGONAL) mamba.hitOrMiss(imIn, imWrk, dse) n = n - mamba.computeVolume(imWrk) else: dse = mamba.doubleStructuringElement([3, 4, 5], [0], mamba.SQUARE) mamba.hitOrMiss(imIn, imWrk, dse) n = mamba.computeVolume(imWrk) dse = mamba.doubleStructuringElement([4], [0, 3, 5], mamba.SQUARE) mamba.hitOrMiss(imIn, imWrk, dse) n = n - mamba.computeVolume(imWrk) dse = mamba.doubleStructuringElement([3, 5], [0, 4], mamba.SQUARE) mamba.hitOrMiss(imIn, imWrk, dse) n = n + mamba.computeVolume(imWrk) return n
def neighborCounter(imIn, imOut, grid=mamba.DEFAULT_GRID): """ For each pixel set to true in the binary image 'imIn', this function counts its neighbor set to true and puts the result in 'imOut'. The neighbors are selected according to 'grid'. """ imWrk = mamba.imageMb(imIn) imOut.reset() for d in mamba.getDirections(grid)[1:]: dse = mamba.doubleStructuringElement([], [0, d], grid) mamba.hitOrMiss(imIn, imWrk, dse) mamba.add(imOut, imWrk, imOut)
def neighborCounter(imIn, imOut, grid=mamba.DEFAULT_GRID): """ For each pixel set to true in the binary image 'imIn', this function counts its neighbor set to true and puts the result in 'imOut'. The neighbors are selected according to 'grid'. """ imWrk = mamba.imageMb(imIn) imOut.reset() for d in mamba.getDirections(grid)[1:]: dse = mamba.doubleStructuringElement([],[0,d],grid) mamba.hitOrMiss(imIn, imWrk, dse) mamba.add(imOut, imWrk, imOut)