[英]Removing the last value in the 2D array in Python
I am running this code, it outputs the value of the image as an Array but with four values the RGB and Alpha, how do I remove the last value so its just the RGB im dealing with. 我正在运行此代码,它将图像的值作为Array输出,但是RGB和Alpha具有四个值,我如何删除最后一个值,以便仅处理RGB im。
from PIL import Image, ImageFilter
import numpy as np
ImageLocation = Image.open("images/numbers/0.1.png")
#Creates an Array [3d] of the image for the colours
ImageArray = np.asarray(ImageLocation)
print(ImageArray)
This is my output is for each pixel and I only want the RGB to be output not the 4th Column. 这是我对每个像素的输出,我只希望输出RGB,而不是第4列。
[[[255 255 255 255]
[255 255 255 255]
[ 0 0 0 255]
[ 0 0 0 255]
[ 0 0 0 255]
[ 0 0 0 255]
[255 255 255 255]
[255 255 255 255]]
You can slice numpy arrays like so: 您可以像这样对numpy数组进行切片:
rgb = my_array[:,:,:3]
Also since you're using PIL: 另外,由于您使用的是PIL:
im = Image.open("path/to/image")
rgb = im.convert('RGB')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.