Animation: Auto-convert adjacent static pixels to transp.

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Copperfield
Posts: 1
Joined: 2013-06-17T09:41:51-07:00
Authentication code: 6789

Animation: Auto-convert adjacent static pixels to transp.

Post by Copperfield »

Hello,

I would like to ask if there is any way in ImageMagick which would help in the following case:
  • I have a sequence of images (frames from a video) as the source for an animated GIF.
  • Only a small amount of pixels change between frames - eg. most of the canvas remains unchanged between adjacent frames (for example, a small ball moving on a static field).
  • When I simply convert the images into an animated GIF, the resulting file will be roughly as large as the sum of all input files (despite only a few pixels needing to be updated).
What I would like to ask:
Is there a method in ImageMagick which would compare the adjacent image segments and automaticaly remove the pixels that did not require a change?

I've tried using the various available optimization methods (-deconstruct, -layer Optimize, etc.) but either I'm doing something wrong, or none of them were designed to handle the above mentioned case.

I can achieve what I need by doing it manualy - ergo painstalkingly removing most of those static pixels in an editor, and then using the modified images for input. This however is not really feasible when the sequence contains a larger amount of frames (like from a video).

My aim is to optimize the size of the final GIF file, where by this method it can be signifficantly reduced (up to a few orders of magnitude in speciffic cases) without a change in visual appearance (when compared to the much larger static full canvas sequence).

Hope I've managed to explain the problem clearly enough for anyone to understand :?
I would be grateful for any kind of advice on how I could achieve this without the need to edit all frames manualy in editor :(

Thanks in advance :)

Jason
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Animation: Auto-convert adjacent static pixels to transp

Post by anthony »

YEs.

-layers 'OptimizeTransparency'

This replaces any pixel that does not change from one frame to the next with transparency. You can also specify a 'fuzz' factor to also make baraly changed colors transparent too.

See IM Examples, Animation Optimizations, Transparency Optimization
http://www.imagemagick.org/Usage/anim_opt/#opt_trans

related to this is LWZ compression optimization which follows on from transparency optimization.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply