I'm trying to learn how to work with image data in numpy arrays. Currently I have a single array with 4 channels where the shape is (221, 95, 4).
I'm trying to subdivide this array into smaller arrays with a fixed window size, and using a window stride, to get a new shape of (n, 20, 20, 4).
So far I have this, but am getting confused:
step = 20
win_size = 10
#stacked is a 3D array
x_steps = (stacked.shape[0]-win_size)//step
y_steps = (stacked.shape[0]-win_size)//step
print(x_steps)
print(y_steps)
tiles = []
for i in range(x_steps):
mini = stacked[i*step : i*step+win_size, i*step : i*step+win_size ,:]
tiles.append(mini)
tiles = np.array(tiles)
I think I'm close, but how do I take into account both the x and y direction of the window?
question from:
https://stackoverflow.com/questions/65864922/slicing-a-3d-numpy-array-using-on-a-fixed-window-and-stride 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…