Fastest way to count non-zero pixels using Python and Pillow
Here's your implementation using Pillow:

def count_nonblack_pil(img):
    """Return the number of pixels in img that are not black.
    img must be a PIL.Image object in mode RGB.

    """
    bbox = img.getbbox()
    if not bbox: return 0
    return sum(img.crop(bbox)
               .point(lambda x: 255 if x else 0)
               .convert("L")
               .point(bool)
               .getdata())


And here's an implementation using Numpy:

def count_nonblack_np(img):
    """Return the number of pixels in img that are not black.
    img must be a Numpy array with colour values along the last axis.

    """
    return img.any(axis=-1).sum()


(We will need scipy.ndimage.imread to load the image.)

Here's a quick performance comparison using timeit.timeit:

&gt;&gt;&gt; from PIL import Image
&gt;&gt;&gt; import scipy.ndimage
&gt;&gt;&gt; from timeit import timeit
&gt;&gt;&gt; img1 = Image.open(filename)
&gt;&gt;&gt; timeit(lambda:count_nonblack_pil(img1), number=10)
5.4229461060022
&gt;&gt;&gt; img2 = scipy.ndimage.imread(filename)
&gt;&gt;&gt; timeit(lambda:count_nonblack_np(img2), number=10)
2.3291947869875003


So Numpy is about two and a half times as fast on my example.