Construct Image From 4D List
Solution 1:
IIUC one way to solve it would be with reshaping and permuting dimensions.
1) Reshape to split the last dimension into two dimensions.
2) Transpose to bring the last two split dims come next to the first two dims).
3) Finally reshape again to merge the first two dims and next two dims into one dim each.
Thus, we would have an implementation like so -
np.array(myList).reshape(10,10,3,8,8).transpose(0,3,1,4,2).reshape(80,80,3)
Solution 2:
You could try this through np.concatenate
and nested list comprehensions, e.g.:
arr = np.array(mylist)
arr2 = np.concatenate([ np.concatenate([arr[...,i + 8*j] for i in np.arange(8)],axis=0) for j in np.arange(8)],axis=1 )
print(arr2.shape)
gives
(80, 80, 3)
The list comprehensions split the full array of images into individual images stored in lists of length 8, and the concatenate then forms an array from these lists where each image is stored sequentially.
Note. It should be relatively easy to change the way you want to tile your images too by just changing the numbers used. For example if you wanted a 12x4 tiling instead of 8x8
arr2 = np.concatenate([ np.concatenate([arr[...,i + 12*j] for i in np.arange(12)],axis=0) for j in np.arange(4)],axis=1 )
Post a Comment for "Construct Image From 4D List"