Python Image.frombytes() Examples

The following are 3 code examples of Image.frombytes(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module Image , or try the search function .
Example #1
Source File: streams_milli.py    From hydrology with GNU General Public License v3.0 5 votes vote down vote up
def arrayToImage(a):
    """
    Converts a gdalnumeric array to a
    Python Imaging Library Image.
    """
    i=Image.frombytes('L',(a.shape[1],a.shape[0]),
            (a.astype('b')).tostring())
    return i 
Example #2
Source File: modis_tg_halli.py    From hydrology with GNU General Public License v3.0 5 votes vote down vote up
def arrayToImage(a):
    """
    Converts a gdalnumeric array to a
    Python Imaging Library Image.
    """
    i=Image.frombytes('L',(a.shape[1],a.shape[0]),
            (a.astype('b')).tostring())
    return i

# clip the raster only for tg halli area
# http://geospatialpython.com/2011/02/clip-raster-using-shapefile.html 
Example #3
Source File: provider.py    From geonotebook with Apache License 2.0 5 votes vote down vote up
def renderArea(self, width, height, srs, xmin, ymin, xmax, ymax, zoom):
        '''
        '''

        # NB: To be thread-safe Map object cannot be stored in the class state.
        # see: https://groups.google.com/forum/#!topic/mapnik/USDlVfSk328

        Map = mapnik.Map(width, height, srs)
        Map.zoom_to_box(Box2d(xmin, ymin, xmax, ymax))

        Map = self.style_map(Map)

        img = mapnik.Image(width, height)
        # Don't even call render with scale factor if it's not
        # defined. Plays safe with older versions.
        if self.scale_factor is None:
            mapnik.render(Map, img)
        else:
            mapnik.render(Map, img, self.scale_factor)

        def gamma_correct(im):
            """Fast gamma correction with PIL's image.point() method."""
            if self.gamma != 1.0:
                table = [pow(x / 255., 1.0 / self.gamma) * 255
                         for x in range(256)]
                # Expand table to number of bands
                table = table * len(im.mode)
                return im.point(table)
            else:
                return im

        # b = BytesIO(img.tostring())
        img = Image.frombytes('RGBA', (width, height), img.tostring())

        img = gamma_correct(img)

        return img