Arithmetic coding for image compression

조회 수: 25 (최근 30일)
haithem abdelghany
haithem abdelghany 2017년 7월 25일
댓글: Walter Roberson 2021년 7월 16일
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.

채택된 답변

Walter Roberson
Walter Roberson 2017년 7월 25일
reshape() the image into a vector. Apply arithmetic encoding.
  댓글 수: 11
Astha Singh
Astha Singh 2021년 7월 16일
can you tell how to save this as an image
Walter Roberson
Walter Roberson 2021년 7월 16일
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 !!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Denoising and Compression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by