plot.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:circletracking 作者: caspervdw 项目源码 文件源码
def imshow(image, ax=None, mpp=1., origin=(0, 0), ax_labels=False, **kwargs):
    """Show an image. Origin is in pixels."""
    _imshow_style = dict(origin='lower', interpolation='nearest',
                         cmap=plt.cm.gray, aspect='equal')
    _imshow_style.update(kwargs)
    if not is_rgb(image, ndim=2):
        try:
            from pims import to_rgb
        except ImportError:
            raise ImportError("Imshow requires PIMS to display a non-RGB image")
        image = to_rgb(image, kwargs.pop('colors', None), normed=False) / 255.
    shape = image.shape[:2]
    mpp = validate_tuple(mpp, ndim=2)
    origin = validate_tuple(origin, ndim=2)

    # extent is defined on the outer edges of the pixels
    # we want the center of the topleft to intersect with the origin
    extent = [(origin[1] - 0.5) * mpp[1],
              (origin[1] + shape[1] - 0.5) * mpp[1],
              (origin[0] - 0.5) * mpp[0],
              (origin[0] + shape[0] - 0.5) * mpp[0]]

    ax.imshow(image, extent=extent, **_imshow_style)
    ax.set_xlim(extent[0], extent[1])
    ax.set_ylim(extent[3], extent[2])

    if ax_labels:
        if mpp == 1.:
            fmt = '{} [px]'
        elif mpl.rcParams['text.usetex']:
            fmt = r'{} [\textmu m]'
        else:
            fmt = r'{} [\xb5m]'
        ax.set_xlabel(fmt.format('x'))
        ax.set_ylabel(fmt.format('y'))
    return ax
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号