zoukankan      html  css  js  c++  java
  • python的skimage库 图像读取显示

    单幅图像读取并显示

    代码

    """
    读取图像并显示
    """
    import matplotlib.pyplot as plt
    import matplotlib
    
    from skimage import data
    
    matplotlib.rcParams['font.size'] = 18
    
    images = ('astronaut',
              'binary_blobs',
              'brick',
              'colorwheel',
              'camera',
              'checkerboard',
              'chelsea',
              'clock',
              'coffee',
              'coins',
              'grass',
              'gravel',
              'horse',
              'logo',
              'page',
              'text',
              'rocket',
              )
    
    
    for name in images:
        # getattr(object, name[, default])
        # 函数功能是从对象object中获取名称为name的属性,等效与调用object.name。
        caller = getattr(data, name)
        # 得到图像们
        image = caller()
        plt.figure()
        plt.title(name)
        if image.ndim == 2:
            plt.imshow(image, cmap=plt.cm.gray)
        else:
            plt.imshow(image)
    
    plt.show()
    

    效果

    程序显示的图像

    读取显示立体图像;同时显示多幅图像

    代码

    """
    ===============
    Specific images
    ===============
    
    """
    import matplotlib.pyplot as plt
    import matplotlib
    from skimage import data
    
    matplotlib.rcParams['font.size'] = 18
    
    
    ######################################################################
    # 立体图像显示
    # Stereo images
    # =============
    
    fig, axes = plt.subplots(1, 2, figsize=(8, 4))
    ax = axes.ravel()
    
    images = data.stereo_motorcycle()
    ax[0].imshow(images[0])
    ax[1].imshow(images[1])
    
    # tight_layout会自动调整子图参数,使之填充整个图像区域。这是个实验特性,可能在一些情况下不工作。
    # 它仅仅检查坐标轴标签、刻度标签以及标题的部分。
    fig.tight_layout()
    plt.show()
    
    
    ######################################################################
    # 同时显示多幅人脸图像
    # Faces and non-faces dataset
    # ===========================
    #
    # A sample of 20 over 200 images is displayed.
    
    fig, axes = plt.subplots(4, 5, figsize=(20, 20))
    ax = axes.ravel()
    images = data.lfw_subset()
    for i in range(20):
        ax[i].imshow(images[90+i], cmap=plt.cm.gray)
        ax[i].axis('off')
    fig.tight_layout()
    plt.show()
    

    结果

    立体图像显示
    同时显示多幅图像

  • 相关阅读:
    自我介绍 Self Introduction
    HDU1864 最大报销额
    HDU2955 Robberies
    Sicily 1509. Rails
    Sicily 1031. Campus
    Sicily 1090. Highways
    Sicily 1034. Forest
    Sicily 1800. Sequence
    Sicily 1150. 简单魔板
    CodeVS4919 线段树练习4
  • 原文地址:https://www.cnblogs.com/wojianxin/p/12631049.html
Copyright © 2011-2022 走看看