【问题标题】:How to plot single pixel values from 3d NumPy array?如何从 3d NumPy 数组中绘制单个像素值?
【发布时间】:2020-02-20 16:37:21
【问题描述】:

我有一叠 7 张 288 x 288 像素的图像,我已将它们转换为 3d NumPy 数组

newarray.shape = (288, 288, 7)

我想从 7 个图像中的每一个中绘制一个特定的像素值,并将其绘制为一个图形,其中 y 轴显示像素值,x 轴显示图像编号。

【问题讨论】:

    标签: python numpy


    【解决方案1】:
    from matplotlib import pyplot as plt
    import numpy as np
    
    # NumPy array storing images
    images = np.random.randint(0, 255, (288, 288, 7), np.uint8)
    
    # Get pixel values across all images of pixel of interest
    x, y = (8, 3)
    pixels = images[y, x, :]
    
    # Plot
    plt.plot(np.arange(images.shape[2]), pixels)
    plt.ylim(0, 255)
    plt.title('Pixel values for x=' + str(x) + ', y=' + str(y))
    plt.tight_layout()
    plt.show()
    

    输出:

    希望有帮助!

    ----------------------------------------
    System information
    ----------------------------------------
    Platform:    Windows-10-10.0.16299-SP0
    Python:      3.8.1
    Matplotlib:  3.2.0rc3
    NumPy:       1.18.1
    ----------------------------------------
    

    【讨论】:

    • 与我所拥有的惊人地相似,甚至到代码 cmets ?
    • @MarkSetchell 思想相似 - 字面意思。 ;-)
    • 工作就像一个魅力。谢谢@HansHirse 和 Mark Setchell。确实是伟大的思想。
    猜你喜欢
    • 2021-07-16
    • 2017-03-14
    • 2020-09-25
    • 1970-01-01
    • 2021-05-05
    • 2019-02-22
    • 2023-04-01
    • 2017-01-22
    • 1970-01-01
    相关资源
    最近更新 更多