JpegZIP is a Python-based package designed to have image and video compression using the JPEG algorithm.
The core approach follows the methodology outlined in the Wikipedia article on JPEG, which describes the JPEG codec in detail.
In addition to the standard JPEG pipeline, JpegZIP introduces advanced customizations like targeted MSE compression and video frame-by-frame processing.
Achieve precise control over the compression process by setting a target Mean Squared Error (MSE). This feature compresses an image iteratively until the specified MSE difference is reached, balancing file size and quality according to your requirements.
The algorithm begins with an initial compression factor, Q_FACTOR
, set to 1
. This value is used to scale the coefficients in the quantizable matrix. The goal is to iteratively adjust the Q_FACTOR
to achieve a target Mean Squared Error (MSE) for a compressed image compared to the original image.
- Calculate the Adjusted
Q-Factor
Using proportional reasoning, compute a new candidate compression factor, Q_FACTOR_NEW
, that would bring the current MSE closer to the target MSE:
- Determine the Adjustment
Step
Calculate the difference between the new and current Q-Factor
values, referred to as STEP
:
- Adjust the
Q-Factor
Gradually
Move the current Q-Factor
toward Q_FACTOR_NEW
by a fraction of STEP
, controlled by a predefined constant FACTOR_RATE
(e.g., 0.5
):
- Iterate Until Convergence or Stop
Repeat the above steps until the difference between the current MSE and the target MSE is within an acceptable tolerance, MAX_TOLERANCE
, or after the MAX_ITERATIONS
has been reached.
In the context of video compression, intra-frame compression refers to the process of compressing each individual frame independently, without considering dependencies or similarities with other frames in the video. Each frame is treated as a standalone image, and compression algorithms are applied directly to the pixel data within that frame.
After compression, the video is reconstructed by assembling all the individually compressed frames in sequence.
The docstring documentation follows the NumPy style guide and was generated with the assistance of ChatGPT. Additionally, certain sections of the README were enhanced and refined using this AI tool.
Cristian Rusu's Signal Processing Lectures
OpenCV Getting Started with Video