1

I have two images img1 and img2 of shape (20,20,3), that I have read using OpenCV.

I have applied the following statement on the two images:

np.stack([img1,img2], axis=2)

and got the following shape:

(20, 20, 2, 3)

Does that mean that we now have 2 20x20x3 images? Are they (images and their channels) like put beside each other?

Thanks.

2
  • It depends how you define "beside" Commented Feb 10, 2018 at 6:20
  • @Eric I mean horizontally adjacent Commented Feb 10, 2018 at 6:46

1 Answer 1

2

No you have created a new axis, your array now has four dimensions.

From the Documentation:

numpy.stack(arrays, axis=0)

Join a sequence of arrays along a new axis.

In order to get what you want try numpy.hstack:

a = np.zeros((20, 20, 3))

b = np.ones((20, 20, 3))

c = np.hstack((a, b))

print(c.shape)

(20, 40, 3)

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.