def fullBuildAlternateFilter(imIn, imOut, n, openFirst, se=mamba.DEFAULT_SE): """ Performs a full alternate filter operation (successive alternate filters of increasing sizes, from 1 to 'n') on image 'imIn' and puts the result in 'imOut'. 'n' controls the filter size. If 'openFirst' is True, the filter begins with an opening, a closing otherwise. This operator uses the buildOpen and buildClose operators instead of the classic open and close. """ mamba.copy(imIn, imOut) for i in range(1,n+1): if openFirst: mamba.buildOpen(imOut, imOut, i, se=se) mamba.buildClose(imOut, imOut, i, se=se) else: mamba.buildClose(imOut, imOut, i, se=se) mamba.buildOpen(imOut, imOut, i, se=se)
def fullBuildAlternateFilter(imIn, imOut, n, openFirst, se=mamba.DEFAULT_SE): """ Performs a full alternate filter operation (successive alternate filters of increasing sizes, from 1 to 'n') on image 'imIn' and puts the result in 'imOut'. 'n' controls the filter size. If 'openFirst' is True, the filter begins with an opening, a closing otherwise. This operator uses the buildOpen and buildClose operators instead of the classic open and close. """ mamba.copy(imIn, imOut) for i in range(1, n + 1): if openFirst: mamba.buildOpen(imOut, imOut, i, se=se) mamba.buildClose(imOut, imOut, i, se=se) else: mamba.buildClose(imOut, imOut, i, se=se) mamba.buildOpen(imOut, imOut, i, se=se)
d = i + 1 linearUltimateOpen(imIn, imWrk2, d, grid=grid) mamba.generateSupMask(imWrk2, imWrk1, imWrk3, True) mamba.logic(imWrk2, imWrk1, imWrk1, "sup") mamba.convertByMask(imWrk3, imWrk4, 0, d) mamba.logic(imWrk4, imOut, imOut, "sup") # Trying these operators on a fiber image. # Loading the initial image. im1 = mamba.imageMb('fiber.png') # Defining some working images. im2 = mamba.imageMb(im1) imbin1 = mamba.imageMb(im1, 1) # A binary image is defined by a top-hat operator, followed by # a thresholding and a filtering. mamba.blackTopHat(im1, im2, 10) mamba.threshold(im2, imbin1, 50, 255) mamba.buildClose(imbin1, imbin1, 2) # The directions encoding is performed. directionalCoding(imbin1, im2) # A palette for displaying the 6 possible directions is defined. dirpal = (0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 0, 0, 255, 255, 255, 0, 255) for i in range(249): dirpal = dirpal + (0, 0, 0) # The result is saved with the palette. im2.save('coded_directions.png', palette=dirpal)
imWrk1.reset() for i in range(mamba.gridNeighbors(grid=grid)): d = i + 1 linearUltimateOpen(imIn, imWrk2, d, grid=grid) mamba.generateSupMask(imWrk2, imWrk1, imWrk3, True) mamba.logic(imWrk2, imWrk1, imWrk1, "sup") mamba.convertByMask(imWrk3, imWrk4, 0, d) mamba.logic(imWrk4, imOut, imOut, "sup") # Trying these operators on a fiber image. # Loading the initial image. im1 = mamba.imageMb('fiber.png') # Defining some working images. im2 = mamba.imageMb(im1) imbin1 = mamba.imageMb(im1, 1) # A binary image is defined by a top-hat operator, followed by # a thresholding and a filtering. mamba.blackTopHat(im1, im2, 10) mamba.threshold(im2, imbin1, 50, 255) mamba.buildClose(imbin1, imbin1, 2) # The directions encoding is performed. directionalCoding(imbin1, im2) # A palette for displaying the 6 possible directions is defined. dirpal = (0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 0, 0, 255, 255, 255, 0, 255) for i in range(249): dirpal = dirpal + (0, 0, 0) # The result is saved with the palette. im2.save('coded_directions.png', palette=dirpal)