0
我有它们的图像的RGB值的字节的阵列。例如,数组的前三个字节将是左上像素的RGB值。即a[0]
是R,a[1]
是G并且a[2]
是B.最快分割图像成瓦片的方法
该图像实际上是图像的网格,通常以2x2形式排列。这是一个例子。
我目前使用PIL到图像分割成4个子图像。这是我目前使用的代码。
def split_image_to_tiles(im, grid_width, grid_height):
#This treats the image `im` as a square grid of images.
w, h = im.size
w_step = w/grid_width
h_step = h/grid_height
tiles = []
for y in xrange(0, grid_height):
for x in xrange(0, grid_width):
x1 = x * w_step
y1 = y * h_step
x2 = x1 + w_step
y2 = y1 + h_step
t = im.crop((x1, y1, x2, y2))
tiles.append(t)
return tiles
这是有效的,但它并不是特别快。有更好还是更快的方法?
你为什么要拆分它们?将其他图像视为填充。 – onemasse