Compressing three separate jpeg photos containing temporary redundancy?
I am interacting with an embedded device with a camera module that returns every compressed jpeg frame every time I run it.
I would like to take three consecutive shots (approximately 1 frame in 1/4 second) and compress the images even more into one file. The assumption here is that there is a lot of temporal redundancy, so there is plenty of room for more compression across three frames (versus sending three separate JPEG images).
I will be implementing the solution to an embedded device in C without any libraries and no OS.
The camera will take photos in an area with very little movement (no visitors or screens in the background, maybe a tree with swaying branches), so I think my redundancy assumption is pretty solid.
When the file is finally viewed on a PC / Mac, I don't mind writing something to extract three frames (so it might be a custom cliche)
So I think that's the actual question . What is the best way to compress these three images together, given the fact that they are already in JPEG format (maybe this is an option to revert to the original image, but if I don't have it either ...)
a source to share
I am adding this as the second answer because it is VERY different from my first now that I understand your problem better.
I believe you are unlikely to be able to work directly with jpeg files. In compressed files, a small change spreads over most of the file, with the result that the two files cannot be compared in many places.
I have two suggestions.
1: write the images up. Sounds too simple, you probably already thought about it, but the zip protocol is well known and freely available and will automatically take advantage of any similarities it can. Again, just grab your camera by taking three shots; zip them up and see how it goes.
2: A bit tricky, but you can decompress three jpegs to bmps, concatenate the bmps (align them one by one) and then recompress to jpeg. The jpeg protocol should take full advantage of the similarities in the three images, and the work is minimal from your point of view.
a source to share
Any decoding / modifying / re-encoding of JPEG images can degrade image quality, but since your camera can only capture JPEG, I guess the final image quality is unlikely to be a key requirement ...
I can't think of an easy way that you can do this in the frequency domain of a JPEG, but you can uncompress images 2 and 3 from image 1 to get delta images . They should shrink much better and will be added back to image # 1 by the receiver.
It turns out there are some operations you can perform on a compressed domain that might help. You need to decompress the Huffman / RLE steps to jpeg and then work directly with the DCT coefficients. This way you could do the subtraction of the image that way and don't have to introduce additional artifacts.
a source to share
Until I studied signals with uni, I think you are looking for a lossless video codec.
Huffyuv is the one around and has source code. The basic concept is to predict the pixel changes between each frame and encode (and compress) the difference between the predicted and actual changes.
Lagarith is another open source codec.
You will need to feed decoded JPEG frames to each of these codecs.
a source to share
If I were you, I would use your system to take three manual shots right now so you can check your assumptions before moving on.
I suppose you need a little translation even if you don't intend to move. Equipment vibration, wind, and even thermal expansion can be enough to pull you a pixel or two away, which will destroy the pixel-to-pixel forward compression.
Other factors could be changes in light due to a cloud passing through the sun, or an increase in heat that comes from terrestrial or even jpeg compression artifacts.
I am not saying that it won't work, I just would run it manually first.
The storage is so cheap that you get a much bigger bug for the dollar by adding a large sim card (or whatever) to your camera.
a source to share