I have a python code that loops through an image and copies them to an array in RGBA format, however the code is incredibly slow, 10 images each 256x256 took more than 5 minutes to process, any ideas how this code can be improved?
self.pixelsArray = array('B')
def extractPixelsFromImage(self):
pixels = self.image.pixels
for y in range(self.height):
for x in range(self.width):
i = (x + (self.height-1-y)*self.width) * 4
r = int (max (0, min (255, 255 * pixels [i ])))
g = int (max (0, min (255, 255 * pixels [i + 1])))
b = int (max (0, min (255, 255 * pixels [i + 2])))
a = int (max (0, min (255, 255 * pixels [i + 3])))
self.pixelsArray.append(r)
self.pixelsArray.append(g)
self.pixelsArray.append(b)
self.pixelsArray.append(a)