Skip to content Skip to sidebar Skip to footer

Python Iterate Through Pixels Of Image

I'm trying to iterate through pixels of an image. I set the size and then use a for loop, however I get a type error: object not iterable. I have imported PIL and Image w=100 h=200

Solution 1:

The type error issue is coming from the fact that w and h and integers and therefore cannot be iterated through. The construct for i in thing: loops through every item in thing, so if thing is a list [2, 5, 6], for example, i will be 2 and then 5 and then 6.

What you want is for a in range(w) and for b in range(h), which will allow you to iterate through all integers from 0 to w or h.


Post a Comment for "Python Iterate Through Pixels Of Image"