Large Language Model for Lossless Image Compression with Visual Prompts

Junhao Du, Chuqin Zhou, Ning Cao, Gang Chen, Yunuo Chen, Zhengxue Cheng, Li Song, Guo Lu, Wenjun Zhang

Abstract

Recent advancements in deep learning have driven significant progress in lossless image compression. With the emergence of Large Language Models (LLMs), preliminary attempts have been made to leverage the extensive prior knowledge embedded in these pretrained models to enhance lossless image compression, particularly by improving the entropy model. However, a significant challenge remains in bridging the gap between the textual prior knowledge within LLMs and lossless image compression. To tackle this challenge and unlock the potential of LLMs, this paper introduces a novel paradigm for lossless image compression that incorporates LLMs with visual prompts. Specifically, we first generate a lossy reconstruction of the input image as visual prompts, from which we extract features to serve as visual embeddings for the LLM. The residual between the original image and the lossy reconstruction is then fed into the LLM along with these visual embeddings, enabling the LLM to function as an entropy model to predict the probability distribution of the residual. Extensive experiments on multiple benchmark datasets demonstrate our method achieves state-of-the-art compression performance, surpassing both traditional and learning-based lossless image codecs. Furthermore, our approach can be easily extended to images from other domains, such as medical and screen content images, achieving impressive performance. These results highlight the potential of LLMs for lossless image compression and may inspire further research in related directions.

Introduction

Lossless image compression is fundamentally a task of probability estimation. To compress a file without losing information, an entropy model must accurately predict the probability distribution of pixels. The more precise the prediction, the fewer bits are required to store the data. While Large Language Models (LLMs) are exceptional at predicting the "next token" in text, applying them to images has been difficult due to the "modality gap." Previous methods often treated pixel values as text, ignoring the spatial relationships like textures and shapes that define an image. This paper addresses this gap by using visual prompts to provide the LLM with necessary spatial context.

Methodology: LLM-based Compression with Visual Prompts

The proposed framework turns a pretrained LLM into a state-of-the-art entropy model. The core innovation is the "Lossy-to-Lossless" shortcut: rather than asking the LLM to predict an image from scratch, the system asks it to predict the residual (the error) of a lossy reconstruction.

Overview of the proposed LLM-based lossless image compression framework.

The process operates in three main stages:

  1. Visual Prompting: The original image is first compressed using a standard lossy codec (like BPG). This reconstruction serves as a "visual prompt" that informs the LLM of the image's general structure.
  2. Embedding Extraction: A Global Embedding Module captures broad context, while Local and Residual Embedding layers track specific patches and the differences between the original and lossy versions.
  3. LLM as Entropy Model: These embeddings are fed into a pretrained LLM (LLaMA3-8B), fine-tuned via Low-Rank Adaptation (LoRA). The LLM predicts the parameters of a Gaussian Mixture Model (GMM), which describes the probability distribution of the residual pixels. An arithmetic coder then packs this data into a compact bitstream.

Experimental Evaluation and Results

The model was evaluated on industry-standard benchmarks including DIV2K, Kodak, and CLIC. The primary metric used is bits per subpixel (bpsp), where a lower score indicates better compression efficiency.

Comparison of compression performance (bpsp) against traditional and learning-based codecs.

Key Findings

  • State-of-the-Art Performance: On high-resolution datasets, the method reduced file sizes by 12.3% to 17.9% compared to JPEG-XL, the current traditional gold standard.
  • Significant Leap over Previous LLM Methods: Compared to the previous leading LLM-based compressor (Delétang et al.), this method improved bpsp on the Kodak dataset from 4.84 to 2.83.
  • Domain Generalization: Due to the vast "world knowledge" in LLMs, the model adapted remarkably well to specialized domains. It achieved a 10.5% improvement over JPEG-XL on screen content (SCID) and outperformed specialized learning-based codecs on medical MRI images (MRNet).

Discussion and Future Work

While the framework achieves unprecedented compression ratios, it faces a significant challenge in computational overhead. Because the process is autoregressive (predicting pixel by pixel), decoding is slow—taking approximately 21 seconds for a single Kodak image on an NVIDIA A100 GPU. Additionally, the system currently depends on an initial lossy reconstruction step.

Future research will focus on improving efficiency, potentially through smaller LLM architectures or non-autoregressive prediction methods, to make this technology viable for real-time consumer applications.

Summary updated

BibTeX
@misc{du2025large,
  author = {Junhao Du and Chuqin Zhou and Ning Cao and Gang Chen and Yunuo Chen and Zhengxue Cheng and Li Song and Guo Lu and Wenjun Zhang},
  title = {{Large Language Model for Lossless Image Compression with Visual Prompts}},
  year = {2025},
  eprint = {2502.16163},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2502.16163},
}
Figure