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