Search code examples
javaimage-processingimage-comparison

Simple but efficient way to store a series of small changes to an image?


I have a series of images. Each one is typically (but not always) similar to the previous one, with 3 or 4 small rectangular regions updated. I need to record these changes using a minimum of disk space.

The source images are not compressed, but I would like the deltas to be compressed.

I need to be able to recreate the images exactly as input (so a lossy video codec is not appropriate.)

I am thinking of something along the lines of:

  • Composite the new image with a negative of the old image
  • Save the composited image in any common format that can compress using RLE (probably PNG.)
  • Recreate the second image by compositing the previous image with the delta.

Although the images have an alpha channel, I can ignore it for the purposes of this function.

Is there an easy-to-implement algorithm or free Java library with this capability?


Solution

  • Experiment a little with existing lossless compressors -- PNG, lossless JPEG, etc -- on an image consisting of the changes only (you can use transparent background for PNG, or some uniform color). These algorithms are very efficient when it comes to compressing an image which is mostly constant, you'll not be able to beat them if you are not an expert.