w, h = im.size
for i in range(w):
    for j in range(h):
        r, g, b = im.getpixel((i, j))
if r != g != b:
    return False
return True
How to check whether a jpeg image is color or gray scale using only Python stdlib