Exemplo n.º 1
0
def test_ignore_zeros():
    np.seterr(all='raise')
    np.random.seed(22)
    A = np.zeros((1024, 24), np.uint8)
    A[:24, :24] = np.random.random_integers(100, 200, size=(24, 24))
    assert rc(A) < 100
    assert otsu(A) < 100
    assert rc(A, ignore_zeros=1) > 100
    assert otsu(A, ignore_zeros=1) > 100
Exemplo n.º 2
0
def test_ignore_zeros():
    np.seterr(all='raise')
    np.random.seed(22)
    A = np.zeros((1024,24), np.uint8)
    A[:24,:24] = np.random.randint(100, 200, size=(24,24))
    assert rc(A) < 100
    assert otsu(A) < 100
    assert rc(A, ignore_zeros=1) > 100
    assert otsu(A, ignore_zeros=1) > 100
Exemplo n.º 3
0
def threshold(img,thresh):
    '''
    T = threshold(img, thresh)

    thresh can be:
        * None: returns -1
        * a number: returns thresh
        * a function: returns thresh(img)
        * a string:
            one of ('otsu','rc','murphy_rc','mean')
    '''
    if thresh is None:
        return -1
    if type(thresh) is str:
        if thresh == 'otsu':
            return otsu(img)
        if thresh == 'rc':
            return rc(img)
        if thresh == 'murphy_rc':
            return murphy_rc(img)
        if thresh == 'mean':
            return img.mean()
        raise ValueError("pyslic.threshold: Cannot handle argument '%s'" % thresh)
    if callable(thresh):
        return thresh(img)
    return thresh
Exemplo n.º 4
0
def murphy_rc(img,ignore_zeros=False):
    """
    T = murphy_rc(img)
    
    Calculate a threshold according to Murphy's adaptation of the RC method.

    @param ignore_zeros: Whether to ignore zero valued pixels (default: False)
        Murphy's Matlab implementation always ignores zero valued pixels.
    """
    pmax = img.max()
    return pmax-rc(pmax-img, ignore_zeros=ignore_zeros)
Exemplo n.º 5
0
def extract1(img, solution):
    labeled, _ = solution
    binary = (labeled > 0)
    bg = img[~binary].ravel()
    objects = img[binary].ravel()
    bstd = bg.std()
    if bstd == 0:
        bstd = 1
    separation = (bg.mean()-objects.mean())/bstd
    corrcoefs = []
    for T in (img.mean(), img.mean() + img.std(), otsu(img), rc(img)):
        corrcoefs.append(_corrcoef(binary, img > T))
    return np.concatenate( ([separation], corrcoefs) )
Exemplo n.º 6
0
def oversegment(img):
    overseg = sobel_segment(img)
    for t in (img.mean(), otsu(img), rc(img)):
        overseg = intersec(overseg, segment(img, t))
    return overseg
Exemplo n.º 7
0
def test_nozeros():
    np.seterr(all='raise')
    np.random.seed(22)
    A = (np.random.rand(100,100)*50).astype(np.uint8)+201
    assert rc(A) > 200
    assert otsu(A) > 200
Exemplo n.º 8
0
def test_nozeros():
    np.seterr(all='raise')
    np.random.seed(22)
    A = (np.random.rand(100,100)*50).astype(np.uint8)+201
    assert rc(A) > 200
    assert otsu(A) > 200