예제 #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 getHistogram3D(imIn):
    """
    Returns a list holding the histogram of the greyscale 3D image 'imIn'
    (0 to 255).
    """
    histo = 256 * [0]
    for im2D in imIn:
        hist_im = mamba.getHistogram(im2D)
        for i in range(256):
            histo[i] += hist_im[i]
    return histo
예제 #4
0
def getHistogram3D(imIn):
    """
    Returns a list holding the histogram of the greyscale 3D image 'imIn'
    (0 to 255).
    """
    histo = 256*[0]
    for im2D in imIn:
        hist_im = mamba.getHistogram(im2D)
        for i in range(256):
            histo[i] += hist_im[i]
    return histo
예제 #5
0
def getMean(imIn):
    """
    Returns the average value (float) of the pixels of 'imIn' (which must be a
    greyscale image).
    """

    histo = mamba.getHistogram(imIn)
    s = sum(histo)
    t = 0
    for i, v in enumerate(histo):
        t = t + i * v
    return float(t) / float(s)
예제 #6
0
def getMean(imIn):
    """
    Returns the average value (float) of the pixels of 'imIn' (which must be a
    greyscale image).
    """
    
    histo = mamba.getHistogram(imIn)
    s = sum(histo)
    t = 0
    for i,v in enumerate(histo):
        t = t + i*v
    return float(t)/float(s)
예제 #7
0
def getVariance(imIn):
    """
    Returns the pixels variance (estimator without bias) of image 'imIn' (which 
    must be a greyscale image)..
    """

    mean = getMean(imIn)
    histo = mamba.getHistogram(imIn)
    s = sum(histo)
    t = 0
    for i, v in enumerate(histo):
        t = t + v * (i - mean) * (i - mean)
    return t / (s - 1)
예제 #8
0
def getVariance(imIn):
    """
    Returns the pixels variance (estimator without bias) of image 'imIn' (which 
    must be a greyscale image)..
    """
    
    mean = getMean(imIn)
    histo = mamba.getHistogram(imIn)
    s = sum(histo)
    t = 0
    for i,v in enumerate(histo):
        t = t+v*(i-mean)*(i-mean)
    return t/(s-1)
예제 #9
0
def getMedian(imIn):
    """
    Returns the median value of the pixels of 'imIn'.

    The median value is defined as the first pixel value for which at least
    half of the pixels are below it. 
    
    'imIn' must be a greyscale image.
    """

    histo = mamba.getHistogram(imIn)
    s = sum(histo)
    t = 0
    for i, v in enumerate(histo):
        t = t + v
        if t > s // 2:
            break
    return i
예제 #10
0
def getMedian(imIn):
    """
    Returns the median value of the pixels of 'imIn'.

    The median value is defined as the first pixel value for which at least
    half of the pixels are below it. 
    
    'imIn' must be a greyscale image.
    """
    
    histo = mamba.getHistogram(imIn)
    s = sum(histo)
    t = 0
    for i,v in enumerate(histo):
        t = t+v
        if t>s//2:
            break
    return i