示例#1
0
def gbernsen(f, se, contrast_threshold, gthresh):
    '''
    thresholded = gbernsen(f, se, contrast_threshold, gthresh)

    Generalised Bernsen local thresholding

    Parameters
    ----------
    f : ndarray
        input image
    se : boolean ndarray
        structuring element to use for "locality"
    contrast_threshold : integer
        contrast threshold
    gthresh : numeric, optional
        global threshold to fall back in low contrast regions

    Returns
    -------
    thresholded : binary ndarray

    See Also
    --------
    bernsen : function
        Bernsen thresholding with a circular region
    '''
    from mahotas.convolve import rank_filter
    fmax = rank_filter(f, se, se.sum()-1)
    fmin = rank_filter(f, se, 0)
    fptp = fmax - fmin
    fmean = fmax/2. + fmin/2. # Do not use (fmax + fmin) as that may overflow
    return np.choose(fptp < contrast_threshold, (fmean < gthresh, fmean > f))
示例#2
0
def gbernsen(f, se, contrast_threshold, gthresh):
    '''
    thresholded = gbernsen(f, se, contrast_threshold, gthresh)

    Generalised Bernsen local thresholding

    Parameters
    ----------
    f : ndarray
        input image
    se : boolean ndarray
        structuring element to use for "locality"
    contrast_threshold : integer
        contrast threshold
    gthresh : numeric, optional
        global threshold to fall back in low contrast regions

    Returns
    -------
    thresholded : binary ndarray

    See Also
    --------
    bernsen : function
        Bernsen thresholding with a circular region
    '''
    from mahotas.convolve import rank_filter
    fmax = rank_filter(f, se, se.sum() - 1)
    fmin = rank_filter(f, se, 0)
    fptp = fmax - fmin
    fmean = fmax / 2. + fmin / 2.  # Do not use (fmax + fmin) as that may overflow
    return np.choose(fptp < contrast_threshold, (fmean < gthresh, fmean > f))
示例#3
0
def test_rank_filter():
    np.random.seed(22)
    A = np.random.random_integers(0,255, (32,32))
    Bc = np.ones((3,3))
    for r in xrange(9):
        B1 = rank_filter(A,Bc,r)
        B2 = _slow_rank_filter(A,r)
        assert np.all(B1[1:-1,1:-1] == B2)
示例#4
0
def test_rank_filter():
    np.random.seed(22)
    A = np.random.randint(0, 256, (32, 32))
    Bc = np.ones((3, 3))
    for r in range(9):
        B1 = rank_filter(A, Bc, r, mode='constant')
        B2 = _slow_rank_filter(A, r)
        assert np.all(B1 == B2)
示例#5
0
def test_rank_filter():
    np.random.seed(22)
    A = np.random.random_integers(0,255, (32,32))
    Bc = np.ones((3,3))
    for r in range(9):
        B1 = rank_filter(A, Bc, r, mode='constant')
        B2 = _slow_rank_filter(A,r)
        assert np.all(B1 == B2)