コード例 #1
0
def vector2narray(v, type='f'):
    """Convert a numpy vector to an narray.  If ndim>1, it converts to
    mathematical coordinates.  This is used with classifiers."""
    checknp(v)
    if v.ndim == 1: return iulib.narray(v, type='f')
    else:
        return iulib.narray(v[::-1, ...].transpose([1, 0] + range(2, v.ndim)))
コード例 #2
0
ファイル: iuutils.py プロジェクト: UIKit0/iulib
def lseg2narray(lseg):
    """Convert a line segmentation (rank 2, 'i') to an narray."""
    checknp(lseg)
    assert lseg.dtype=='i' and lseg.ndim==2,"wanted rank 2 'i' array, got %s"%lseg
    lseg = lseg[::-1,...].transpose()
    lseg = iulib.narray(lseg,type='i')
    return lseg
コード例 #3
0
def lseg2narray(lseg):
    """Convert a line segmentation (rank 2, 'i') to an narray."""
    checknp(lseg)
    assert lseg.dtype == 'i' and lseg.ndim == 2, "wanted rank 2 'i' array, got %s" % lseg
    lseg = lseg[::-1, ...].transpose()
    lseg = iulib.narray(lseg, type='i')
    return lseg
コード例 #4
0
ファイル: iuutils.py プロジェクト: UIKit0/iulib
def numpy2narray(page,type='B'):
    """Convert a numpy image to an narray. Flips from raster to
    mathematical coordinates.  When converting float to integer
    types, multiplies with 255.0, and when converting integer to
    float types, divides by 255.0."""
    checknp(page)
    if type is None: type = ctype(page)
    if isfp(page) and not isfp(type):
        page = array(255*page,dtype='B')
    elif not isfp(page) and isfp(type):
        page = page/255.0
    page = page.transpose([1,0]+range(2,page.ndim))[:,::-1,...]
    return iulib.narray(page,type=type)
コード例 #5
0
def numpy2narray(page, type='B'):
    """Convert a numpy image to an narray. Flips from raster to
    mathematical coordinates.  When converting float to integer
    types, multiplies with 255.0, and when converting integer to
    float types, divides by 255.0."""
    checknp(page)
    if type is None: type = ctype(page)
    if isfp(page) and not isfp(type):
        page = array(255 * page, dtype='B')
    elif not isfp(page) and isfp(type):
        page = page / 255.0
    page = page.transpose([1, 0] + range(2, page.ndim))[:, ::-1, ...]
    return iulib.narray(page, type=type)
コード例 #6
0
ファイル: iuutils.py プロジェクト: UIKit0/iulib
def vector2narray(v,type='f'):
    """Convert a numpy vector to an narray.  If ndim>1, it converts to
    mathematical coordinates.  This is used with classifiers."""
    checknp(v)
    if v.ndim==1: return iulib.narray(v,type='f')
    else: return iulib.narray(v[::-1,...].transpose([1,0]+range(2,v.ndim)))
コード例 #7
0
def as_narrayI(image, dtype=dtype):
    if type(image) != numpy.ndarray: return image
    image = image[::-1, ...]
    image = image.transpose([1, 0] + range(2, image.ndim))
    return iulib.narray(image, type=dtype)
コード例 #8
0
def as_narray(image, flip=0, dtype='f'):
    if type(image) != numpy.ndarray: return image
    if flip and image.ndim: return as_narrayI(image, dtype=dtype)
    return iulib.narray(image, type=dtype)