RAW Image Compression with Lossy and Lossless algorithms

Updated:

Fastvideo RAW image compression encodes 12–16-bit Bayer and monochrome sensor data directly in the RAW domain on the GPU, with both lossless and lossy algorithms, reducing file size by 5–10 times while keeping visually lossless quality. Working on the raw mosaic instead of on demosaiced RGB avoids the color-spaced artifacts that ordinary image codecs introduce, and the GPU pipeline is fast enough for real-time recording and on-camera use.

Detailed benchmark data. Measured results are published on our benchmark pages: RawZipper benchmarks, all benchmarks.

The task is simple to state: compress the 12–16-bit data from a Bayer or monochrome sensor with a lossless or lossy algorithm, and tune the settings to each application. We work directly in the raw domain — we do not convert RAW to RGB first and then encode. This is the technology behind our RawZipper RAW Bayer codec.

Lossless RAW Image Compression

Lossless encoding is employed to minimize the file size of captured RAW images, ensuring the absence of any artifacts, but the compression ratio (CR) is usually around 2 or up to 2.5, which is not enough in many cases. Still, this is a mathematically lossless approach, meaning that each image will be restored exactly with zero loss. These are some lossless algorithms for raw image compression to consider: Lossless JPEG (1–16 bits), JPEG-LS (1–16 bits), JPEG 2000 (up to 16 bits), JPEG XS (up to 16 bits), JPEG XL (up to 16 bits), etc. In certain cases, the application of lossless compression is mandatory, particularly within the context of scientific research.

The ~2:1 ceiling has a physical reason: a large share of every raw pixel is sensor noise, which is close to random and barely compresses, so lossless encoding can only remove the redundancy that is left. To go beyond that ratio, the loss has to be controlled against the noise floor — which is exactly what lossy RAW compression does. Lossless is usually slower than lossy, but it is a must-have option for any raw compression solution.

Additionally, there are some options for the utilization of lossless video codecs. Video codecs typically exhibit a higher compression ratio in comparison with the results obtained for still image compression, but they are not very fast. The lossless H.265 encoding algorithm is capable of processing color video streams; however, its application is limited to 8/10-bit color (NV12, YUV) output, and it's not working with RAW formats. This assertion holds true for the lossless AV1 codec as well, which is capable of encoding up to 10-bit YUV (4:2:0, 4:2:2, 4:4:4) but not RAW. As we see, these methods are not applicable to the most common use case, which is the raw image compression from Bayer or monochrome image sensors with bits per pixel of 12 or higher, up to 16 bits. Still, there are some cases when video codecs could be viable for such a task.

Lossy RAW Image Compression

Applying lossy encoding to RAW images is a sound way to reach a higher compression ratio, but the loss in image quality has to be controlled — that is what makes these algorithms work. Even small distortions in the RAW-encoded frames can turn into visible artifacts, which typically appear only after the RAW data is converted to RGB. Lossy encoding can push the compression ratio well above 2:1, so the goal is a solution that balances image quality against the compression ratio.

One remark is worth making here: a "RAW image" is not as raw as the name suggests. Between the photons hitting a pixel and the RAW file being written, the camera already applies a chain of hardware processing, and high-quality results still depend on camera calibration — dark frame, PRNU, bad/hot pixels, linearization, shading correction, undistortion, and color, noise and lens profiles. So the frames we compress are already the product of some processing, not pristine sensor output; keeping that in mind matters when we decide how much loss is acceptable.

Applying a lossy algorithm directly to a raw Bayer (Color Filter Array, CFA) image exposes the core difficulty: it produces significant artifacts that are not acceptable, and these artifacts become visible once the RAW data is converted to RGB. In other words, raw frames are not ready for direct lossy encoding — they need preprocessing first to make them suitable for it.

The idea of preprocessing is evident due to its similarity across various lossy encoding algorithms for monochrome images. To compress a monochrome image in a lossy way, we need to convert input data to a latent space via shift and DCT for JPEG or DWT for JPEG 2000, this is a fundamental the first step. Quantization, which constitutes the primary lossy component of the algorithm, is then followed by regrouping and data compression with an entropy codec, which by default operate in a lossless way. The same approach should be applied to RAW encoding to obtain a satisfactory result.

Image Quality and CR Considerations

Below we present some results of our new solution for RAW Image Compression.

Mode Compression ratio Image quality Typical use
Lossless about 2:1 (up to 2.5:1) bit-exact, zero loss scientific and archival
Lossy, maximum quality 4:1 to 5:1 PSNR above 60 dB critical imaging
Lossy, balanced 5:1 to 10:1 PSNR 50–55 dB most applications
Lossy, high ratio up to 20:1 reduced, task-dependent aerial and aerospace, less demanding tasks

RAW Bayer compression modes on GPU: compression ratio versus image quality for 12-bit sensor data.

For RAW Bayer frames from conventional 12-bit image sensors by Sony, Gpixel, OnSemi, and CMOSIS, lossless algorithms typically reach a compression ratio of about CR~2. The same holds for 14-bit raw data from Sony, Canon, Nikon, and other photo cameras. The reason is that the useful data also contains noise, which can be important in scientific applications that require lossless compression. On top of the low CR, lossless encoding is also slower than its lossy counterparts.

Lossy encoding trades some loss (for a higher CR) against better performance, and the result depends on the image content, the encoding parameters, and the hardware. The key is to control how much loss is introduced so that image quality stays high for the task at hand. In most cases we compress RAW frames at a CR of about 5–10, reaching a peak signal-to-noise ratio (PSNR) of 50–55 dB or better. The PSNR is computed between the original RAW Bayer image and the same image after processing, encoding, decoding, and restoration.

It is acknowledged that PSNR metrics are of limited utility. To this end, visual image quality assessment is performed to determine the most suitable default processing parameters for a given project. A visual comparison is conducted between RGB images, which undergo processing under identical parameters, as opposed to RAW images. For instance, there should be no perceptible differences between the source image and its processed counterpart when viewed at a 500% zoom level. However, this requirement is contingent upon the specific task at hand.

For applications that require maximum image quality with lossy compression, a CR of about 4–5 keeps the PSNR above 60 dB.

There are numerous examples of cases that exhibit significantly weaker image quality requirements and a pronounced need for enhanced CR. Achieving a CR of up to 20:1 for such applications is a feasible objective.

Our lossy RAW solution is more than a plain codec. It balances preserving the raw data with additional processing that raises the contrast-to-noise ratio and suppresses distortion, so on raw Bayer and monochrome images it reaches higher CR and PSNR than applying JPEG or JPEG 2000 to the same data. Once a project's requirements are clear, the software can be tuned for it.

The practical test is whether the differences a lossy codec introduces stay within the sensor's own noise. As an example, we processed a ColorChecker raw frame from a DALSA/FLIR camera (20 MPix, 4512×4512, 12-bit, RGGB) with lossy raw Bayer encoding at CR = 10 and measured every patch: PSNR = 45.3 dB, the standard deviation (σ) changed by less than 2% on average, and the SNR by less than 0.15 dB. In other words, the noise statistics of the restored image match the original within a fraction of the noise itself.

Benefits of RAW Image Compression

Compressing RAW on the GPU cuts storage and bandwidth by the same factor as the compression ratio: at 5:1 to 10:1 a recording needs five to ten times less disk space and network traffic. Because raw Bayer data is already about one third the size of demosaiced RGB, storing compressed RAW instead of processed RGB can cut the data volume by an order of magnitude.

Conclusions

How to proceed

Get in touch with our team to learn how to reduce your RAW images in size by up to 10× with our software and how to integrate that solution into your pipeline with our SDK.

Frequently Asked Questions

Is RAW image compression lossless or lossy?

Both. Lossless encoding restores every pixel exactly but reaches only about 2:1, while controlled lossy encoding reaches 5:1 to 10:1 (up to 20:1 for less demanding tasks) by keeping the loss within the sensor noise. Most applications use the lossy mode; scientific work that needs bit-exact data uses lossless.

Why can't lossless RAW compression go beyond about 2:1?

Because a large share of every raw pixel is sensor noise, which is almost random and barely compresses. Lossless encoding can only remove the redundancy that is left, so the ratio settles near 2:1. To go further, the loss has to be controlled against the noise floor — which is what lossy RAW compression does.

Does lossy RAW compression reduce image quality?

Not visibly when the loss is controlled. On a ColorChecker frame from a DALSA/FLIR camera (20 MPix, 12-bit, RGGB) at CR = 10 we measured PSNR = 45.3 dB, with the standard deviation changing by less than 2% and the SNR by less than 0.15 dB — the noise statistics of the restored image match the original within a fraction of the noise itself.

How much storage and bandwidth does RAW compression save?

Up to 5 to 10 times. Encoding the raw data at a 5:1 to 10:1 ratio cuts storage and transmission by the same factor, and because raw data is already about one third the size of demosaiced RGB, storing compressed RAW instead of uncompressed RGB can reduce data volume by an order of magnitude.

Can you compress RAW without converting it to RGB first?

Yes. We work directly in the raw domain and do not demosaic first, which avoids the color-spaced artifacts that ordinary image codecs introduce and keeps the sensor data intact for later RAW-to-RGB processing.

Useful links on the subject

Fyodor Serzhenko, Fastvideo

About the author

Fyodor Serzhenko, PhD, is the founder and CEO of Fastvideo. He earned his PhD at the Moscow Institute of Physics and Technology (MIPT) in 1993. Since 2009 he has led the development of Fastvideo’s GPU-accelerated image codecs and ISP modules, including the Fastvideo SDK. Connect on LinkedIn.

Why you can trust these results

Fastvideo has built GPU-accelerated image processing software since 2009. Our codecs comply with the standards they implement — JPEG (ITU-T T.81 / ISO IEC 10918) and JPEG2000 (ITU-T T.800 / ISO IEC 15444) — and our tools are open source on GitHub. Every performance figure we publish is reproducible: see our benchmark methodology, download the Fastvideo SDK benchmark report (PDF), and measure it on your own GPU.

Contact Form

This form collects your name and email. See our Privacy Policy for how we handle your personal data.