如何仅获取 plt.imread 的 rgb?

Tla*_*-ES 5 python numpy matplotlib

你好,我正在阅读一张图片

plt.imread('photo.png') 
Run Code Online (Sandbox Code Playgroud)

这将返回以下形状:

100, 100, 4

我该怎么办才能只得到rgb,也就是说

100, 100, 3

She*_*ore 6

尝试使用以下省略 alpha 参数的方法从 RGBA 序列 (100, 100, 4) 中获取前三个值,即 RGB 序列 (100, 100, 3)。根据文档imread对于 RGB 图像返回 (M, N, 3),对于 RGBA 图像返回 (M, N, 4)。

rgb = plt.imread('photo.png')[:,:,:3]
Run Code Online (Sandbox Code Playgroud)