예제 #1
0
def measureLabelling(imIn, imMeasure, imOut):
    """
    Labelling each particle of the binary image or each cell of the partition 'imIn'
    with the number of pixels in the binary image 'imMeasure' contained in each particle
    or each cell of the partition. The result is put is the 32-bit image 'imOut'.
    """
    
    imWrk1 = mamba.imageMb(imIn, 32)
    imWrk2 = mamba.imageMb(imIn, 1)
    imWrk3 = mamba.imageMb(imIn, 8)
    imWrk4 = mamba.imageMb(imIn, 8)
    imWrk5 = mamba.imageMb(imIn, 8)
    imWrk6 = mamba.imageMb(imIn, 32)
    
    # Output image is emptied.
    imOut.reset()
    # Labelling the initial image.
    if imIn.getDepth() == 1:
        nbParticles = mamba.label(imIn, imWrk1)
    else:
        nbParticles = partitionLabel(imIn, imWrk1)
    # Defining output LUTs.
    outLuts = [[0 for i in range(256)] for i in range(4)]
    # Converting the imMeasure image to 8-bit.
    mamba.convert(imMeasure, imWrk4)
    while nbParticles > 0:
        # Particles with labels between 1 and 255 are extracted.
        mamba.threshold(imWrk1, imWrk2, 0, 255)
        mamba.convert(imWrk2, imWrk3)
        mamba.copyBytePlane(imWrk1, 0, imWrk5)
        mamba.logic(imWrk3, imWrk5, imWrk3, "inf")
        # The points contained in each particle are labelled.
        mamba.logic(imWrk3, imWrk4, imWrk5, "inf")
        # The histogram is computed.
        histo = mamba.getHistogram(imWrk5)
        # The same operation is performed for the 255 particles. 
        for i in range(1, 256):
            # The number of points in each particle is obtained from the histogram.
            value = histo[i]
            j = 3
            # This value is splitted in powers of 256 and stored in the four 
            # output LUTs.
            while j >= 0:
                n = 2 ** (8 * j)
                outLuts[j][i] = value // n
                value = value % n
                j -= 1
        # Each LUT is used to label each byte plane of a temporary image with the
        # corresponding value.
        for i in range(4):
            mamba.lookup(imWrk3, imWrk5, outLuts[i])
            mamba.copyBytePlane(imWrk5, i, imWrk6)
        # The intermediary result is accumulated in the final image.
        mamba.logic(imOut, imWrk6, imOut, "sup")
        # 255 is subtracted from the initial labelled image in order to process
        # the next 255 particles.
        mamba.floorSubConst(imWrk1, 255, imWrk1)
        nbParticles -= 255
예제 #2
0
def measureLabelling(imIn, imMeasure, imOut):
    """
    Labelling each particle of the binary image or each cell of the partition 'imIn'
    with the number of pixels in the binary image 'imMeasure' contained in each particle
    or each cell of the partition. The result is put is the 32-bit image 'imOut'.
    """

    imWrk1 = mamba.imageMb(imIn, 32)
    imWrk2 = mamba.imageMb(imIn, 1)
    imWrk3 = mamba.imageMb(imIn, 8)
    imWrk4 = mamba.imageMb(imIn, 8)
    imWrk5 = mamba.imageMb(imIn, 8)
    imWrk6 = mamba.imageMb(imIn, 32)

    # Output image is emptied.
    imOut.reset()
    # Labelling the initial image.
    if imIn.getDepth() == 1:
        nbParticles = mamba.label(imIn, imWrk1)
    else:
        nbParticles = partitionLabel(imIn, imWrk1)
    # Defining output LUTs.
    outLuts = [[0 for i in range(256)] for i in range(4)]
    # Converting the imMeasure image to 8-bit.
    mamba.convert(imMeasure, imWrk4)
    while nbParticles > 0:
        # Particles with labels between 1 and 255 are extracted.
        mamba.threshold(imWrk1, imWrk2, 0, 255)
        mamba.convert(imWrk2, imWrk3)
        mamba.copyBytePlane(imWrk1, 0, imWrk5)
        mamba.logic(imWrk3, imWrk5, imWrk3, "inf")
        # The points contained in each particle are labelled.
        mamba.logic(imWrk3, imWrk4, imWrk5, "inf")
        # The histogram is computed.
        histo = mamba.getHistogram(imWrk5)
        # The same operation is performed for the 255 particles.
        for i in range(1, 256):
            # The number of points in each particle is obtained from the histogram.
            value = histo[i]
            j = 3
            # This value is splitted in powers of 256 and stored in the four
            # output LUTs.
            while j >= 0:
                n = 2**(8 * j)
                outLuts[j][i] = value // n
                value = value % n
                j -= 1
        # Each LUT is used to label each byte plane of a temporary image with the
        # corresponding value.
        for i in range(4):
            mamba.lookup(imWrk3, imWrk5, outLuts[i])
            mamba.copyBytePlane(imWrk5, i, imWrk6)
        # The intermediary result is accumulated in the final image.
        mamba.logic(imOut, imWrk6, imOut, "sup")
        # 255 is subtracted from the initial labelled image in order to process
        # the next 255 particles.
        mamba.floorSubConst(imWrk1, 255, imWrk1)
        nbParticles -= 255
예제 #3
0
def lookup3D(imIn, imOut, lutable):
    """
    Converts the greyscale 3D image 'imIn' using the look-up table 'lutable'
    and puts the result in greyscale 3D image 'imOut'.
    
    'lutable' is a list containing 256 values with the first one corresponding 
    to 0 and the last one to 255.
    """
    outl = len(imOut)
    inl = len(imIn)
    if inl != outl:
        mamba.raiseExceptionOnError(core.MB_ERR_BAD_SIZE)

    for i in range(outl):
        mamba.lookup(imIn[i], imOut[i], lutable)
예제 #4
0
def lookup3D(imIn, imOut, lutable):
    """
    Converts the greyscale 3D image 'imIn' using the look-up table 'lutable'
    and puts the result in greyscale 3D image 'imOut'.
    
    'lutable' is a list containing 256 values with the first one corresponding 
    to 0 and the last one to 255.
    """
    outl = len(imOut)
    inl = len(imIn)
    if inl!=outl:
        mamba.raiseExceptionOnError(core.MB_ERR_BAD_SIZE)
    
    for i in range(outl):
        mamba.lookup(imIn[i], imOut[i], lutable)