Fast Lossless Image Compression: interested?

Hi,

so, I coundn’t shut up about this on my social media, so some of you might be already sick and tired of me, but I am sharing it here, hoping to understand if the robotic community may benefit from this work.

By pure chance, I started exploring the topic of Lossless Image Compression, in particular in terms of speed, thinking about real-time streaming and recording.

I got very interesting results that I think may benefit some use cases in robotics.

Before moving forward releasing the code or more details about the algorithm (that is very much still work in progress) I wanted to:

  • share the binaries with the community to allow people with healthy dose of skepticism to replicate results on their computer.

  • understand what the actual use case for fast, but still better than PNG, lossless compression is.

These are my results: 3 codecs with 3 different tradeoffs (being Griffin the most balanced one in the 3 dimensions).

I would love to hear the feedback of the community :grin:

LINK: GitHub - AurynRobotics/dvid3-codec · GitHub

Also, if you think that you have a practical application for this, please DM me to discuss this, either here or contacting me on dfaconti@aurynrobotics.com

Davide

9 Likes

No reaction ? :laughing:

Let me drop another image here:

1 Like

What’s your proposal here? Are you thinking of an alternative back end for ROS Bag? A new format for image pipeline? A lossless WebRTC-like a streaming utility for a UI? A super cool new fourth thing?

Since it is almost tax day here in the states, I want to know what kind of tax I’m paying to send uncompressed images over the wire in ROS versus using a video streaming codec.

Just some food for thought, if you are streaming series of images (i.e. frames from a camera) most video streaming codecs exploit inter-frame consistency to achieve higher compression ratios and de/compression speeds. What might be handy here is a bench mark on how well a lossless sequential image stream compares to something like a lossy video streaming codec. I would try using a dataset of 10-30s worth of images collected at 30-60 Hz from a ROS Bag (i.e. 300-1800 images taken sequentially) and compare the results against a video streaming codec. This would help determine the trade off between using something like a lossy real-time video streaming codec versus having a series of images with better per-image compression.

3 Likes

The truth is that maybe there is no use cases for this technology.

If the goals of streaming is visual inspection, or teleoperation, lossy video streaming is waaaay better.

Even if someone still prefers to save individual Compressed images in rosbag, maybe lossy jpeg is fine?

So, there is a high probability that no one needs this :sweat_smile:

1 Like

Did you also compare to QOI codec? It was pretty interesting last time I used it.

We sometimes use lossless to store depth or thermal images, or some camera masks (PBM seems unbeatable for masks).

Video codec are not good for “random image access”. You have the keyframes and the “delta” from the last keyframe. In order to reconstruct a frame, you have to jump back to the previous keyframe and add the deltas on top. IMHO, I still see use for individual image messages.

I mostly use lossless compression for uint16 depth frames. But here, I need a 16-bit colour channel. This is possible with PNG. QOI officially does not support 16 bit channels (only 8 bit), and never will as the format is now fixed. I guess you could work around this by splitting your single values across multiple channels.

Does “Griffin” support 16 bit single channel images, that could be used for lossless compressed depth?

How does this compare to TIFF? I think you can already use TIFF as format in ROS compressed image transport.

If I could replace 16bit PNG with 16bit “Griffin” for depth images, and this is integrated into the ROS image transport and stays maintained, I would be interested.

yes, I did.

Furthermore, I created an accelerated QOI version that is 50% faster than the reference implementation.

Compression ratio and speed of Griffin is MUCH better…

1 Like

I shall try that. DM to provide some dataset that you want me to use for the benchmarking

You can use the TUM RGB-D dataset Computer Vision Group - Dataset Download. The “*.tgz” files contain colour and depth image. The depth is stored as PNG with 5000:1 scale, i.e. 5000 units are 1 metre.

Additionally, you can use the ICL RGB-D dataset https://www.doc.ic.ac.uk/~ahanda/VaFRIC/iclnuim.html, where depth is also stored as “TUM RGB-D Compatible PNG”.

In both cases, you can recompress the depth PNG images and recompress in any format that supports 16 bit channels. The TUM dataset has more depth typical noise and missing depth readings, while the ICL dataset is purely synthetic. So the TUM dataset is more realistic.

You will like this. I do.

When you see speed (Mib/sec) you should actually think in terms of CPU used

At a previous job we used GitHub - swri-robotics/imagezero_transport: ROS image_transport implementation of a fast, lossless compression library for 24-bit color images · GitHub for computer to computer sending of image data within the same robot. Some setups are limited to gigabit which just doesn’t go very far with image data.

These days not many people seem to have multiple computers on the same robot anymore though. (Maybe that’s why nobody finished ROS2 multimachine launching)

“Griffin BEST” achieves 64% of the size of the PNG? That sounds good at first sight. Is this against the original PNG data? Can you also show the decode/encode speed against PNG and with the different PNG compression levels (0 … 9)?

Yes, that is in percentage of the original file. By the way, since I posted I reduced that further to 50%-ish.

I can go on posting benchmarks and comparisons, but I feel like I demonstrated enough my point.

If anyone is seriously interested to use this in production, let me know (DM).

Also, you may have fun and try to replicate something similar on your own using Claude Code :grin:

I feel like you are giving me an unpaid job to do (not even asking “please” :laughing:) but here we go.

Anything else I can do for you. Fill in your tax return? :joy:

1 Like

Well, “Reviewer #3” also always asks me to implement additional baselines, run additional experiments, and squeeze them into non-existing space without a “Please” :slight_smile:

But thanks for the results. Those are indeed impressive. I always have issues with high PNG compression rates, as those churn up the CPU and eventually result in frame drops.

Do you know how much of this performance gain stems from compiler optimisation (AVX, …)? If this lands in the ROS repos, then it probably will be compiled for some more generic target without additional CPU features.

Where can I find the reference implementation of “griffin”?

1 Like

This reminded me there’s ongoing PR to add depth data to LeRobot datasets, and since ROS predates LeRobot by almost two decades, it might be beneficial if you could share some knowledge/tips with them (I have D455 on my robot so I’m also interested in getting this merged).

They want to quantize depth to 12 bit or provide some parameters for tweaking, but from my practical experience with Realsense the depth is super noisy so maybe some lossless compression like @facontidavide talked about could be better? Maybe veterans like @peci1 @Katherine_Scott can also chime in :sparkles:

Lossless compression won’t help you with depth noise. In fact, it will preserve the depth noise perfectly. In order to reduce the noise with the RealSense, you have to tune the filter parameters. Or you just use a better ToF camera, such as the Orbbec Femto :slight_smile:

Most video codecs (if not all?) use lossy compression. And they are mostly optimised for colour (RGB) data. Applying lossy 3-channel colour compression to single channel depth data will have weird effects. Colour images do not encode metric properties, so they can be compressed by removing subtle “imperceivable” details. Depth images on the other hand encode metric values, and you usually do not want to remove information in the same way you would do with colour images. There are some lossy compression approaches for depth and point clouds, but they do not seem to be widely used.

I don’t fully get how lerobot wants to do the lossy depth compression. They are mentioning “Streaming encoding is enforced for depth maps to avoid lossy PNG-based intermediate compression.”, but there is no “lossy PNG” AFAIK. Compressing depth via 16bit PNG is quite common.

1 Like

Going from 16bit to 12bit and doing compression will probably produce some garbage values? I wasn’t commenting on denoising it or anything…

I also don’t know how lerobot wants to do lossy depth compression, therefore I just mentioned it here that you could have some insights :slight_smile: I guess if you have depth data alongside RGB, you will eventually need to compress it somehow otherwise you’ll end up with insane amounts of data, that you will need to feed to VLA/VLMs for training…

AVX helps a LOT, but we can use other instructions that work equally well on arm

They shouldn’t.
I will be happy to release as OSS this work (only depth16bits) if they want to consider using it