During some random discussion with my colleague today, I rediscovered an experiment I did quite some years ago: MP3 compression of image data. This is, feed raw 8-bit-per-pixel grayscale image data into an MP3 encoder, let it compress it, and decode the MP3 file again. After some conversion (the decoder will always produce 16 bit signed output, but 8 bit unsigned image data is needed), a raw image file will result of this whole process, ready to be displayed with an arbitrary image viewer. Sounds simple, eh? :)
I just reimplemented the whole thing, this time using some more-or-less standard Unix tools (bash, ImageMagick, LAME, Python) instead of Turbo Pascal and Paint Shop Pro handiwork. For the first test, I used some representative image, scaled it down to 960×720 pixels, and pretended that it was a 24 kHz mono sound file. The LAME encoder options were
-q 0 -k -b $SomeBitrate (maximum quality, no lowpass filtering) with bitrates from 8 kbps on. The results are not as bad as the rude misuse of an audio-specific algorithm for image compression would suggest: Above 24 kbps (about 1 bit per pixel), quality is actually quite acceptable. Of course, it doesn’t even remotely match JPEG’s quality, there are still much artifacts that look a bit like noisy analogue TV reception.
By the way, the generated MP3 files sound a bit like recordings from space probes, so if you need some nifty sound effects, mp3img might be the right tool for you :)
- mp3_vs_jpeg.png (355k) – the MP3 vs. JPEG quality assessment
- mp3img (1k) – shell script to compress image files with MP3
(This article is also available in Russian at Softdroid)