Arithmetic coding for image compression
24 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Walter Roberson
2017-7-25
reshape() the image into a vector. Apply arithmetic encoding.
11 个评论
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:
- the compressed values become statistically indistinguishable from random; or
- 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 Center 和 File Exchange 中查找有关 Denoising and Compression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!