Zing Forum

Reading

bpcodec: A New Neural Network-Based Lossless Image Compression Scheme

bpcodec is a strictly lossless image codec written in Rust, designed specifically for 8-bit grayscale images. It uses bit-plane encoding and fixed-point binary context models to achieve efficient compression while maintaining complete losslessness, with support for Metal GPU acceleration.

无损压缩图像编解码神经网络Rust灰度图像熵编码Metal加速开源工具
Published 2026-05-10 15:53Recent activity 2026-05-10 16:02Estimated read 7 min
bpcodec: A New Neural Network-Based Lossless Image Compression Scheme
1

Section 01

Introduction to bpcodec: A New Neural Network-Based Lossless Image Compression Scheme

bpcodec is a strictly lossless image codec written in Rust, designed specifically for 8-bit grayscale images. It uses bit-plane encoding and fixed-point binary context models to achieve efficient compression while maintaining complete losslessness, and supports Metal GPU acceleration during the training phase. It is suitable for scenarios with high data integrity requirements such as medical imaging, scientific data archiving, and digital asset management. The project uses the LGPLv3 open source license.

2

Section 02

Demand for Lossless Compression and Limitations of Traditional Schemes

In the field of image compression, lossy compression (e.g., JPEG, WebP) balances volume and quality, but fields like medical imaging and scientific data require strictly lossless compression. Traditional schemes like PNG and TIFF are reliable, but their compression ratios often fail to meet demands. bpcodec attempts to open a new path for lossless compression using neural network technology, optimized for 8-bit grayscale images, balancing losslessness and compression efficiency.

3

Section 03

Core Technical Architecture and Principles of bpcodec

Core technical features of bpcodec:

  • Bit-plane encoding: Encodes pixel information layer by layer from the most significant bit (MSB) to the least significant bit (LSB);
  • Polarity normalization: Dynamically adjusts image polarity to optimize encoding;
  • Fixed-point binary context model: Uses a trained global model (containing 5120 Q12 format zero-probability entries) to predict bit probabilities;
  • Neural network assistance: Improves entropy coding efficiency by understanding the statistical characteristics of images through the model;
  • Metal-accelerated training: Apple Silicon devices can enable GPU acceleration to shorten training time (decoding is pure CPU operation to ensure determinism).
4

Section 04

Usage Workflow and Command-Line Tools of bpcodec

bpcodec provides a complete command-line tool, with the workflow divided into training and application: Train model: bpcodec train --input-dir ./images --model model.bpm (learns image statistics to generate a .bpm model); Single image encoding/decoding:

  • Encode: bpcodec encode --model model.bpm --input image.png --output image.bpc;
  • Decode: bpcodec decode --model model.bpm --input image.bpc --output restored.png; Batch processing: bpcodec pack/unpack packs the model and images into a .bpa archive. Three file formats are supported: .bpm (model), .bpc (single image compression), .bpa (archive), all in little-endian byte order, with metadata to ensure integrity.
5

Section 05

Applicable Scenarios and Current Limitations of bpcodec

Applicable scenarios: Medical imaging archiving (X-ray, CT), scientific datasets (astronomy, microscopy), digital asset management, document scanning/industrial inspection and other grayscale image fields; Current limitations: Only supports 8-bit grayscale images (does not support RGB/RGBA), so conversion to grayscale mode is required for use; compression effect depends on training data—when the image to be compressed differs greatly from the training data, the effect may decrease. It is recommended to train a dedicated model for specific domains.

6

Section 06

Open Source License and Usage Notes of bpcodec

bpcodec uses the GNU Lesser General Public License v3 (LGPLv3):

  • Free to use and modify the code;
  • Can be linked as a library to commercial software;
  • When modifying and distributing bpcodec itself, the modified parts need to be open-sourced. This license balances open source features and commercial application needs.
7

Section 07

Value and Future Outlook of bpcodec

bpcodec is an innovative attempt of neural network technology in the field of lossless compression. Compared with traditional DEFLATE/JPEG-LS, the learning-based method has better compression potential on specific images. The Rust implementation ensures memory safety and efficiency, and the fixed-point design ensures cross-platform consistency. Although it currently only supports grayscale images, it is a noteworthy alternative for target fields. In the future, it is expected to support color images and introduce more advanced context model architectures.