Create a dataset of 3D patches of multiple features

Hello,

I have a list of brain feature volumetric maps (thickness, sulc) with size (241, 336, 283) for multiple subjects, I want to create dataset of feature maps patches and label(if it intersect label mask) for classification problem.

all_patch = np.empty(1,num_of_patches_per_sub,36,36,36)

patchs = 64

for x in range(0, feature.shape[0]-patchs//2, patchs):
        for y in range(0, feature.shape[1]-patchs//2, patchs):
            for z in range(0, feature.shape[2]-patchs//2, patchs):

                patch_feature = feature[x: min(x+patchs, feature.shape[0]),
                                       y: min(y+patchs, feature.shape[1]),
                                       z: min(z+patchs, feature.shape[2]),]
                patch_label = label_data[x: min(x+patchs, feature.shape[0]),
                                   y: min(y+patchs, feature.shape[1]),
                                   z: min(z+patchs, feature.shape[2]),]

               all_patches = np.concatenate([all_patch, patch_feature])

How can patch_feature and label be saved for training set?:
X = np.array(feature1[batch1, batch2, …], feature2[batch1,batch2, …], feature3[batch1, batch2, …], [batch1, batch2, …])
Y = np.array([1,1,1,1], [0,0,0,0])

Sorry, is your question about the creation of X and Y, or about the proper way to write them to disk ?
Bertrand

Hi, my question is how to assign feature array to X and labels array to Y.
V

Sorry, I’m afraid I don’t understand: I guess that all you need is to create Numpy arrays with the right shape and content. What prevents you from doing it ?

The Value error I can’t resolve in concatenate:

ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 3 dimension(s) and the array at index 1 has 5 dimension(s)

Then, all the question boils down to choosing what are the shapes of the arrays you want to use. Then you can adapt these dimensions by concatenating or flattening data as you fancy. np.rollaxis can also be very useful in that context.
I cannot run the snippet your provided, but my best advice is to follow a Numpy tutorial.
Best,
Bertrand