0

I have a numpy array Data of 1D of size [36*64]. Basically, I have 36, 8*8 images stored in a 1D array. Each image is stored in Height(8)*Width(8) format.

For e.g.: ith image is stored from Data[i*8*8 : (i*8*8 + 8*8)].

Now I want to make a tile of images from the given 36 images, i.e. 6 images stacked on top of each other. Example.

Basically, I want to transform my 1D Numpy array into a 2D array of images in the above mentioned format.

I would prefer answers with just using Numpy methods.

pseudo_teetotaler
  • 1,485
  • 1
  • 15
  • 35

2 Answers2

0

To convert your 1D array to 2D use reshape as shown with an example:

# Creating 36 images each of shape 8x8
initial_1D = np.random.randn(2304).reshape(36, 8, 8)

Collage can be formed using PIL. For clear understanding refer here Making a collage in PIL

meW
  • 3,832
  • 7
  • 27
0

If I understand you correctly, you can do it like this

# make example data
a = np.linspace(0, 36*64-1, 36*64)
print(a[:64])
print(a.shape)

# reshape 1D to 3D array
b = a.reshape(-1, 8, 8)
# look at first "image"
print(b[0])

If I did not understand you correctly, you need to put the -1, 8, 8 in a different order.

Louic
  • 2,403
  • 3
  • 19
  • 34