Skip to content

zaccrites/jpeg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JPEG Encoder

A JPEG encoder implemented in Python

Q=20 Comparison

The script does not generate usable .jpg files in truth, but it will perform the transforms needed to convert e.g. a PNG image to JPEG at a requested quality level, showing the difference in each luma and chroma channel from the original source image and the JPEG-ified output.

Encoding Steps

  1. Convert image RGB pixel values to the YCbCr (luma+chroma) color space.
  2. Compute the discrete cosine transform to find coefficients for high and low frequency content in 8x8 pixel blocks.
  3. Compute a quantization table using a specified quality value, then divide each coefficient by the corresponding entry in the table. Divisors increase in magnitude for higher frequency image content.
  4. Round resulting quotients to the nearest integer. This typically rounds high frequency coefficients to zero. Multiply by the original divisor to get the quantized coefficients, many of which will now be zero.

Decoding Steps

  1. Perform an inverse discrete cosine transform to obtain quantized YCbCr pixel values.
  2. Convert YCbCr color data to RGB to display the image.

Compression

The strength of the JPEG encoding process lies in the quantization and removal of high frequency content. High frequency content is less noticeable than low frequency content, so it can be removed with little noticeable impact on many images (notably photographs). By employing run-length encoding and traversing DCT coefficients from lowest frequency to highest, a long string of zeroes in the high frequency section may be represented compactly. Applying a further layer of Huffman coding can further compress the data.

Results

Quality = 90

Q=90 Output

Q=90 Comparison

Q=90 Difference Plots

Quality = 50

Q=50 Output

Q=50 Comparison

Q=50 Difference Plots

Quality = 20

Q=20 Output

Q=20 Comparison

Q=20 Difference Plots

Quality = 10

Q=10 Output

Q=10 Comparison

Q=10 Difference Plots

About

A JPEG encoder implemented in Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages