I'm currently working with fMRI data in the form of 3D numpy arrays. However, my arrays are of various shapes: from (60, 40, 20, 20) to (64, 64, 40, 20) to values like (96, 96, 60, 20). In order to use these fMRI images in a machine learning framework, I need to ensure that all of these numpy arrays are the same shape.
This is what I'm doing right now:
for f in dataset:
img_data_arr.resize (64, 64, 40, 20)
I'm using the resize function to reshape all of the arrays into (64, 64, 40, 20) shape. However, I've heard that if the image is larger than the shape given, it'll just replace the empty boxes with repeated values. For example:
First array:
[[1 2 3]
[4 5 6]]
The shape of first array:
(2, 3)
Second array:
[[1 2]
[3 4]
[5 6]]
The shape of second array:
(3, 2)
Resize the second array:
[[1 2 3]
[4 5 6]
[1 2 3]]
Is there any way to resize smaller arrays so that the empty spaces are filled with 0s? Thank you!
numpyresize(function or method) is appropriate for your purpose. And test anything with small enough arrays so that you can actually what's going on. Image processing packages (cv2etc) have better resizing functions.