将图像转换为字节并拆分为片段

convert image to byte and split into fragments

我正在尝试在 python 中创建图像拆分器。这个想法是以 'rb' 模式读取图像。首先,是否可以将字节流拆分成片段,然后将它们组合起来生成原始图像?如果是,我该如何拆分文件。

到目前为止,这是我的代码

import re

data = open('py.png','rb').read()
image_array = re.split(r'\',data)
print(image_array)

因为这些是我不能使用的字节 re.split。如何拆分存储在 data vairable

中的数据

正在查找 Python 图像库(http://effbot.org/imagingbook/pil-index.htm) would be a good place to start, possibly combining it with NumPy (http://docs.scipy.org/doc/numpy/index.html)。

from PIL import Image
import numpy as np

im = Image.open('py.png')
image_array = np.array(im)

然后您可以将 image/array 拆分为:

splitA = image_array[:10,:]
splitB = image_array[11:20,:]
etc...