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 conjugateDirectionalErode(imIn, imOut, d, size, grid=mamba.DEFAULT_GRID, edge=mamba.FILLED): """ Performs the erosion 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 FILLED by default (can be changed). Note that this operator is not equivalent to successive erosions by a doublet of points. """ 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.linearErode(imWrk1, imWrk1, d, n=1, grid=grid, edge=edge) mamba.shift(imWrk1, imWrk1, j1, 1, val, grid=grid) mamba.logic(imWrk1, imOut, imWrk1, "inf") mamba.linearErode(imWrk2, imWrk2, j2, n=1, grid=grid, edge=edge) mamba.shift(imWrk2, imWrk2, j3, 1, val, grid=grid) mamba.logic(imWrk2, imOut, imWrk2, "inf") mamba.logic(imWrk1, imWrk2, imOut, "sup")
def rotate(self, step=1): """ Rotates the structuring element 'step' times. When step is positive, rotation is clockwise. When step is negative, rotation is counterclockwise. When step is equal to zero, there is no rotation. Example: >>>SEGMENT.getDirections() [0, 1] >>>SEGMENT.rotate().getDirections() [0, 2] """ ndirs = [ mamba.rotateDirection(u, step, self.grid) for u in self.directions ] o = structuringElement(ndirs, self.grid) return o