Hello, I think there is an errore in the frame selection inside PIL_decode_parts(). for frame in ImageSequence.Iterator(image): # Assume the pixel with the largest value is the # background. bg = max(frame.histogram()) if bg < bgpix: image = frame bgpix = bg outside this loop image (in my opinion) will be always the last frame of original image. A part from this the algorithm could be better. From my test using stddev and sum2 yield better result.
From a (very) raw test you may use the attached code snippet. Of course all of these are very simple test and can be wrong bug you test failed for a pattern common few days ago (see the attached image)
-- Luigi Pugnetti Symbolic S.p.A. V.le Mentana, 29 I-43100 Parma Italy Tel: +39 0521 708811 Fax: +39 0521 776190