1

When I read a colour image in OpenCV, it is showing the dimensions as 256x256x3. But I need to pass it as 3x256x256 array to my neural network. How do I change the array shape, retaining the pixel locations in BGR.

1 Answer 1

2

You can simply transpose the array. For an example, my picture is a 10 x 10 picture:

import numpy as np

#my picture
wrong_format = np.arange(300).reshape(10,10,3)

correct_format = wrong_format.T 

If it works properly, then correct_format(0,1,1) should be equal to wrong_format(1,1,0). And we can see that it is:

correct_format(0,1,1) == wrong_format(1,1,0)

True

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

Comments

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.