Ejemplo n.º 1
0
    def make_image(self, flipy):        

        if self._A is not None:
            x = self.to_rgba(self._A, self._alpha)
            im = _image.fromarray(x, 0)
        else:
            raise RuntimeError('You must first set the image array or the image attribute')

        bg = colorConverter.to_rgba(self.axes.get_frame().get_facecolor(), 0)
        im.set_bg( *bg)
        im.is_grayscale = (self.cmap.name == "gray" and
                           len(self._A.shape) == 2)
        
        im.set_aspect(self._aspectd[self._aspect])        
        im.set_interpolation(self._interpd[self._interpolation])



        # image input dimensions
        numrows, numcols = im.get_size()
        im.reset_matrix()

        xmin, xmax, ymin, ymax = self.get_extent() 
        dxintv = xmax-xmin
        dyintv = ymax-ymin

        # the viewport scale factor
        sx = dxintv/self.axes.viewLim.width()
        sy = dyintv/self.axes.viewLim.height()

        if im.get_interpolation()!=_image.NEAREST:
            im.apply_translation(-1, -1)

        # the viewport translation
        tx = (xmin-self.axes.viewLim.xmin())/dxintv * numcols
        if flipy: 
            ty = -(ymax-self.axes.viewLim.ymax())/dyintv * numrows
        else:
            ty = (ymin-self.axes.viewLim.ymin())/dyintv * numrows

        l, b, widthDisplay, heightDisplay = self.axes.bbox.get_bounds()

        im.apply_translation(tx, ty)
        im.apply_scaling(sx, sy)

        # resize viewport to display
        rx = widthDisplay / numcols
        ry = heightDisplay  / numrows

        if im.get_aspect()==_image.ASPECT_PRESERVE:
            if ry < rx: rx = ry
            # todo: center the image in viewport
            im.apply_scaling(rx, rx)
        else:
            im.apply_scaling(rx, ry)

        #print tx, ty, sx, sy, rx, ry, widthDisplay, heightDisplay
        im.resize(int(widthDisplay+0.5), int(heightDisplay+0.5))
        return im
Ejemplo n.º 2
0
    def make_image(self):
        if self._A is None:
            raise RuntimeError('You must first set the image array')

        x = self.to_rgba(self._A, self._alpha)

        im = _image.fromarray(x, 1)
        im.set_bg(*colorConverter.to_rgba(self.figure.get_facecolor(), 0))
        im.is_grayscale = (self.cmap.name == "gray"
                           and len(self._A.shape) == 2)
        return im
Ejemplo n.º 3
0
    def make_image(self):
        if self._A is None:
            raise RuntimeError('You must first set the image array')

        x = self.to_rgba(self._A, self._alpha)

        im = _image.fromarray(x, 1)
        im.set_bg( *colorConverter.to_rgba(self.figure.get_facecolor(), 0) )
        im.is_grayscale = (self.cmap.name == "gray" and
                           len(self._A.shape) == 2)
        return im
Ejemplo n.º 4
0
    def make_image(self):
        if self._A is not None:
            if self._imcache is None:
                if typecode(self._A) == UInt8:
                    im = _image.frombyte(self._A, 0)
                    im.is_grayscale = False
                else:
                    x = self.to_rgba(self._A, self._alpha)
                    im = _image.fromarray(x, 0)
                    if len(self._A.shape) == 2:
                        im.is_grayscale = self.cmap.is_gray()
                    else:
                        im.is_grayscale = False
                self._imcache = im
            else:
                im = self._imcache
        else:
            raise RuntimeError("You must first set the image array or the image attribute")

        bg = colorConverter.to_rgba(self.axes.get_frame().get_facecolor(), 0)

        if self.origin == "upper":
            im.flipud_in()

        im.set_bg(*bg)

        im.set_interpolation(self._interpd[self._interpolation])

        # image input dimensions
        numrows, numcols = im.get_size()
        im.reset_matrix()

        xmin, xmax, ymin, ymax = self.get_extent()
        dxintv = xmax - xmin
        dyintv = ymax - ymin

        # the viewport scale factor
        sx = dxintv / self.axes.viewLim.width()
        sy = dyintv / self.axes.viewLim.height()

        if im.get_interpolation() != _image.NEAREST:
            im.apply_translation(-1, -1)

        # the viewport translation
        tx = (xmin - self.axes.viewLim.xmin()) / dxintv * numcols

        # if flipy:
        #    ty = -(ymax-self.axes.viewLim.ymax())/dyintv * numrows
        # else:
        #    ty = (ymin-self.axes.viewLim.ymin())/dyintv * numrows
        ty = (ymin - self.axes.viewLim.ymin()) / dyintv * numrows

        l, b, widthDisplay, heightDisplay = self.axes.bbox.get_bounds()

        im.apply_translation(tx, ty)
        im.apply_scaling(sx, sy)

        # resize viewport to display
        rx = widthDisplay / numcols
        ry = heightDisplay / numrows
        im.apply_scaling(rx, ry)

        # print tx, ty, sx, sy, rx, ry, widthDisplay, heightDisplay
        im.resize(int(widthDisplay + 0.5), int(heightDisplay + 0.5), norm=self._filternorm, radius=self._filterrad)

        if self.origin == "upper":
            im.flipud_in()

        return im
Ejemplo n.º 5
0
    def make_image(self):
        if self._A is not None:
            if self._imcache is None:
                if typecode(self._A) == UInt8:
                    im = _image.frombyte(self._A, 0)
                    im.is_grayscale = False
                else:
                    x = self.to_rgba(self._A, self._alpha)
                    im = _image.fromarray(x, 0)
                    if len(self._A.shape) == 2:
                        im.is_grayscale = self.cmap.is_gray()
                    else:
                        im.is_grayscale = False
                self._imcache = im
            else:
                im = self._imcache
        else:
            raise RuntimeError(
                'You must first set the image array or the image attribute')

        bg = colorConverter.to_rgba(self.axes.get_frame().get_facecolor(), 0)

        if self.origin == 'upper':
            im.flipud_in()

        im.set_bg(*bg)

        im.set_interpolation(self._interpd[self._interpolation])

        # image input dimensions
        numrows, numcols = im.get_size()
        im.reset_matrix()

        xmin, xmax, ymin, ymax = self.get_extent()
        dxintv = xmax - xmin
        dyintv = ymax - ymin

        # the viewport scale factor
        sx = dxintv / self.axes.viewLim.width()
        sy = dyintv / self.axes.viewLim.height()

        if im.get_interpolation() != _image.NEAREST:
            im.apply_translation(-1, -1)

        # the viewport translation
        tx = (xmin - self.axes.viewLim.xmin()) / dxintv * numcols

        #if flipy:
        #    ty = -(ymax-self.axes.viewLim.ymax())/dyintv * numrows
        #else:
        #    ty = (ymin-self.axes.viewLim.ymin())/dyintv * numrows
        ty = (ymin - self.axes.viewLim.ymin()) / dyintv * numrows

        l, b, widthDisplay, heightDisplay = self.axes.bbox.get_bounds()

        im.apply_translation(tx, ty)
        im.apply_scaling(sx, sy)

        # resize viewport to display
        rx = widthDisplay / numcols
        ry = heightDisplay / numrows
        im.apply_scaling(rx, ry)

        #print tx, ty, sx, sy, rx, ry, widthDisplay, heightDisplay
        im.resize(int(widthDisplay + 0.5),
                  int(heightDisplay + 0.5),
                  norm=self._filternorm,
                  radius=self._filterrad)

        if self.origin == 'upper':
            im.flipud_in()

        return im