def ModalValue(image):
    """look for the modal value of an image"""
    # print image.dtype
    if image.dtype == "uint8":
        depthmax = 255
        print "8bits"
    if image.dtype == "uint16":
        depthmax = 65535
        print "16bits"
    histo = mahotas.fullhistogram(image)
    countmax = histo.max()
    print "countmax:", countmax
    print "image max", image.max()
    mig = image.min()  # image min graylevel
    mag = image.max()  # image max gray level
    mode = 0
    countmax = 0  # occurence of a given grayscale
    print "mig=", mig, "  mag=", mag
    for i in range(mig, mag - 1, 1):
        test = histo[i] > countmax
        # print "test:",test,"histo(",i,")=", histo[i],"max",countmax
        if test:
            countmax = histo[i]
            mode = i
            # print "mode",mode
    return mode
Пример #2
0
def ModalValue(image):
    '''look for the modal value of an image'''
    #print image.dtype
    if image.dtype=="uint8":
        depthmax=255
        print "8bits"
    if image.dtype=="uint16":
        depthmax=65535
        print "16bits"
    histo=mahotas.fullhistogram(image)
    countmax=histo.max()
    print "countmax:",countmax
    print "image max",image.max()
    mig=image.min()#image min graylevel
    mag=image.max()#image max gray level
    mode=0
    countmax=0#occurence of a given grayscale
    print "mig=",mig,"  mag=",mag
    for i in range(mig,mag-1,1):
        test=histo[i]>countmax
        #print "test:",test,"histo(",i,")=", histo[i],"max",countmax
        if  test:
            countmax=histo[i]
            mode=i
            #print "mode",mode
    return mode
Пример #3
0
def perimeter(bwimage, n=4, mode="constant"):
    """
    p = perimeter(bwimage, n=4, mode="constant")

    Calculate total perimeter of all objects in binary image.

    Parameters
    ----------
    bwimage : array
        binary image
    n : int, optional
        passed to ``bwperim`` as is
    mode : str, optional
        passed to ``bwperim`` as is

    Returns
    -------
    p : float
        total perimeter of all objects in binary image

    See Also
    --------
    bwperim : function
        Finds the perimeter region

    References
    ----------
    .. [1] K. Benkrid, D. Crookes. Design and FPGA Implementation of
           a Perimeter Estimator. The Queen's University of Belfast.
           http://www.cs.qub.ac.uk/~d.crookes/webpubs/papers/perimeter.doc
    """
    global _perimeter_values
    perim = bwperim(bwimage, n, mode)
    perim = perim.astype(np.uint8)

    histogram = mh.fullhistogram(
                    mh.convolve(perim, _perimeter_magic))

    if _perimeter_values is None:
        _perimeter_values = np.zeros(34, float)
        _perimeter_values[[5, 7, 15, 17, 25, 27]] = 1
        _perimeter_values[[21, 33]] = np.sqrt(2)
        _perimeter_values[[13, 23]] = (1 + np.sqrt(2)) / 2

    size = min(34, len(histogram))
    return np.dot(histogram[:size], _perimeter_values[:size])
Пример #4
0
def perimeter(bwimage, n=4, mode="constant"):
    """
    p = perimeter(bwimage, n=4, mode="constant")

    Calculate total perimeter of all objects in binary image.

    Parameters
    ----------
    bwimage : array
        binary image
    n : int, optional
        passed to ``bwperim`` as is
    mode : str, optional
        passed to ``bwperim`` as is

    Returns
    -------
    p : float
        total perimeter of all objects in binary image

    See Also
    --------
    bwperim : function
        Finds the perimeter region

    References
    ----------
    .. [1] K. Benkrid, D. Crookes. Design and FPGA Implementation of
           a Perimeter Estimator. The Queen's University of Belfast.
           http://www.cs.qub.ac.uk/~d.crookes/webpubs/papers/perimeter.doc
    """
    global _perimeter_values
    perim = bwperim(bwimage, n, mode)
    perim = perim.astype(np.uint8)

    histogram = mh.fullhistogram(
                    mh.convolve(perim, _perimeter_magic))

    if _perimeter_values is None:
        _perimeter_values = np.zeros(34, float)
        _perimeter_values[[5, 7, 15, 17, 25, 27]] = 1
        _perimeter_values[[21, 33]] = np.sqrt(2)
        _perimeter_values[[13, 23]] = (1 + np.sqrt(2)) / 2

    size = min(34, len(histogram))
    return np.dot(histogram[:size], _perimeter_values[:size])
Пример #5
0
 def get_histogram(array):
     '''
 '''
     return mh.fullhistogram(array)
Пример #6
0
 def get_histogram(array):
     '''
 '''
     return mh.fullhistogram(array.astype(np.uint64))