Exemplo n.º 1
0
    def colorize(self, image, nodata=None):
        """Returns a new RGBA VImage that has been colorized"""
        if image.Bands() != 1:
            raise ValueError("image {0!r} has more than one band".format(image))

        logging.info("Coloring data")
        logging.debug("Algorithm: {0} {1}".format(type(self).__name__, self))

        # Convert to a numpy array
        data = numpy.frombuffer(buffer=image.tobuffer(), dtype=image.NumPyType())

        # Use numexpr to color the data as RGBA bands
        bands = self._colorize_bands(data=data, nodata=nodata)

        # Merge the bands into a single RGBA VImage
        width, height = image.Xsize(), image.Ysize()
        images = [
            VImage.from_numpy_array(array=band, width=width, height=height, bands=1, format=VImage.FMTUCHAR)
            for band in bands
        ]
        return VImage.gbandjoin(bands=images)