Luigi> I think there is an errore in the frame selection inside Luigi> PIL_decode_parts(). Luigi> for frame in ImageSequence.Iterator(image): Luigi> # Assume the pixel with the largest value is the Luigi> # background. Luigi> bg = max(frame.histogram()) Luigi> if bg < bgpix: Luigi> image = frame Luigi> bgpix = bg Luigi, I can't tell what you're doing in this change. Can you describe it? Also, in the future, please submit patches and bug reports to the SourceForge tracker (as context or unified diffs, not as complete replacements). Luigi> A part from this the algorithm could be better. From my test Luigi> using stddev and sum2 yield better result. No doubt my algorithm could be better. I'm afraid I just don't know what yours does and the ImageStat.Stat documentation isn't much help. ;-) Skip