• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python _image.frombyte函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中matplotlib._image.frombyte函数的典型用法代码示例。如果您正苦于以下问题:Python frombyte函数的具体用法?Python frombyte怎么用?Python frombyte使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了frombyte函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: make_image

    def make_image(self, renderer, magnification=1.0):
        if self._A is None:
            raise RuntimeError('You must first set the image '
                               'array or the image attribute')

        if self._imcache is None:
            A = self._A
            if self.origin == 'upper':
                A = A[::-1]
            if A.dtype == np.uint8 and len(A.shape) == 3:
                im = _image.frombyte(A, 0)
                im.is_grayscale = False
            else:
                if self._rgbacache is None:
                    x = self.to_rgba(A, bytes=True)
                    self._rgbacache = x
                else:
                    x = self._rgbacache
                im = _image.frombyte(x, 0)
                if len(A.shape) == 2:
                    im.is_grayscale = self.cmap.is_gray()
                else:
                    im.is_grayscale = False
            self._imcache = im
        else:
            im = self._imcache

        # image input dimensions
        im.reset_matrix()

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

        im.set_resample(self._resample)

        l, b, r, t = self.get_window_extent(renderer).extents  # bbox.extents
        widthDisplay = abs(round(r) - round(l))
        heightDisplay = abs(round(t) - round(b))
        widthDisplay *= magnification
        heightDisplay *= magnification

        numrows, numcols = self._A.shape[:2]

        if (not self.interp_at_native and
            widthDisplay == numcols and heightDisplay == numrows):
            im.set_interpolation(0)

        # resize viewport to display
        rx = widthDisplay / numcols
        ry = heightDisplay / numrows
        #im.apply_scaling(rx*sx, ry*sy)
        im.apply_scaling(rx, ry)
        #im.resize(int(widthDisplay+0.5), int(heightDisplay+0.5),
        #          norm=self._filternorm, radius=self._filterrad)
        im.resize(int(widthDisplay), int(heightDisplay),
                  norm=self._filternorm, radius=self._filterrad)
        return im
开发者ID:agardelein,项目名称:matplotlib,代码行数:56,代码来源:image.py


示例2: make_image

    def make_image(self, renderer, magnification=1.0):
        if self._A is None:
            raise RuntimeError("You must first set the image array or the image attribute")

        if self._imcache is None:
            if self._A.dtype == np.uint8 and len(self._A.shape) == 3:
                im = _image.frombyte(self._A, 0)
                im.is_grayscale = False
            else:
                if self._rgbacache is None:
                    x = self.to_rgba(self._A, self._alpha, bytes=True)
                    self._rgbacache = x
                else:
                    x = self._rgbacache
                im = _image.frombyte(x, 0)
                if len(self._A.shape) == 2:
                    im.is_grayscale = self.cmap.is_gray()
                else:
                    im.is_grayscale = False
            self._imcache = im

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

        # image input dimensions
        im.reset_matrix()

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

        im.set_resample(self._resample)

        l, b, r, t = self.get_window_extent(renderer).extents  # bbox.extents
        widthDisplay = (round(r) + 0.5) - (round(l) - 0.5)
        heightDisplay = (round(t) + 0.5) - (round(b) - 0.5)
        widthDisplay *= magnification
        heightDisplay *= magnification

        numrows, numcols = self._A.shape[:2]

        # resize viewport to display
        rx = widthDisplay / numcols
        ry = heightDisplay / numrows
        # im.apply_scaling(rx*sx, ry*sy)
        im.apply_scaling(rx, ry)
        # im.resize(int(widthDisplay+0.5), int(heightDisplay+0.5),
        #          norm=self._filternorm, radius=self._filterrad)
        im.resize(int(widthDisplay), int(heightDisplay), norm=self._filternorm, radius=self._filterrad)
        return im
开发者ID:dhomeier,项目名称:matplotlib-py3,代码行数:50,代码来源:image.py


示例3: make_image

    def make_image(self, magnification=1.0):
        if self._A is None:
            raise RuntimeError('You must first set the image array')

        x = self.to_rgba(self._A, self._alpha, bytes=True)
        self.magnification = magnification
        # if magnification is not one, we need to resize
        ismag = magnification!=1
        #if ismag: raise RuntimeError
        if ismag:
            isoutput = 0
        else:
            isoutput = 1
        im = _image.frombyte(x, isoutput)
        fc = self.figure.get_facecolor()
        im.set_bg( *mcolors.colorConverter.to_rgba(fc, 0) )
        im.is_grayscale = (self.cmap.name == "gray" and
                           len(self._A.shape) == 2)

        if ismag:
            numrows, numcols = self.get_size()
            numrows *= magnification
            numcols *= magnification
            im.set_interpolation(_image.NEAREST)
            im.resize(numcols, numrows)
        if self.origin=='upper':
            im.flipud_out()

        return im
开发者ID:CTPUG,项目名称:matplotlib,代码行数:29,代码来源:image.py


示例4: finish_gl_drawing

def finish_gl_drawing(glcanvas, renderer, tag, trans):
    renderer._k_globj += 1
    if (renderer._k_globj != renderer._num_globj): return
    #print ("finish gl draw", renderer._k_globj, renderer._num_globj)
    if not glcanvas._hittest_map_update:
        glcanvas._no_hl = False
        id_dict = glcanvas.draw_mpl_artists(tag)
        im = glcanvas.read_data(tag) # im : image, im2: id, im3: depth
        gc = renderer.new_gc()
        x, y =trans.transform(frame_range[0:2])
        im = frombyte(im, 1)
        if not isMPL2:
            im.is_grayscale = False ## this is needed to print in MPL1.5
        renderer.draw_image(gc, round(x), round(y), im)
        gc.restore()
    else:
        #
        # need to draw twice due to buffering of pixel reading
        #
        glcanvas._no_hl = True
        glcanvas._hittest_map_update = True        
        id_dict = glcanvas.draw_mpl_artists(tag)
        # im : image, im2, im2d: id, im3: depth
        im, im2, im2d, im3 = glcanvas.read_data(tag)
        
        glcanvas._hittest_map_update = False
        id_dict = glcanvas.draw_mpl_artists(tag)
        im = glcanvas.read_data(tag) # im : image, im2: id, im3: depth
        glcanvas._hittest_map_update = True                

        gc = renderer.new_gc()
        x, y =trans.transform(frame_range[0:2])
        im = frombyte(im, 1)
        if not isMPL2:
            im.is_grayscale = False ## this is needed to print in MPL1.5

        if renderer.gl_svg_rescale:
           ### svg renderer has image_dpi = 100 (not 72)
           ### therefore width and height needs to be set
           x2, y2 =trans.transform(frame_range[2:])        
           renderer.draw_image(gc, round(x), round(y), im,
                               dx=round(x2-x), dy = round(y2-y))
        else:
           renderer.draw_image(gc, round(x), round(y), im)
        renderer.update_id_data((x, y, id_dict, im2, im2d, im3), tag = tag)
        gc.restore()
    tag._gl_img = im
开发者ID:piScope,项目名称:piScope,代码行数:47,代码来源:art3d_gl.py


示例5: _get_unsampled_image

    def _get_unsampled_image(self, A, image_extents, viewlim):
        """
        convert numpy array A with given extents ([x1, x2, y1, y2] in
        data coordinate) into the Image, given the viewlim (should be a
        bbox instance).  Image will be clipped if the extents is
        significantly larger than the viewlim.
        """
        xmin, xmax, ymin, ymax = image_extents
        dxintv = xmax-xmin
        dyintv = ymax-ymin

        # the viewport scale factor
        if viewlim.width == 0.0 and dxintv == 0.0:
            sx = 1.0
        else:
            sx = dxintv/viewlim.width
        if viewlim.height == 0.0 and dyintv == 0.0:
            sy = 1.0
        else:
            sy = dyintv/viewlim.height
        numrows, numcols = A.shape[:2]
        if sx > 2:
            x0 = (viewlim.x0-xmin)/dxintv * numcols
            ix0 = max(0, int(x0 - self._filterrad))
            x1 = (viewlim.x1-xmin)/dxintv * numcols
            ix1 = min(numcols, int(x1 + self._filterrad))
            xslice = slice(ix0, ix1)
            xmin_old = xmin
            xmin = xmin_old + ix0*dxintv/numcols
            xmax = xmin_old + ix1*dxintv/numcols
            dxintv = xmax - xmin
            sx = dxintv/viewlim.width
        else:
            xslice = slice(0, numcols)

        if sy > 2:
            y0 = (viewlim.y0-ymin)/dyintv * numrows
            iy0 = max(0, int(y0 - self._filterrad))
            y1 = (viewlim.y1-ymin)/dyintv * numrows
            iy1 = min(numrows, int(y1 + self._filterrad))
            if self.origin == 'upper':
                yslice = slice(numrows-iy1, numrows-iy0)
            else:
                yslice = slice(iy0, iy1)
            ymin_old = ymin
            ymin = ymin_old + iy0*dyintv/numrows
            ymax = ymin_old + iy1*dyintv/numrows
            dyintv = ymax - ymin
            sy = dyintv/viewlim.height
        else:
            yslice = slice(0, numrows)

        if xslice != self._oldxslice or yslice != self._oldyslice:
            self._imcache = None
            self._oldxslice = xslice
            self._oldyslice = yslice

        if self._imcache is None:
            if self._A.dtype == np.uint8 and self._A.ndim == 3:
                im = _image.frombyte(self._A[yslice,xslice,:], 0)
                im.is_grayscale = False
            else:
                if self._rgbacache is None:
                    x = self.to_rgba(self._A, self._alpha, bytes=True)
                    self._rgbacache = x
                else:
                    x = self._rgbacache
                im = _image.frombyte(x[yslice,xslice,:], 0)
                if self._A.ndim == 2:
                    im.is_grayscale = self.cmap.is_gray()
                else:
                    im.is_grayscale = False
            self._imcache = im

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

        return im, xmin, ymin, dxintv, dyintv, sx, sy
开发者ID:CTPUG,项目名称:matplotlib,代码行数:80,代码来源:image.py


示例6: _get_unsampled_image

    def _get_unsampled_image(self, A, image_extents, viewlim):
        """
        convert numpy array A with given extents ([x1, x2, y1, y2] in
        data coordinate) into the Image, given the viewlim (should be a
        bbox instance).  Image will be clipped if the extents is
        significantly larger than the viewlim.
        """
        xmin, xmax, ymin, ymax = image_extents
        dxintv = xmax-xmin
        dyintv = ymax-ymin

        # the viewport scale factor
        if viewlim.width == 0.0 and dxintv == 0.0:
            sx = 1.0
        else:
            sx = dxintv/viewlim.width
        if viewlim.height == 0.0 and dyintv == 0.0:
            sy = 1.0
        else:
            sy = dyintv/viewlim.height
        numrows, numcols = A.shape[:2]
        if sx > 2:
            x0 = (viewlim.x0-xmin)/dxintv * numcols
            ix0 = max(0, int(x0 - self._filterrad))
            x1 = (viewlim.x1-xmin)/dxintv * numcols
            ix1 = min(numcols, int(x1 + self._filterrad))
            xslice = slice(ix0, ix1)
            xmin_old = xmin
            xmin = xmin_old + ix0*dxintv/numcols
            xmax = xmin_old + ix1*dxintv/numcols
            dxintv = xmax - xmin
            sx = dxintv/viewlim.width
        else:
            xslice = slice(0, numcols)

        if sy > 2:
            y0 = (viewlim.y0-ymin)/dyintv * numrows
            iy0 = max(0, int(y0 - self._filterrad))
            y1 = (viewlim.y1-ymin)/dyintv * numrows
            iy1 = min(numrows, int(y1 + self._filterrad))
            yslice = slice(iy0, iy1)
            ymin_old = ymin
            ymin = ymin_old + iy0*dyintv/numrows
            ymax = ymin_old + iy1*dyintv/numrows
            dyintv = ymax - ymin
            sy = dyintv/viewlim.height
        else:
            yslice = slice(0, numrows)

        if xslice != self._oldxslice or yslice != self._oldyslice:
            self._imcache = None
            self._oldxslice = xslice
            self._oldyslice = yslice

        if self._imcache is None:
            A = self._A
            if self.origin == 'upper':
                A = A[::-1]

            if A.dtype == np.uint8 and A.ndim == 3:
                im = _image.frombyte(A[yslice, xslice, :], 0)
                im.is_grayscale = False
            else:
                if self._rgbacache is None:
                    x = self.to_rgba(A, bytes=False)
                    # Avoid side effects: to_rgba can return its argument
                    # unchanged.
                    if np.may_share_memory(x, A):
                        x = x.copy()
                    # premultiply the colors
                    x[..., 0:3] *= x[..., 3:4]
                    x = (x * 255).astype(np.uint8)
                    self._rgbacache = x
                else:
                    x = self._rgbacache
                im = _image.frombyte(x[yslice, xslice, :], 0)
                if self._A.ndim == 2:
                    im.is_grayscale = self.cmap.is_gray()
                else:
                    im.is_grayscale = False
            self._imcache = im
        else:
            im = self._imcache

        return im, xmin, ymin, dxintv, dyintv, sx, sy
开发者ID:SungSingSong,项目名称:matplotlib,代码行数:85,代码来源:image.py


示例7: make_image

    def make_image(self, magnification=1.0):
        if self._A is None:
            raise RuntimeError('You must first set the image array or the image attribute')

        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
        numrows, numcols = self._A.shape[:2]
        if sx > 2:
            x0 = (self.axes.viewLim.x0-xmin)/dxintv * numcols
            ix0 = max(0, int(x0 - self._filterrad))
            x1 = (self.axes.viewLim.x1-xmin)/dxintv * numcols
            ix1 = min(numcols, int(x1 + self._filterrad))
            xslice = slice(ix0, ix1)
            xmin_old = xmin
            xmin = xmin_old + ix0*dxintv/numcols
            xmax = xmin_old + ix1*dxintv/numcols
            dxintv = xmax - xmin
            sx = dxintv/self.axes.viewLim.width
        else:
            xslice = slice(0, numcols)

        if sy > 2:
            y0 = (self.axes.viewLim.y0-ymin)/dyintv * numrows
            iy0 = max(0, int(y0 - self._filterrad))
            y1 = (self.axes.viewLim.y1-ymin)/dyintv * numrows
            iy1 = min(numrows, int(y1 + self._filterrad))
            if self.origin == 'upper':
                yslice = slice(numrows-iy1, numrows-iy0)
            else:
                yslice = slice(iy0, iy1)
            ymin_old = ymin
            ymin = ymin_old + iy0*dyintv/numrows
            ymax = ymin_old + iy1*dyintv/numrows
            dyintv = ymax - ymin
            sy = dyintv/self.axes.viewLim.height
        else:
            yslice = slice(0, numrows)

        if xslice != self._oldxslice or yslice != self._oldyslice:
            self._imcache = None
            self._oldxslice = xslice
            self._oldyslice = yslice

        if self._imcache is None:
            if self._A.dtype == np.uint8 and len(self._A.shape) == 3:
                im = _image.frombyte(self._A[yslice,xslice,:], 0)
                im.is_grayscale = False
            else:
                if self._rgbacache is None:
                    x = self.to_rgba(self._A, self._alpha)
                    self._rgbacache = x
                else:
                    x = self._rgbacache
                im = _image.fromarray(x[yslice,xslice], 0)
                if len(self._A.shape) == 2:
                    im.is_grayscale = self.cmap.is_gray()
                else:
                    im.is_grayscale = False
            self._imcache = im

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

        fc = self.axes.patch.get_facecolor()
        bg = mcolors.colorConverter.to_rgba(fc, 0)
        im.set_bg( *bg)

        # image input dimensions
        im.reset_matrix()
        numrows, numcols = im.get_size()
        if numrows < 1 or numcols < 1:   # out of range
            return None
        im.set_interpolation(self._interpd[self._interpolation])

        im.set_resample(self._resample)

        # the viewport translation
        tx = (xmin-self.axes.viewLim.x0)/dxintv * numcols
        ty = (ymin-self.axes.viewLim.y0)/dyintv * numrows

        l, b, r, t = self.axes.bbox.extents
        widthDisplay = (round(r*magnification) + 0.5) - (round(l*magnification) - 0.5)
        heightDisplay = (round(t*magnification) + 0.5) - (round(b*magnification) - 0.5)
        im.apply_translation(tx, ty)

        # resize viewport to display
        rx = widthDisplay / numcols
        ry = heightDisplay  / numrows
        im.apply_scaling(rx*sx, ry*sy)
        im.resize(int(widthDisplay+0.5), int(heightDisplay+0.5),
                  norm=self._filternorm, radius=self._filterrad)
        return im
开发者ID:zoccolan,项目名称:eyetracker,代码行数:99,代码来源:image.py


示例8: _byte2image

 def _byte2image(self, img):
     image = frombyte(np.flipud(img), 1)
     #image.flipud_out()
     return image
开发者ID:piScope,项目名称:piScope,代码行数:4,代码来源:backend_wxagg_mod.py



注:本文中的matplotlib._image.frombyte函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python _image.pcolor函数代码示例发布时间:2022-05-27
下一篇:
Python _image.fromarray函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap