Arithmetic coding for image compression

15 views (last 30 days)
I am working on the topic of image compression I found built in matlab function for arithmetic coding which is arithenco I want to use it in image compression can any give me example on how to this function for image compression.

Accepted Answer

Walter Roberson
Walter Roberson on 25 Jul 2017
reshape() the image into a vector. Apply arithmetic encoding.
  11 Comments
Astha Singh
Astha Singh on 16 Jul 2021
can you tell how to save this as an image
Walter Roberson
Walter Roberson on 16 Jul 2021
bytes = uint8([]);
bytes = [bytes, uint8(length(unique_symbols)) ];
bytes = [bytes, uint8(unique_symbols)];
coded_as_uint8 = uint8(bin2dec(char(buffer(coded_result,8) + '0').'));
unused_bits_of_last_byte = uint8(length(coded_as_uint8) * 8 - length(coded_result) );
bytes = [bytes, unused_bits_of_last_byte];
bytes = [bytes, coded_as_uint8];
imwrite(bytes, 'useless_image.tif');
The above will fail if the encoding requires more than 4 gigabytes. You must use .tif to be able to handle that size; if you can be sure that the encoding will be no more than 2 gigabytes (minus one byte) then you can use .png .
.tif and .png files can be used to store arbitrary bytes without loss. (.bmp too, but .bmp has a limit of 30000 bytes for this purpose.)
You will not get any useful output if you ask to display an image created in this way: if the arithematic encoding worked properly, then the output will look pretty much random. Just because you can create an image file does not mean that the image file is understandable to humans.
People keep expecting that compressed images look like... I don't know. A distorted but partly recognizable version of the original, I guess? A smaller and possibly recolored version of the original?
But compression theory says that you can continue to compress until one of two things happens:
  1. the compressed values become statistically indistinguishable from random; or
  2. the overhead needed to describe the data transformations to apply more compression starts to take more space than just listing the compressed bytes as they are.
If you could still make out any resemblence between the original image and the data representing the compressed image, then you did not do a good enough job of compression !!

Sign in to comment.

More Answers (0)

Categories

Find more on Denoising and Compression in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!