MP3 for image compression
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)
Nice. How about AAC and OGG? :)
So I guess JPEG compression of a sound file is the next step?
@Toke, why not go for ethernet-over-audio by pumping arbitrary data through the MP3 encoder, playing it, recording it on another machine, then trying to reverse that to what the MP3 encoder saw? Purpose unknown, but sounds challenging in a fun way.
You’ve just invented dialup
Cool, so you’re now halfways visualizing sounds from space ;)
Cool! I had a project in which the objective was sending images encoded as text. This comes in handy in remote areas where there’s only eg. GSM available. The challenge is in compression. ;)
@Miguel, isn’t this just using something like PNG or JPEG compression to get a byte stream, then using something like Base64 to encode it as text? I would imagine this is doable in about 2 dozen lines of code (less if you don’t care about readability).
Nice! Finally i’ve got something to show to people who dont beleive that mp3 lowers the quality of an audio signal :)