Python Forum
grayscale image processing - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: grayscale image processing (/thread-5849.html)

Pages: 1 2


RE: grayscale image processing - heiner55 - Oct-26-2017

You still have to find the maximum yourself.
As Mekire already said: This solution is slow.

from PIL import Image
img  = Image.open('grey.jpg')

for row in range(img.height):
    counter = 0
    for col in range(img.width):
        pixel = img.getpixel((col,row))
        red   = pixel[0]; green = pixel[1]; blue  = pixel[2]
        grey  = (red + green + blue) // 3
        if grey > 200:
            counter += 1
    if counter != 0:
        print("row %d: %d" % (row, counter))