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

Greg Corradini gregcorradini at gmail.com
Mon Aug 15 05:12:26 CEST 2011


Thanks Jim. Comments below.

> 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?)

I'm testing RGBA png(s) for blank spots. Considering that each band except
the Alpha band in my image has black and white min/max values, then I'm
guessing that any minimum Alpha values of black (0) indicate a blank spot
(this is only a guess and I'm always open to better educated guesses ;-) ).

Here is the extrema min/max output  for each band before editing a png:

>>> import ImageStat
>>> stat = ImageStat.Stat(img)
>>> stat.extrema
[(0, 255), (0, 255), (0, 255), (191, 255)]

After using Gimp to erase cells from the png, the extrema min/max output
looks like this:

>>> stat.extrema
[(0, 255), (0, 255), (0, 255), (0, 255)]


So i guess I'll test for that

> 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.





On Sun, Aug 14, 2011 at 4:21 PM, Jim Tittsler <jwt at onjapan.net> wrote:

> 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
> _______________________________________________
> Image-SIG maillist  -  Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
>



-- 
Greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20110814/edb4ae63/attachment-0001.html>


More information about the Image-SIG mailing list