How to use the mahotas.internal._verify_is_integer_type 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 / mahotas / features / texture.py View on Github external
or as the variance of P(\|x-y\|). In order to achieve compatibility with
        other software and previous versions of mahotas, mahotas defaults to
        using ``VAR[P(\|x-y\|)]``; if this argument is True, then it uses
        ``VAR[\|x-y\|]`` (default: False)


    Returns
    -------
    feats : ndarray of np.double
        A 4x13 or 4x14 feature vector (one row per direction) if `f` is 2D,
        13x13 or 13x14 if it is 3D. The exact number of features depends on the
        value of ``compute_14th_feature`` Also, if either ``return_mean`` or
        ``return_mean_ptp`` is set, then a single dimensional array is
        returned.
    '''
    _verify_is_integer_type(f, 'mahotas.haralick')

    if len(f.shape) == 2:
        nr_dirs = len(_2d_deltas)
    elif len(f.shape) == 3:
        nr_dirs = len(_3d_deltas)
    else:
        raise ValueError('mahotas.texture.haralick: Can only handle 2D and 3D images.')
    fm1 = f.max() + 1
    cmat = np.empty((fm1, fm1), np.int32)
    def all_cmatrices():
        for dir in range(nr_dirs):
            cooccurence(f, dir, cmat, symmetric=True, distance=distance)
            yield cmat
    return haralick_features(all_cmatrices(),
                        ignore_zeros=ignore_zeros,
                        preserve_haralick_bug=preserve_haralick_bug,
github luispedro / mahotas / mahotas / morph.py View on Github external
out : ndarray, optional
        output array. If used, this must be a C-array of the same ``dtype`` as
        ``A``. Otherwise, a new array is allocated.
    output : deprecated
        Do not use

    Returns
    -------
    dilated : ndarray
        dilated version of ``A``

    See Also
    --------
    erode
    '''
    _verify_is_integer_type(A, 'dilate')
    Bc = get_structuring_elem(A,Bc)
    output = _get_output(A, out, 'dilate', output=output)
    return _morph.dilate(A, Bc, output)
github luispedro / mahotas / mahotas / features / texture.py View on Github external
The input image
    direction : integer
        Direction as index into (horizontal [default], diagonal
        [nw-se], vertical, diagonal [ne-sw])
    output : np.long 2 ndarray, optional
        preallocated result.
    symmetric : boolean, optional
        whether return a symmetric matrix (default: True)
    distance : integer, optional (default=1)
        Distance to the central pixel to consider.

    Returns
    -------
      cooccurence_matrix : cooccurence matrix
    '''
    _verify_is_integer_type(f, 'mahotas.cooccurence')
    if len(f.shape) == 2 and not (0 <= direction < 4):
        raise ValueError('mahotas.texture.cooccurence: `direction` {0} is not in range(4).'.format(direction))
    elif len(f.shape) == 3 and not (0 <= direction < 13):
        raise ValueError('mahotas.texture.cooccurence: `direction` {0} is not in range(13).'.format(direction))
    elif len(f.shape) not in (2,3):
        raise ValueError('mahotas.texture.cooccurence: cannot handle images of %s dimensions.' % len(f.shape))

    if output is None:
        mf = f.max()
        output = np.zeros((mf+1, mf+1), np.int32)
    else:
        assert np.min(output.shape) >= f.max(), 'mahotas.texture.cooccurence: output is not large enough'
        assert output.dtype == np.int32, 'mahotas.texture.cooccurence: output is not of type np.int32'
        output.fill(0)

    if len(f.shape) == 2:
github luispedro / mahotas / mahotas / morph.py View on Github external
Bc : ndarray, optional
        Structuring element (default: 3x3 elementary cross).
    out : ndarray, optional
        Output array
    output : deprecated
        Do not use

    Returns
    -------
    y : ndarray

    See Also
    --------
    open : function
    """
    _verify_is_integer_type(f, 'open')
    Bc = get_structuring_elem(f, Bc)
    eroded = erode(f, Bc, out=out)
    # We need to copy for the simple reason that otherwise, the image will be
    # modified in place, which can mess up the implementation
    return dilate(eroded.copy(), Bc, out=eroded)
github luispedro / mahotas / mahotas / morph.py View on Github external
Bc : ndarray, optional
        Structuring element. (Default: 3x3 elementary cross).
    out : ndarray, optional
        Output array
    output : deprecated
        Do not use

    Returns
    -------
    y : ndarray

    See Also
    --------
    open : function
    """
    _verify_is_integer_type(f, 'close')
    Bc = get_structuring_elem(f, Bc)
    dilated = dilate(f, Bc, out=out)
    # We need to copy for the simple reason that otherwise, the image will be
    # modified in place, which can mess up the implementation
    return erode(dilated.copy(), Bc, out=dilated)
github luispedro / mahotas / mahotas / features / lbp.py View on Github external
one_count.flat[i] == nr_of_1s_in_binary_representation_of(array.flat[i])

    Parameters
    ----------
    array : ndarray
        input array

    Returns
    -------
    one_count : ndarray
        output array of same type & shape as array
    '''
    from ..internal import _verify_is_integer_type
    array = np.array(array)
    _verify_is_integer_type(array, 'mahotas.features.lbp.count_binary1s')
    maxv = 1+int(np.log2(1+array.max()))
    counts = np.zeros_like(array)
    for _ in range(maxv):
        counts += (array & 1)
        array >>= 1
    return counts
github luispedro / mahotas / mahotas / histogram.py View on Github external
Notes
    -----
    Only handles unsigned integer arrays.

    Parameters
    ----------
    img : array-like of an unsigned type
        input image.

    Returns
    -------
    hist : an dnarray of type np.uint32
        This will be of size ``img.max() + 1``.
    """
    _verify_is_integer_type(img, 'fullhistogram')
    img = np.ascontiguousarray(img)
    if img.dtype == np.bool:
        ones = img.sum()
        zeros = img.size - ones
        return np.array([zeros, ones], np.uintc)

    histogram = np.zeros(int(img.max()) + 1, np.uintc)
    _histogram.histogram(img, histogram)
    return histogram
github luispedro / mahotas / mahotas / morph.py View on Github external
Structuring element. By default, use a cross (see
        ``get_structuring_elem`` for details on the default).
    out : ndarray, optional
        output array. If used, this must be a C-array of the same ``dtype`` as
        ``A``. Otherwise, a new array is allocated.

    Returns
    -------
    erosion : ndarray
        eroded version of ``A``

    See Also
    --------
    dilate
    '''
    _verify_is_integer_type(A,'erode')
    Bc = get_structuring_elem(A,Bc)
    output = _get_output(A, out, 'erode', output=output)
    return _morph.erode(A, Bc, output)
github luispedro / mahotas / mahotas / morph.py View on Github external
----------
    input : input ndarray
        This is interpreted as a binary array.
    Bc : ndarray
        hit & miss template, values must be one of (0, 1, 2)
    out : ndarray, optional
        Used for output. Must be Boolean ndarray of same size as ``input``
    output : deprecated
        Do not use

    Returns
    -------
    filtered : ndarray
    '''
    _verify_is_integer_type(input, 'hitmiss')
    _verify_is_integer_type(Bc, 'hitmiss')
    if input.dtype != Bc.dtype:
        if input.dtype == np.bool_:
            input = input.view(np.uint8)
            if Bc.dtype == np.bool_:
                Bc = Bc.view(np.uint8)
            else:
                Bc = Bc.astype(np.uint8)
        else:
            Bc = Bc.astype(input.dtype)

    if out is None and output is not None: # pragma: no cover
        out = output

    # We cannot call internal._get_output here because the conditions around
    # dtypes are different from those implemented in `internal._get_output`