I have an MNIST dataset of the shape (60000, 28, 28) and I need a way to crop and shift the images such that the middle pixel value in each image is the same as that in the cropped images. I have extracted the first and last rows and columns of the black pixels in each image. I need an output array of shape (60000, 20, 20) containing the cropped images.
I have tried using this code to crop out all images:
cropped = train_images_raw[:, first_ink_rows[1]:last_ink_rows[1]+1, first_ink_cols[1]:last_ink_cols[1]+1]
but the shape is only fixed for a specific black pixel row and column.
How can shift the image to fit in a boundary box of the size (20, 20) and still retain the value of the mid pixel?