I'm trying to extract patches from a 3D image as training data for a neural network. But am having trouble reshaping the patches for larger images. I'm currently using view_as_windows, but am open to other methods if they prove more useful.
An example of what my code would look like:
import numpy as np
from skimage.util import view_as_windows
kernel_size = 17
V = np.random.rand(150,150,150)
X = view_as_windows(V,(kernel_size,kernel_size,kernel_size),step=1)
This creates a numpy array that has the size(134,134,134,17,17,17)
. Now I would ideally like to reshape this to be of size (2406104,4913)
, but trying to reshape results in an allocation error:
X = X.reshape(134**3,17**3)
MemoryError: Unable to allocate 88.1 GiB for an array with shape (134, 134, 134, 17, 17, 17) and data type float64
Is there a way to reshape my patches or is there a better general way to go about this?