I am loading an image into python e.g.
image = cv2.imread("new_image.jpg")
How can i acccess the RGB values of image?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can do
or equivalently
image[y][x][c].and it will return the value of the pixel in the
x,y,ccoordinates. Notice that indexing begins at0. So, if you want to access the third BGR (note: not RGB) component, you must doimage[y, x, 2]whereyandxare the line and column desired.Also, you can get the methods available in Python for a given object by typing
dir(<variable>). For example, after loadingimage, rundir(image)and you will get some usefull commands:Usage:
image.mean()