码迷,mamicode.com
首页 > 编程语言 > 详细

python 图像转矩阵,矩阵转图像

时间:2018-11-22 14:36:36      阅读:397      评论:0      收藏:0      [点我收藏+]

标签:ase   nta   position   infer   inf   help   cut   export   ready   

1、图像转换为矩阵

matrix = numpy.asarray(image)    
Help on function asarray in module numpy.core.numeric:

asarray(a, dtype=None, order=None)
    Convert the input to an array.
    
    Parameters
    ----------
    a : array_like
        Input data, in any form that can be converted to an array.  This
        includes lists, lists of tuples, tuples, tuples of tuples, tuples
        of lists and ndarrays.
    dtype : data-type, optional
        By default, the data-type is inferred from the input data.
    order : {‘C‘, ‘F‘}, optional
        Whether to use row-major (C-style) or
        column-major (Fortran-style) memory representation.
        Defaults to ‘C‘.
    
    Returns
    -------
    out : ndarray
        Array interpretation of `a`.  No copy is performed if the input
        is already an ndarray with matching dtype and order.  If `a` is a
        subclass of ndarray, a base class ndarray is returned.
    
    See Also
    --------
    asanyarray : Similar function which passes through subclasses.
    ascontiguousarray : Convert input to a contiguous array.
    asfarray : Convert input to a floating point ndarray.
    asfortranarray : Convert input to an ndarray with column-major
                     memory order.
    asarray_chkfinite : Similar function which checks input for NaNs and Infs.
    fromiter : Create an array from an iterator.
    fromfunction : Construct an array by executing a function on grid
                   positions.

2、矩阵转换为图像

image = Image.fromarray(matrix)

Help on function fromarray in module PIL.Image: fromarray(obj, mode=None) Creates an image memory from an object exporting the array interface (using the buffer protocol). If obj is not contiguous, then the tobytes method is called and :py:func:`~PIL.Image.frombuffer` is used. :param obj: Object with array interface :param mode: Mode to use (will be determined from type if None) See: :ref:`concept-modes`. :returns: An image object. .. versionadded:: 1.1.6

 

python 图像转矩阵,矩阵转图像

标签:ase   nta   position   infer   inf   help   cut   export   ready   

原文地址:https://www.cnblogs.com/yaocylulu/p/10000404.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!