File Exchange

image thumbnail

JPEG Baseline Encoder

version 1.3 (774 KB) by

This baseline uses an encoding scheme based on the Discrete Cosine Transform (DCT).

3 Ratings



View License

The JPEG compression scheme is divided into the following stages:
1. Transform the image into an optimal color space.
2. Adjust Aspect Ratio 16:9
3. Digitization Scheme 4:2:0.
4. Apply a Discrete Cosine Transform (DCT) to blocks of pixels, thus removing redundant image data.
5. Quantize each block of DCT coefficients using weighting functions optimized for the human eye.
6. Encode the resulting coefficients (image data) using a Huffman variable word-length algorithm to remove redundancies in the coefficients.
7. Byte Stuffing.
8. Header JFIF
9. JPG Data Store

Comments and Ratings (11)

There is a mistake in the Huffman table. The codeword of the second codeword in the last column is: '1111111110001000'

Kenn Lu

Kyo ,I encod the Y ,Cb and Cr component.
But I am also facing the same problem in this JFIF header. Pls help me.


it doesn't support color images and needs significant modification in JFIF header


bipul (view profile)

Kyo, if your problem is solved , will you like to tell me, i am also facing the same problem, jpg is saving as bw image, i need a color saving


kyo (view profile)

Hi, can you check this for me, output image is endomaged :(
this is the link:


kyo (view profile)

I want to save the jpeg file as color, i did do all process (dct,quantif,entropy coding) for my 3 COMPENENT, so i have 3 arrays binary coded (or we can say 3 vectorseam because stream must be vector):
Y_encoded, Cb_encoded, Cr_encoded
- Can you write me the order of fields that i have to create them on my stream vector to get a color image (with function write of corse)
for exemple: SOI APP0 ..............EOI ?????
thank you


Jorgenhoc (view profile)

Hi kyo,
Please review the update with comments made ​​and ask me any questions.


kyo (view profile)

thank you for your answer, i need your help urgent in this few days,
please contact me on my email (facebook)

Thank you again


Jorgenhoc (view profile)

Hi kyo,
Yes, I can help you, but right now it impossible for me. Tomorrow I will help you.
Good luck. I am sorry, but now I have plenty to do.


kyo (view profile)

can you help me please with some points:
1- how can i créate jfif file for Y Cb Cr file = output file will be a color image
2- more explication for all bytes of your header, marker
waiting you
thank you



Including comments of the JFIF header.

MATLAB Release
MATLAB 7.14 (R2012a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video