Predict Original JPEG Quality Factor with ML
Machine learning models can accurately predict the original, pre-compression quality factor (QF) of a modified JPEG image. By analyzing subtle quantization artifacts, discrete cosine transform (DCT) coefficient distributions, and compression inconsistencies, modern machine learning and deep learning architectures can reverse-engineer an image's compression history. This forensic capability remains effective even when the image has undergone subsequent editing, cropping, or re-compression.
The Mechanics of JPEG Compression Artifacts
JPEG compression operates in the frequency domain. An image is divided into 8x8 pixel blocks, transformed using the Discrete Cosine Transform (DCT), and quantized using a specific quantization table determined by the Quality Factor (ranging from 1 to 100).
Quantization is inherently lossy and rounds DCT coefficients to specific integer steps. This rounding leaves behind a distinct mathematical footprint:
- DCT Histogram Periodicities: Re-compressing or modifying an image creates periodic patterns or comb-like structures in the histogram of DCT coefficients.
- Quantization Error Residuals: Subtle high-frequency noise profiles remain tied to the primary quantization step sizes, even after spatial modifications.
How Machine Learning Detects the Primary Quality Factor
When an image is modified—such as being edited and saved again at a different quality level—it undergoes "double compression." Machine learning systems predict the primary QF by recognizing the interaction between the original and secondary compression stages.
1. Feature-Based Classifiers
Traditional machine learning methods extract engineered features from the image:
- Benford’s Law Violations: Natural images follow Benford's Law regarding the distribution of first digits in DCT coefficients. Prior compression disrupts this distribution in ways unique to the primary QF.
- Block Artifact Grid (BAG) Alignment: Measuring the strength and alignment of the 8x8 block boundaries identifies whether spatial operations like cropping have shifted the grid. Classifiers such as Support Vector Machines (SVMs) and Random Forests use these statistical features to categorize or regress the original QF value.
2. Deep Convolutional Neural Networks (CNNs)
Deep learning models typically outperform traditional feature-based methods by operating directly on raw pixels or unquantized DCT domains:
- High-Pass Pre-filtering: Forensics-focused CNNs often use fixed or trainable high-pass filters (such as Spatial Rich Model filters) in their initial layers to suppress image content and expose compression noise residuals.
- Dual-Domain Networks: Advanced architectures analyze both the spatial domain (to detect pixel-level boundaries and interpolation artifacts) and the frequency domain (to inspect DCT coefficients directly).
Key Challenges in Modified JPEGs
While prediction is reliable under controlled conditions, several modifications complicate the prediction process:
- Non-Aligned Re-compression: If an image is cropped by an offset that is not a multiple of 8, the original 8x8 block grid shifts. The secondary compression creates a new grid, obscuring the primary frequency-domain artifacts. Specialized CNNs must first identify the grid offset before predicting the original QF.
- Lower-to-Higher Quality Compression: If the original QF was low (e.g., QF 50) and the modified QF is high (e.g., QF 95), detection is straightforward because the coarse quantization footprints are preserved. Conversely, if a high-quality original (e.g., QF 95) is re-compressed at a low quality (e.g., QF 30), the second compression step discards the subtle high-frequency data from the original, making accurate prediction significantly harder.
- Aggressive Spatial Filtering: Blurring, resizing, or intense color grading can erase high-frequency quantization traces.
Real-World Applications
Predicting the original quality factor plays a vital role in digital media verification:
- Digital Forensics: Establishing whether an image presented as evidence has been altered or degraded from a higher-quality source.
- Tamper Localization: Identifying regions of an image that have different compression histories, which highlights cut-and-paste splices.
- Image Restoration: Knowing the original compression parameters allows de-blocking and enhancement algorithms to invert compression artifacts more effectively.