Example #1
0
def whiteTopHat(imIn, imOut, n, se=mamba.DEFAULT_SE):
    """
    Performs a white Top Hat operation on 'imIn' and puts the result in 'imOut'.
    This operator extracts from 'imIn' the bright objects thinner than 2*'n'+1.

    The structuring element used is defined by 'se' ('DEFAULT_SE' by default).
    """
    
    imWrk = mamba.imageMb(imIn)
    mamba.opening(imIn, imWrk, n, se=se)
    mamba.sub(imIn, imWrk, imOut)
Example #2
0
def alternateFilter(imIn, imOut,n, openFirst, se=mamba.DEFAULT_SE):
    """
    Performs an alternate filter operation of size 'n' on image 'imIn' and puts
    the result in 'imOut'. If 'openFirst' is True, the filter begins with an
    opening, a closing otherwise.
    """
    
    if openFirst:
        mamba.opening(imIn, imOut, n, se=se)
        mamba.closing(imOut, imOut, n, se=se)
    else:
        mamba.closing(imIn, imOut, n, se=se)
        mamba.opening(imOut, imOut, n, se=se)
Example #3
0
def fullAlternateFilter(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.
    """
    
    mamba.copy(imIn, imOut)
    for i in range(1,n+1):
        if openFirst:
            mamba.opening(imOut, imOut, i, se=se)
            mamba.closing(imOut, imOut, i, se=se)
        else:
            mamba.closing(imOut, imOut, i, se=se)
            mamba.opening(imOut, imOut, i, se=se)
Example #4
0
def skeletonByOpening(imIn, imOut1, imOut2, grid=mamba.DEFAULT_GRID):
    """
    General skeleton by openings working on greytone image 'imIn'.
    'imOut1' contains the skeleton function and 'imOut2' contains the 
    associated function.
    
    This skeleton corresponds to the centers of maximal cylinders included
    in the set under the graph of the image 'imIn'.
    
    Depth of 'imOut1' is the same as 'imIn', depth of 'imOut2' is 32. 

    The edge is always set to 'FILLED'.
    """

    maskIm = mamba.imageMb(imIn, 1)
    imWrk1 = mamba.imageMb(imIn)
    imWrk2 = mamba.imageMb(imIn)
    imWrk3 = mamba.imageMb(imIn, 32)
    se = mamba.structuringElement(mamba.getDirections(grid), grid)
    i = 0
    mamba.copy(imIn, imWrk1)
    v2 = mamba.computeVolume(imWrk1)
    v1 = v2 + 1
    imOut1.reset()
    imOut2.reset()
    while v1 > v2:
        i += 1
        v1 = v2
        mamba.opening(imWrk1, imWrk2, se=se)
        mamba.sub(imWrk1, imWrk2, imWrk2)
        _generateMask_(imWrk2, imOut1, maskIm)
        mamba.convertByMask(maskIm, imWrk3, 0, i)
        mamba.logic(imOut1, imWrk2, imOut1, "sup")
        mamba.logic(imOut2, imWrk3, imOut2, "sup")
        mamba.erode(imWrk1, imWrk1, se=se)
        v2 = mamba.computeVolume(imWrk1)
Example #5
0
## DESCRIPTION #################################################################
# This example shows how a very simple transformation (opening here) can solve
# a problem of detection and counting of the teeth of a notched wheel when it is 
# associated to a preliminary selection of the zone where these teeth should be.

## SCRIPT ######################################################################
# Importing mamba
import mamba
import mambaDisplay

im = mamba.imageMb("wheel.png", 1)
im1 = mamba.imageMb(im, 1)
im2 = mamba.imageMb(im, 1)

# Opening of image
mamba.opening(im, im1, 3)
# Selection of the outside region
mamba.negate(im1, im2)
mamba.removeEdgeParticles(im2, im1)
mamba.diff(im2, im1, im2)
# Extracting the wheel teeth
mamba.logic(im, im2, im2, "inf")
# Cleaning the image
mamba.opening(im2, im2)
# Counting and marking each tooth
mamba.thinD(im2, im1)
nb_teeth = mamba.computeVolume(im1)
print("Number of teeth: %d" % (nb_teeth))
mamba.dilate(im1, im1, 3, mamba.SQUARE3X3)
im1.convert(8)
im8 = mamba.imageMb(im, 8)
Example #6
0
## DESCRIPTION #################################################################
# This example shows how a very simple transformation (opening here) can solve
# a problem of detection and counting of the teeth of a notched wheel when it is
# associated to a preliminary selection of the zone where these teeth should be.

## SCRIPT ######################################################################
# Importing mamba
import mamba
import mambaDisplay

im = mamba.imageMb("wheel.png", 1)
im1 = mamba.imageMb(im, 1)
im2 = mamba.imageMb(im, 1)

# Opening of image
mamba.opening(im, im1, 3)
# Selection of the outside region
mamba.negate(im1, im2)
mamba.removeEdgeParticles(im2, im1)
mamba.diff(im2, im1, im2)
# Extracting the wheel teeth
mamba.logic(im, im2, im2, "inf")
# Cleaning the image
mamba.opening(im2, im2)
# Counting and marking each tooth
mamba.thinD(im2, im1)
nb_teeth = mamba.computeVolume(im1)
print("Number of teeth: %d" % (nb_teeth))
mamba.dilate(im1, im1, 3, mamba.SQUARE3X3)
im1.convert(8)
im8 = mamba.imageMb(im, 8)