def conjugateDirectionalDilate(imIn, imOut, d, size, grid=mamba.DEFAULT_GRID, edge=mamba.EMPTY): """ Performs the dilation of image 'imIn' in the conjugate direction 'd' of the grid and puts the result in image 'imOut'. The images can be binary, greyscale or 32-bit images. 'size' is a multiple of the distance between two adjacent points in the conjugate directions. 'edge' is set to EMPTY by default (can be changed). Note that the linear structuring element is not connected. Points connecting adjacent points in the conjugate directions are not present. This is normal if we want to insure that the result is identical when we iterate n size 1 operations to get a size n one (the same remark applies to the erosion). """ imWrk1 = mamba.imageMb(imIn) imWrk2 = mamba.imageMb(imIn) mamba.copy(imIn, imOut) j3 = mamba.transposeDirection(d, grid=grid) j2 = mamba.rotateDirection(d, grid=grid) j1 = mamba.transposeDirection(j2, grid=grid) val = mamba.computeMaxRange(imIn)[1] * int(edge == mamba.FILLED) for i in range(size): mamba.copy(imOut, imWrk1) mamba.copy(imOut, imWrk2) mamba.linearDilate(imWrk1, imWrk1, d, 1, grid=grid, edge=edge) mamba.shift(imWrk1, imWrk1, j1, 1, val, grid=grid) mamba.logic(imWrk1, imOut, imWrk1, "sup") mamba.linearDilate(imWrk2, imWrk2, j2, 1, grid=grid, edge=edge) mamba.shift(imWrk2, imWrk2, j3, 1, val, grid=grid) mamba.logic(imWrk2, imOut, imWrk2, "sup") mamba.logic(imWrk1, imWrk2, imOut, "inf")
def cellsBuild(imIn, imInOut, grid=mamba.DEFAULT_GRID): """ Geodesic reconstruction of the cells of the partition image 'imIn' which are marked by the image 'imInOut'. The marked cells take the value of their corresponding marker. Note that the background cells (labelled by 0) are also modified if they are marked. The result is stored in 'imInOut'. The images can be 8-bit or 32-bit images. 'grid' can be set to HEXAGONAL or SQUARE. """ imWrk1 = mamba.imageMb(imIn) imWrk2 = mamba.imageMb(imIn) imWrk3 = mamba.imageMb(imIn, 1) vol = 0 prec_vol = -1 dirs = mamba.getDirections(grid)[1:] while (prec_vol!=vol): prec_vol = vol for d in dirs: ed = 1<<d mamba.copy(imIn, imWrk1) mamba.copy(imIn, imWrk2) mamba.supNeighbor(imWrk1, imWrk1, ed, grid=grid) mamba.infNeighbor(imWrk2, imWrk2, ed, grid=grid) mamba.generateSupMask(imWrk2, imWrk1, imWrk3, False) mamba.convertByMask(imWrk3, imWrk1, 0, mamba.computeMaxRange(imIn)[1]) mamba.linearDilate(imInOut, imWrk2, d, 1, grid=grid) mamba.logic(imWrk2, imWrk1, imWrk2, "inf") v = mamba.buildNeighbor(imWrk1, imWrk2, d, grid=grid) mamba.logic(imWrk2, imInOut, imInOut, "sup") vol = mamba.computeVolume(imInOut)
def directionalDilate(imIn, imOut, d, size, grid=mamba.DEFAULT_GRID, edge=mamba.EMPTY): """ General directional dilation of image 'imIn', result in 'imOut'. The images can have any format. The direction 'd' is coded clockwise from 1 to 12 or 16. Direction 1 corresponds to 60 degrees on the hexagonal grid and 90 degrees on the square grid. 'size' corresponds to twice the normal size when standard directions are used. 'edge' is set to EMPTY by default. """ if (d & 1) == 0: conjugateDirectionalDilate(imIn, imOut, d / 2, size, grid=grid, edge=edge) else: mamba.linearDilate(imIn, imOut, (d + 1) / 2, size * 2, grid=grid, edge=edge)
def cellsBuild(imIn, imInOut, grid=mamba.DEFAULT_GRID): """ Geodesic reconstruction of the cells of the partition image 'imIn' which are marked by the image 'imInOut'. The marked cells take the value of their corresponding marker. Note that the background cells (labelled by 0) are also modified if they are marked. The result is stored in 'imInOut'. The images can be 8-bit or 32-bit images. 'grid' can be set to HEXAGONAL or SQUARE. """ imWrk1 = mamba.imageMb(imIn) imWrk2 = mamba.imageMb(imIn) imWrk3 = mamba.imageMb(imIn, 1) vol = 0 prec_vol = -1 dirs = mamba.getDirections(grid)[1:] while (prec_vol != vol): prec_vol = vol for d in dirs: ed = 1 << d mamba.copy(imIn, imWrk1) mamba.copy(imIn, imWrk2) mamba.supNeighbor(imWrk1, imWrk1, ed, grid=grid) mamba.infNeighbor(imWrk2, imWrk2, ed, grid=grid) mamba.generateSupMask(imWrk2, imWrk1, imWrk3, False) mamba.convertByMask(imWrk3, imWrk1, 0, mamba.computeMaxRange(imIn)[1]) mamba.linearDilate(imInOut, imWrk2, d, 1, grid=grid) mamba.logic(imWrk2, imWrk1, imWrk2, "inf") v = mamba.buildNeighbor(imWrk1, imWrk2, d, grid=grid) mamba.logic(imWrk2, imInOut, imInOut, "sup") vol = mamba.computeVolume(imInOut)
def linearOpen(imIn, imOut, dir, n, grid=mamba.DEFAULT_GRID, edge=mamba.FILLED): """ Performs an opening by a segment of size 'n' in direction 'dir'. 'edge' is set to 'FILLED' by default. """ mamba.linearErode(imIn, imOut, dir, n, edge=edge, grid=grid) mamba.linearDilate(imOut, imOut, mamba.transposeDirection(dir, grid=grid), n, grid=grid)
def linearClose(imIn, imOut, dir, n, grid=mamba.DEFAULT_GRID, edge=mamba.FILLED): """ Performs a closing by a segment of size 'n' in direction 'dir'. If 'edge' is set to 'EMPTY', the operation must be modified to remain extensive. """ imWrk = mamba.imageMb(imIn) if edge==mamba.EMPTY: mamba.copy(imIn, imWrk) mamba.linearDilate(imIn, imOut, dir, n, grid=grid) mamba.linearErode(imOut, imOut, mamba.transposeDirection(dir, grid=grid), n, edge=edge, grid=grid) if edge==mamba.EMPTY: mamba.logic(imOut, imWrk, imOut, "sup")
def linearClose(imIn, imOut, dir, n, grid=mamba.DEFAULT_GRID, edge=mamba.FILLED): """ Performs a closing by a segment of size 'n' in direction 'dir'. If 'edge' is set to 'EMPTY', the operation must be modified to remain extensive. """ imWrk = mamba.imageMb(imIn) if edge == mamba.EMPTY: mamba.copy(imIn, imWrk) mamba.linearDilate(imIn, imOut, dir, n, grid=grid) mamba.linearErode(imOut, imOut, mamba.transposeDirection(dir, grid=grid), n, edge=edge, grid=grid) if edge == mamba.EMPTY: mamba.logic(imOut, imWrk, imOut, "sup")