python - 如何从 3d NumPy 数组绘制单个像素值?

标签 python numpy

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

newarray.shape = (288, 288, 7)

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

最佳答案

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()

输出:

Output

希望有帮助!

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

关于python - 如何从 3d NumPy 数组绘制单个像素值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60311884/

相关文章:

python - Python 中的插值 - 绘图

python - 如何对图像进行人脸识别并确定其中的人脸是否已知?

python - 如何使用python计算周期数

python - 为什么列表理解中的元组需要括号?

python - 基类变量不存储派生类设置的值

python - Pandas 按行添加另一列

python - 在 Python 中使用 Pandas 从每列中获取前 4 个最大值

python - 值错误 : Unable to determine number of fit parameters. "Problem in curve fitting"

python - 我需要在变量中拆分一个值

python - 帮助 "Install"使用 WGET 的 Python 模块