I am new to image compression topic and really appreciate it if someone could help me understand how compression rati works in this case. Assuming I have JPEG lossless coder that encodes the following image:

2 3 4 3
1 A B C

I have used predictive coding and Huffman to obtain the binary representations (codes) for pixels A, B and C:

Which are:

A=0 -> 0 
B=3 -> 1101
C=0 -> 0

How can I calculate the compression ratio achieved for coding of the pixels A, B and C (jointly) assuming that the original image has pixel values ranging from 1 to 8?

  • 1
    $\begingroup$ The given answer seems quite clear. Do not hesitate to accept it $\endgroup$ Feb 14, 2018 at 18:48
  • $\begingroup$ the original image is 256*256 pixel single band (gray scale) 8-bit per pixel this file is 65.536 bytes (64k) after compression the image file is 6.554 byte compression ratio is ? $\endgroup$ Aug 31, 2018 at 12:21

1 Answer 1


Compression ratio is $$ \frac{N_{uncomp}^b}{N_{comp}^b}$$ where ${N_{comp}^b}$ is the total number bits requried to represent those $3$ pixels $A$,$B$, and $C$ while ${N_{uncomp}^b}$ is the total number of bits required when they are not compressed.

Based on your claims, assuming that, those three pixels had $8$ levels with fixed length coding (FLC) of $3$ bits per pixel then; ${N_{uncomp}^b} = 3 \times 3 = 9$ bits in total. And again based on your variable length code (VLC) of the lossless coding scheme which uses $1$ bit for $A$ and $C$ and $4$ bits for $B$ you have ${N_{comp}^b} = 1 + 4 + 1 = 6$ bits in the compressed case, hence the ratio is $$ \frac{N_{uncomp}^b}{N_{comp}^b} = \frac{9}{6} = \frac{3}{2} $$

which means a $1.5 \times$ reduction in the number of bits required to represent the same source compared to its uncompressed form.

Note that you can also use the reciprocal of that ratio to indicate a similar metric, which would be $2/3$ in this case indicating the size that compressed form will have compared to the original.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.