How to use the mahotas.histogram.fullhistogram function in mahotas

To help you get started, we’ve selected a few mahotas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github luispedro / mahotas / tests / test_histogram.py View on Github external
def test_fullhistogram():
    A100 = np.arange(100).reshape((10,10)).astype(np.uint32)
    assert fullhistogram(A100).shape == (100,)
    assert np.all(fullhistogram(A100) == np.ones(100))

    A1s = np.ones((12,12), np.uint8)
    assert fullhistogram(A1s).shape == (2,)
    assert np.all(fullhistogram(A1s) == np.array([0,144]))

    A1s[0] = 0
    A1s[1] = 2
    assert fullhistogram(A1s).shape == (3,)
    assert np.all(fullhistogram(A1s) == np.array([12,120,12]))
github luispedro / mahotas / tests / test_histogram.py View on Github external
def test_fullhistogram_random():
    np.random.seed(122)
    A = np.random.rand(12,3,44,33)*1000
    A = A.astype(np.uint16)
    hist = fullhistogram(A)
    for i in xrange(len(hist)):
        assert hist[i] == (A == i).sum()
    assert len(hist.shape) == 1

    A = A[::2,:,2::3,1:-2:2]
    hist = fullhistogram(A)
    for i in xrange(len(hist)):
        assert hist[i] == (A == i).sum()
    assert hist.sum() == A.size
    assert len(hist.shape) == 1
github luispedro / mahotas / tests / test_histogram.py View on Github external
def test_float():
    fullhistogram(np.arange(16.*4., dtype=float).reshape((16,4)))
github luispedro / mahotas / tests / test_histogram.py View on Github external
def test_types():
    A100 = np.arange(100).reshape((10,10)).astype(np.uint32)
    assert np.all(fullhistogram(A100.astype(np.uint8)) == fullhistogram(A100))
    assert np.all(fullhistogram(A100.astype(np.uint16)) == fullhistogram(A100))
    assert np.all(fullhistogram(A100.astype(np.uint32)) == fullhistogram(A100))
    assert np.all(fullhistogram(A100.astype(np.uint64)) == fullhistogram(A100))
github luispedro / mahotas / tests / test_histogram.py View on Github external
def test_fullhistogram():
    A100 = np.arange(100).reshape((10,10)).astype(np.uint32)
    assert fullhistogram(A100).shape == (100,)
    assert np.all(fullhistogram(A100) == np.ones(100))

    A1s = np.ones((12,12), np.uint8)
    assert fullhistogram(A1s).shape == (2,)
    assert np.all(fullhistogram(A1s) == np.array([0,144]))

    A1s[0] = 0
    A1s[1] = 2
    assert fullhistogram(A1s).shape == (3,)
    assert np.all(fullhistogram(A1s) == np.array([12,120,12]))
github luispedro / mahotas / tests / test_histogram.py View on Github external
def test_fullhistogram_boolean():
    np.random.seed(123)
    A = (np.random.rand(128,128) > .5)
    H = fullhistogram(A)
    assert H[0] == (~A).sum()
    assert H[1] == A.sum()
github luispedro / mahotas / tests / test_histogram.py View on Github external
def test_fullhistogram():
    A100 = np.arange(100).reshape((10,10)).astype(np.uint32)
    assert fullhistogram(A100).shape == (100,)
    assert np.all(fullhistogram(A100) == np.ones(100))

    A1s = np.ones((12,12), np.uint8)
    assert fullhistogram(A1s).shape == (2,)
    assert np.all(fullhistogram(A1s) == np.array([0,144]))

    A1s[0] = 0
    A1s[1] = 2
    assert fullhistogram(A1s).shape == (3,)
    assert np.all(fullhistogram(A1s) == np.array([12,120,12]))
github luispedro / mahotas / mahotas / features / lbp.py View on Github external
Returns
    -------
    features : 1-D numpy ndarray
        histogram of features. See above for a caveat on the interpretation of
        these.

    References
    ----------
    Gray Scale and Rotation Invariant Texture Classification with Local Binary Patterns
        Ojala, T. Pietikainen, M. Maenpaa, T. Lecture Notes in Computer Science (Springer)
        2000, ISSU 1842, pages 404-420
    '''
    from mahotas.features import _lbp
    codes = lbp_transform(image, radius, points, ignore_zeros=ignore_zeros, preserve_shape=False)
    final = fullhistogram(codes.astype(np.uint32))

    codes = np.arange(2**points, dtype=np.uint32)
    iters = codes.copy()
    codes = _lbp.map(codes.astype(np.uint32), points)
    pivots = (codes == iters)
    npivots = np.sum(pivots)
    compressed = final[pivots[:len(final)]]
    compressed = np.append(compressed, np.zeros(npivots - len(compressed)))
    return compressed
github luispedro / mahotas / mahotas / thresholding.py View on Github external
Parameters
    ----------
    img : an image as a numpy array.
        This should be of an unsigned integer type.
    ignore_zeros : Boolean
        whether to ignore zero-valued pixels
        (default: False)

    Returns
    -------
    T : integer
        the threshold
    """
    _verify_is_integer_type(img, 'otsu')
    hist = fullhistogram(img)
    hist = np.asanyarray(hist, dtype=np.double)
    if ignore_zeros:
        hist[0] = 0
    return _histogram.otsu(hist)
github luispedro / mahotas / mahotas / thresholding.py View on Github external
# finally, we use the value to form a binary image:
        bin = (im > t)

    Parameters
    ----------
    img : ndarray
        Image of any type
    ignore_zeros : boolean, optional
        Whether to ignore zero valued pixels (default: False)

    Returns
    -------
    T : float
        threshold
    """
    hist = fullhistogram(img)
    if ignore_zeros:
        if hist[0] == img.size:
            return 0
        hist[0] = 0
    N = hist.size

    # Precompute most of what we need:
    first_moment = np.cumsum(np.arange(N) * hist)
    cumsum = np.cumsum(hist)

    r_first_moment = np.flipud(np.cumsum(np.flipud(np.arange(N) * hist)))
    r_cumsum = np.flipud(np.cumsum(np.flipud(hist)))

    maxt = N-1
    while hist[maxt] == 0:
        maxt -= 1