2 回答

TA贡献1835条经验 获得超7个赞
你并不完全需numpy要这样做,虽然我不知道是否有必要使用它,但有一种方法可以用简单的 Python 做到这一点:
from PIL import Image
src_image = Image.open('test_image.png') # Image of size (28,28)
pixels = list(src_image.getdata()) # Get all pixel in 1D array.
dst_image = Image.new('RGB', (1,src_image.size[0] * src_image.size[1])) # Create new image with new size.
dst_image.putdata(pixels) # Place pixels in the new image.
dst_image.save('result.png') # Save the new image.

TA贡献1773条经验 获得超3个赞
如果您的问题是如何将多个图像连接成一个,其中每一行代表原始数据集中的一个图像,那么 reshape + concatenate 应该可以解决问题:
# all_images is a list / iterator of 28x28x3 numpy arrays
final_image = np.concatenate([img.reshape(1, -1, 3) for img in all_images])
添加回答
举报