0

I have an image that is currently in a numpy array. This is useful for my work as I with to do things with the images fourier transform.

Currently I am interested in viewing the fourier transform of lots of bits of the image. The image is a 512x512 array in numpy and I would like to split it into small boxes. I am thinking of splitting it into 4 boxes then 16 boxes.

I have found np.array_split however this appears to only split the array into strips. As a result I am just calling it multiple times as shown below (where Real is the input array of 512,512)

H1, H2 = np.array_split(Real, 2, axis=0)
B1, B2 = np.array_split(H1, 2, axis=1)
B3, B4 = np.array_split(H2, 2, axis=1)

fig, ax = plt.subplots(2, 2)
ax[0,0].imshow(B1, cmap='Greys')
ax[0,1].imshow(B2, cmap='Greys')
ax[1,0].imshow(B3, cmap='Greys')
ax[1,1].imshow(B4, cmap='Greys')

plt.show()

When I split them into 16 this feels like it is going to look very untidy. I was wondering if I am not noticing another numpy function i could use?

thank you

j.t.2.4.6
  • 178
  • 1
  • 11
  • 1
    Does this answer your question? [Slice 2d array into smaller 2d arrays](https://stackoverflow.com/questions/16856788/slice-2d-array-into-smaller-2d-arrays) – effy Mar 17 '20 at 09:53
  • If you have `skimage` then just use [`view_as_blocks`](https://scikit-image.org/docs/dev/api/skimage.util.html#skimage.util.view_as_blocks) – Brenlla Mar 17 '20 at 09:56
  • @effy thanks for the link unfortunately that function is not working correctly for me – j.t.2.4.6 Mar 17 '20 at 10:48

0 Answers0