If you are asking about a usage convention, in image processing for machine learning, I usually see each image flattened so that each image is one long row, in row-major order followed by channel order. Numpy has obj.flatten() command to make this easy. Then to retrieve the middle channel, Numpy slicing or indexing can be used. Each processed batch has many images (rows), and each image is one very long flattened row.
Example:
b = a.flatten()
print(b)
# output array([1, 2, 3, 4, 5, 6, 7, 8, 9])
channel2 = b[3:6]
print(channel2)
# output array([4, 5, 6])
For other use cases, there may be a different convention.
Longer example using a 3x3 image array with 3 channels.
Note numerical values are in row-major order followed by channel order.
img_a = np.arange(0, 27).reshape(3, 3, 3)
''' output
array([[[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8]],
[[ 9, 10, 11],
[12, 13, 14],
[15, 16, 17]],
[[18, 19, 20],
[21, 22, 23],
[24, 25, 26]]])
'''
# Flatten into one long row
row_a = img_a.flatten()
# output array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
# 17, 18, 19, 20, 21, 22, 23, 24, 25, 26])
# Select middle channel using Numpy slicing
channel_mid = row_a[9:18]
# output array([ 9, 10, 11, 12, 13, 14, 15, 16, 17])
# Convert middle channel back into a matrix shape (if needed).
matrix_mid = channel_mid.reshape(3, 3)
''' output
array([[ 9, 10, 11],
[12, 13, 14],
[15, 16, 17]])
'''
a[:,:,1]
gives you a(200,200)
array,a[:,:,[1]]
gives you(200,200,1)
. You can also doa[...,1]
. – Quang Hoang