Python – 使用Matplotlib处理PNG图像

Python – 使用Matplotlib处理PNG图像

Matplotlib是Python中用于2D数组可视化的惊人图形库。Matplotlib是一个多平台数据可视化库,它建立在NumPy数组上,并设计为与更广泛的SciPy堆栈一起使用。

示例

    #应用伪色
    #从Matplotlib导入pyplot和image
    import matplotlib.pyplot as plt
    import matplotlib.image as img
    #读入PNG图像
    im = img.imread('imR.png')
    #应用伪色
    #默认的colormap值被使用
    lum = im[:, :, 0]
    #显示图像
    plt.imshow(lum)
    # 加上颜色栏
    #从Matplotlib导入pyplot和image
    import matplotlib.pyplot as plt
    import matplotlib.image as img
    #读入PNG图像
    im = img.imread('imR.png')
    lum = im[:, :, 0]
    #将colormap设置为hot
    plt.imshow(lum, cmap ='hot')
    plt.colorbar()
    #插值
    #从PIL和Matplotlib导入
    from PIL import Image
    import matplotlib.pyplot as plt  
    #读入PNG图像
    img = Image.open('imR.png')
    #调整图像大小
    img.thumbnail((50, 50), Image.ANTIALIAS)
    imgplot = plt.imshow(img)
    #bicubic插值
    #从Matplotlib导入pyplot
    import matplotlib.pyplot as plt
    #从PIL导入图像
    from PIL import Image
    #读入图像
    img = Image.open('imR.png')
    img.thumbnail((30, 30), Image.ANTIALIAS)
    #使用bicubic进行插值
    imgplot = plt.imshow(img, interpolation ='bicubic')#使用sinc插值的值
    #使用sinc插值
    #从PIL和Matplotlib导入
    from PIL import Image
    import matplotlib.pyplot as plt
    #读入图像
    img = Image.open('imR.png')
    img.thumbnail((30, 30), Image.ANTIALIAS)
    #使用sinc进行插值
    imgplot = plt.imshow(img, interpolation ='sinc')
Python

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册