lib/matplotlib/image.py
def pil_to_array( pilImage ):
    """
    load a PIL image and return it as a numpy array of uint8.  For
    grayscale images, the return array is MxN.  For RGB images, the
    return value is MxNx3.  For RGBA images the return value is MxNx4
    """
    def toarray(im):
        'return a 1D array of floats'
        x_str = im.tostring('raw',im.mode,0,-1)
        x = np.fromstring(x_str,np.uint8)
        return x

    if pilImage.mode in ('RGBA', 'RGBX'):
        im = pilImage # no need to convert images
    elif pilImage.mode=='L':
        im = pilImage # no need to luminance images
        # return MxN luminance array
        x = toarray(im)
        x.shape = im.size[1], im.size[0]
        return x
    elif pilImage.mode=='RGB':
        #return MxNx3 RGB array
        im = pilImage # no need to RGB images
        x = toarray(im)
        x.shape = im.size[1], im.size[0], 3
        return x

    else: # try to convert to an rgba image
        try:
            im = pilImage.convert('RGBA')
        except ValueError:
            raise RuntimeError('Unknown image mode')

    # return MxNx4 RGBA array
    x = toarray(im)
    x.shape = im.size[1], im.size[0], 4
    return x

    load a PIL image and return it as a numpy array of uint8.  For
    grayscale images, the return array is MxN.  For RGB images, the
    return value is MxNx3.  For RGBA images the return value is MxNx4
    
load a PIL image and return it as a numpy array of uint8.  For
grayscale images, the return array is MxN.  For RGB images, the
return value is MxNx3.  For RGBA images the return value is MxNx4
load a PIL image and return it as a numpy array of uint8 . For grayscale images the return array is MxN . For RGB images the return value is MxNx3 . For RGBA images the return value is MxNx4
def pil_to_array( pilImage ):
    def toarray(im):
        x_str = im.tostring('raw',im.mode,0,-1)
        x = np.fromstring(x_str,np.uint8)
        return x
    if pilImage.mode in ('RGBA', 'RGBX'):
        im = pilImage 
    elif pilImage.mode=='L':
        im = pilImage 
        x = toarray(im)
        x.shape = im.size[1], im.size[0]
        return x
    elif pilImage.mode=='RGB':
        im = pilImage 
        x = toarray(im)
        x.shape = im.size[1], im.size[0], 3
        return x
    else: 
        try:
            im = pilImage.convert('RGBA')
        except ValueError:
            raise RuntimeError('Unknown image mode')
    x = toarray(im)
    x.shape = im.size[1], im.size[0], 4
    return x
def pil_to_array ( pilImage ) : def toarray ( im ) : 'return a 1D array of floats' x_str = im . tostring ( 'raw' , im . mode , 0 , - 1 ) x = np . fromstring ( x_str , np . uint8 ) return x if pilImage . mode in ( 'RGBA' , 'RGBX' ) : im = pilImage elif pilImage . mode == 'L' : im = pilImage x = toarray ( im ) x . shape = im . size [ 1 ] , im . size [ 0 ] return x elif pilImage . mode == 'RGB' : im = pilImage x = toarray ( im ) x . shape = im . size [ 1 ] , im . size [ 0 ] , 3 return x else : try : im = pilImage . convert ( 'RGBA' ) except ValueError : raise RuntimeError ( 'Unknown image mode' ) x = toarray ( im ) x . shape = im . size [ 1 ] , im . size [ 0 ] , 4 return x
load a PIL image and return it as a numpy array of uint8.
load a PIL image and return it as a numpy array of uint8 .
"""
    load a PIL image and return it as a numpy array of uint8.  For
    grayscale images, the return array is MxN.  For RGB images, the
    return value is MxNx3.  For RGBA images the return value is MxNx4
    """ 'return a 1D array of floats' # no need to convert images # no need to luminance images # return MxN luminance array #return MxNx3 RGB array # no need to RGB images # try to convert to an rgba image # return MxNx4 RGBA array
pilImage