DCT Algorithm Steps
Load the image (grayscale or color).
If color, convert to grayscale or YCbCr (for JPEG-style compression).
Divide the image into non-overlapping 8×8 blocks of pixels.
Each block will be processed independently.
Shift pixel values from range [0, 255] to [-128, 127] by subtracting 128 from each
pixel.
This helps center the data around zero, which improves DCT efficiency.
Apply the 2D Discrete Cosine Transform to each 8×8 block.
This transforms spatial data (pixels) to frequency domain.
Divide each DCT coefficient by a quantization matrix and round to nearest integer.
Quantization reduces precision, enabling compression.
Separate quantization tables are used for luminance and chrominance.
Rearrange the 8×8 quantized block into a 1D array using zig-zag ordering.
Apply Run-Length Encoding (RLE) and Huffman Encoding to compress the 1D array.
This removes further redundancy from the image data.