[Image-SIG] PIL performance issue
Vadim Suvorov
vsuvorov@cccglobal.com
Sat, 20 May 2000 22:01:49 -0500
Hello,
I have a fairly big bitmap (3086 x 2775 256 colors, about 8.5 MB) in which I
need to find pixels of certain color (for example, most of bitmap is black
and white, except for 4 red pixels, and 3-5 yellow).
I came up (after optimization) with solution like:
im = Image.open("myfile.bmp")
im.load()
xxx = range(im.size[0]); yyy = range(im.size[1])
imx = im.im # for sake of speed, bypass Image's wrapper (7 times faster)
coords = {}
for iy in yyy:
for ix in xxx:
c = imx.getpixel((ix, iy))
if c <> 0 and c <> 255:
if coords.has_key(c): coords[c].append((ix, iy))
else: coords[c] = [(ix, iy)]
print coords
but it is still fairly slow (about 50+ seconds on 400 MHz Pentium II). I
know there are methods like Point(), but they do not have access to
coordinates of the point. Is there any way to speed up the process?
Thank you,
Vadim