0

I want to cycle through top to bottom instead of left to right on an image. (0,0 starts from top left)

    for y in range(image.height): # getting pixels
        for x in range(image.width):
             pixel = image.get_pixel(y,x) #invert coordinates to move down

I tried inverting the coordinates but it doesn't work on images that are not square.

Alvaro
  • 3
  • 1
  • I would prefer using numpy package for manipulating arrays. https://stackoverflow.com/questions/10148818/numpy-how-to-iterate-over-columns-of-array – Apu Jul 09 '21 at 17:20
  • What are you actually trying to do, please? Iterating through images with `for` loops in Python should really be avoided if possible. – Mark Setchell Jul 09 '21 at 17:28

1 Answers1

0

Inverting the coordinates doesn't work on an image that is not square because you go beyond the width or height. For example, in a 4x6 image, you can get a pixel at x, y == 4, 6, but if you ask for the pixel at x, y == 6, 4, it does not exist -- there is no pixel at x == 6.

Hammurabi
  • 1,141
  • 1
  • 4
  • 7