Arithmetic coding for image compression
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
2017년 7월 25일
1 개 추천
reshape() the image into a vector. Apply arithmetic encoding.
댓글 수: 11
haithem abdelghany
2017년 7월 26일
편집: Walter Roberson
2017년 7월 27일
I write the following code to convert image to vector
c=dicomread('brain.dcm');
c=im2uint8(c);
imgV = reshape(c.', 1, []); % Convert to vector
counts = [99 1];
arithenco(imgV,counts)
but it gives me
The symbol sequence parameter must be a vector of positive finite integers
arithenco(imgV+1,counts)
Note: your counts vector should be the same length as the number of unique values in imgV
It give me the following error
The symbol sequence parameter can take values only between 1 and the length of the symbol counts parameter.
Reread what I said before,
"Note: your counts vector should be the same length as the number of unique values in imgV"
Is there any technique in matlab to make counts vector equal imgV vector
You have two choices:
1) Use a fixed vector of counts that matches some probability model you have determined. This has the advantage of not needing to store / transmit the dictionary for decoding; or
2) Use the actual counts. This has the advantage of providing the best compression, but does require storing/transmitting the list of symbols used (because, if I recall correctly, it is not permitted to use a count of 0.)
[unique_symbols, ~, symbol_number] = unique(imgV);
symbol_counts = accumarray(symbol_number, 1);
coded_result = arithenco(symbol_number, symbol_counts);
and you need to store/transmit unique_symbols to decode.
Thank you but finally I want to save the coded_result I saved it as .mat and the problem is that the output file size increase Is there any other method to save the output file
The size of a .mat can be larger or smaller than the size of the data being saved. You should save into .mat files for ease of recalling data exactly was it was saved; you should not save into .mat files expecting them to be any particular size.
If you are looking at the file size from a data compression point of view, you should be using something like,
fid = fopen('compressed_data.dat', 'w');
fwrite(fid, uint8(length(unique_symbols)) );
fwrite(fid, 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) );
fwrite(fid, unused_bits_of_last_byte);
fwrite(fid, coded_as_uint8);
fclose(fid);
This creates a file with the following structure:
- a single byte that gives the length of the symbol table
- a vector that length of bytes that are the symbols being encoded
- a single byte that gives the number of unused bits in the last byte of the data that follows
- a vector of the arithenco results converted from a vector of double(0) and double(1) into a stream of bytes by packing 8 bits per byte
The "number of unused bits in the last byte" is there because the conversion of a stream of bits into bytes has a problem if the number of bits being converted is not an exact multiple of 8. The buffer() call (from the Signal Processing Toolbox) puts in 0s for the extra bits and when decoding you need a way to know when to stop decoding and ignore the final few 0s.
There are other approaches that can be used instead of coding the number of unused bits, and some of the other approaches can be pretty useful in some situations, but they are more complicated to decode.
Thank you it is great
Astha Singh
2021년 7월 16일
can you tell how to save this as an image
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개)
카테고리
도움말 센터 및 File Exchange에서 Denoising and Compression에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
