0

Can someone please explain to me what would the following line do?

bgr = img[:,:,:3]
1
  • That copies all of the first and second dimensions, but only the first 3 elements of the 3rd dimension. If you had a (5,5,5) array, you would end up with a (5,5,3) array. Imagine if you had an image that was a (640,480,3) array; img[:,:,:2] would keep the R and G values, but not the B. Commented Jun 8, 2021 at 6:26

1 Answer 1

4

What you want to look for here is "slicing" and "indexing". Have a look on those links:

Basically, img is a 3-dimensional array and you are selecting all elements of axis "0" and "1", but only the first 3 elements ([0,1,2])of axes "2".

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.