0

i need to do this Create 3 lists, one for red, one for green and one for blue, each containing 256 elements all initialized to 0 For every pixel in the image: Get the amount, r, of red from the pixel Increment position r in the red list Get the amount, g, of green from the pixel Increment position g in the green list Get the amount, b, of blue from the pixel Increment position b in the blue list Return the red, green and blue lists i wrote the code

def colour(): red=[0]*256 for x in range(0, getWidth(img)): for y in range (0, getHeight(img)): r= getPixel(img,getWidth(img) ,getHeight(img)) red.append(r) return (red) but for some reason i am unable to see the list

2 Answers 2

1

You appear to be getting the same value from the image each time. You should probably be using x and y instead of getWidth(img) in the getPixel function inside your loop.

Also, since you are appending in the loop (and not writing to a certain position in the list red) you should just initialize an empty loop and not a bunch of zeroes. I'd try:

def colour():
    red = []
    for x in range(getWidth(img)):
        for y in range (getHeight(img)):
            r= getPixel(img,x,y)
            red.append(r)
    return red
Sign up to request clarification or add additional context in comments.

Comments

0

It's easy, Take a look at this example.

>>> f= [9,5,4,3,2,7]
>>> g= ["p","o"]
>>> h= ["t","g"]
>>> def c():
    return f , g ,h

>>> c()
([9, 5, 4, 3, 2, 7], ['p', 'o'], ['t', 'g'])

Just remove the brackets around red , and if u want all the three list to be passed just do

return red, green ,blue

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.