I have a JPEG image and I need to calculate the average value of each raster (red, blue and green) as fast as possible. When I try to use two for loops to access each pixel and add the values, the process takes quite long (about 30 seconds). Is there a way to calculate the average raster values fast (maybe using numpy and OpenCV)? The code I'm using is given below:
for i in range(width):
for j in range(height):
pix = im.getpixel((i,j))
redValues = redValues + pix[0]
greenValues = greenValues + pix[1]
blueValues = blueValues + pix[2]
im.getpixel((i,j))call but I'm not sure. - m4p85r