[Image-SIG] Scan Image for blank spots using PIL

Jim Tittsler jwt at OnJapan.net
Mon Aug 15 01:21:51 CEST 2011

On 2011-08-08 04:09, Greg Corradini wrote:
> I want to use PIL to scan a newly created image for possible corrupt
> (blank) pixels.
> The PIL documentation doesn't seem to mention what value a blank pixel
> might have (I assume it would come back as None).  I'm not sure what to
> test for.

It is going to depend on (a) the format of the image file and (b) your
definition of what a "blank pixel" is.  (Black?  White?  Something else?)

You could do a brute force check of each pixel's value, or depending on
your definition, you might be able to use something like the histogram
method to see if any pixels meet your criteria.

> I see the Image module has a verify function
> <http://www.pythonware.com/library/pil/handbook/image.htm>, but I'm not
> sure if that covers validating that pixels are not blank.

I believe it only detects if PIL will be able to load the specified
image file.

Jim Tittsler     http://www.OnJapan.net/      GPG: 0x01159DB6
Python Starship  http://Starship.Python.net/crew/jwt/
Mailman IRC      irc://irc.freenode.net/#mailman

More information about the Image-SIG mailing list