Losslessly compressing similar images?

10

2

I need to reduce the size of my photo library so I naturally want to compress them. Many of them are not quite identical, but still very similar (subsequent shots of the same scene). Is there any compression algorithm that takes advantage of this fact to effectively compress these images? 7zip (LZMA) is useless.

Erik

Posted 2012-04-29T10:44:20.067

Reputation: 644

Answers

11

You might try Paq 8 (fp8_v2.zip). I just tried it myself on 1440 similar PNG images and then again on 111 similar JPG images. Here are the results.

  • 1440 PNG Files, 28,631,615 bytes => 2,058,653 bytes compressed
  • 111 JPG Files, 15,003,820 bytes => 489,096 bytes compressed

Compression of the PNG files took about 8 minutes and 550 MB of memory when using:

fp8_v2.exe -7 images *.png

Compression of the JPG files took about 5 minutes and 125 MB of memory when using:

fp8_v2.exe -5 images image12*.jpg

See also: jpg lossless image compression test

jftuga

Posted 2012-04-29T10:44:20.067

Reputation: 2 877

97% compression for the JPGs seems unrealistic. The numbers in the comparison test you link to say the compression is about 20% – OneSolitaryNoob – 2015-05-28T05:30:01.377

@OneSolitaryNoob Did you forget that the JPEGs are similar? 110/111 = 99.1% expected compression. The comparison test that he linked is about compressing a single JPEG. – Navin – 2018-04-22T19:51:48.840

@Navin it's really unlikely. Even if they look nearly identical most of the pixels will be slightly different. – OneSolitaryNoob – 2018-04-22T19:55:20.033

@OneSolitaryNoob So what? 1 second of video (30 frames) can be compressed to about the same size as a single frame. As long as the slight difference makes up a small fraction of the data, you're all good. – Navin – 2018-04-23T01:57:28.233

@Navin thats lossy compression, many details are gone but most people won't notice. Paq* is lossless compression – OneSolitaryNoob – 2018-04-23T01:59:13.410

1

I would imagine that that the burrows-wheeler transform with an arithmetic coder would be ideal for this given a large enough window. What happens if you configure BZIP2 to use a block size equal to a small run of photos? It'll be slower and take more memory but the compression ratio should skyrocket. And have you tried LZMA with larger block sizes yet?

Peter Hanneman

Posted 2012-04-29T10:44:20.067

Reputation: 121

1

Here's a simple solution which doesn't work for photos but may work if one has several images with large pixel-by-pixel identical areas: save the images in an unpacked format like BMP (not PNG or GIF) and then TAR them and compress with a decent compressor like XZ, e. g. on Linux with something like

tar -c myDirectory | xz -9 >myDirectory.tar.xz

Instead of TAR and XZ, one may use 7-Zip with the “solid archive” option to get roughly the same performance. This way I could compress 16 similar screenshots, that took about 900 KB each when saved as separate PNG files, into a 2 MB archive. The benefit of this solution is that it uses common file formats, so it works without installing new software. (Unfortunately the older and even more common programs GZIP and BZIP2 didn't do a good job for me — maybe because the block size of BZIP2 cannot be configured to be larger than 900 KB.)

Jaan

Posted 2012-04-29T10:44:20.067

Reputation: 111

0

Not that I've seen. Probably the closest thing would be taking several similar JPEGs and putting them into an MJPEG movie. You could also use APNG or animated GIFs for a similar purpose.

I'm not sure how well that would work though, and it sounds like you're already talking about movie screencaps, so repacking them into a movie file sounds... counterproductive.

Maybe a better way, if you still have the clips that the screens came from, would be to simply find a command line tool that can extract the exact frame for you, copy that unique identifier into a text file someplace, and then you can always easily re-extract the frame when you need it.

afrazier

Posted 2012-04-29T10:44:20.067

Reputation: 21 316

GIF is not suitable for compressing photos, and animated GIF is even less. Even compressing photos to a MJPEG video does not seem useful in my eyes, because restoring single images would be difficult. – Martin – 2012-04-29T17:11:06.237

I didn't say it was a good idea... :-) The ultimate idea was to put the photos into an animated variant of their original format. – afrazier – 2012-04-29T20:25:41.667