I am trying to segment a colour image using Mean-Shift clustering using sklearn. I have read the image into a numpy array, however I want to extract each colour channel (R,G,B) so that I can use each as a variable for classification.
I have found the following code online, which extracts the RGB colour channels of an image which is represented as a numpy array.
red = image[:,:,2] green = image[:,:,1] blue = image[:,:,0]
However, I don't understand how this code works. What do the 2, 1 and 0 mean? Any insights are appreciated.
A normal picture you will have 3 layer, Red Green and Blue.
When you read an picture by a tool (example is open-cv), it will return for you a numpy array with shape (width_image x length_image x channels).
The arrange of channels depend on what you used, if you read by open-cv it will be Blue is first then Green then Red, else if you use matplotlib.pyplot.imread it will be Red-Green-Blue.
That code wrote like that because they read picture by open-cv
- How can I print literal curly-brace characters in python string and also use .format on it?
- How to access index in function for applymap in pandas?
- Finding all possible permutations of a given string in python
- Using regex to alter digits pandas
- regaining original line breaks pandas \n
- Error when using two matching foreignKeys in django
- Proper use of method overriding with multiple inheritance?
- Python dynamically define function within function
- Lazy logger message string evaluation