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)))
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
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
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)
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)
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)))
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)
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)