1

I want to crop RGB images such that the upper half part of the image is removed. After cropping I want to concatenate the image to a numpy array (here images). But I get the following error ValueError: all the input array dimensions except for the concatenation axis must match exactly. I tried multiple things but I don't seem to have luck with any of my attempts.

My code looks like

images = np.zeros((1, 32, 64, 3))
image = get_image()  # has shape 1, 64, 64, 3
# removing the first coordinate didn't change the error.
images = np.concatenate([images, image[:, 32:63, :, :]], axis=0)  

EDIT: The following modifications in image[:, 32:63, :, :] did not resolve the problem

a) [:, 32:63, :, :] -> [32:63, :, :]

b) [:, 32:63, :, :] -> [:][32:63][:][:]

1 Answer 1

1

You should do

images = np.zeros((1, 32, 64, 3))
image = get_image()  # has shape 1, 64, 64, 3
# removing the first coordinate didn't change the error.
images = np.concatenate([images, image[:, 32:, :, :]], axis=0)  

As 32:63 leaves out the last element. (32:64 would be possible too)

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I get the desired output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.