フィルターのクリア

LZW Compression Via Gif Transformation

1 回表示 (過去 30 日間)
samet ercetin
samet ercetin 2018 年 2 月 26 日
コメント済み: Jan 2018 年 2 月 27 日
Hi everyone, i can compress an array which be formed binary data but i can't decompress it. I use "gif" transformation to compress the array.
%Generates bits with equal probabilities
n=100000;
prob = [.5 .5];
Input=[0 1];
fp =randsrc(1,n,[Input;prob]);
data1 = uint8(fp);
imwrite(data1,'1KB.gif');
fp2 = fopen('1KB.gif','rb');
data = uint8(fread(fp2));
it works but i need to de decompress it.
i need the first binary array after the decompression. How can i do that ?
Thanks for your Help.
  3 件のコメント
samet ercetin
samet ercetin 2018 年 2 月 26 日
編集済み: samet ercetin 2018 年 2 月 26 日
thanks, how can i ignore these header data?(of course if it is possible)
Jan
Jan 2018 年 2 月 26 日
It is not trivial to interpret the specifications of the GIF 89a standard, see https://www.w3.org/Graphics/GIF/spec-gif89a.txt. It will be much easier to use one of the functions of the file exchange. It would help to post a suggestion, if you explain, what you want to do.

サインインしてコメントする。

採用された回答

Jan
Jan 2018 年 2 月 26 日
編集済み: Jan 2018 年 2 月 26 日
Writing GIF compresses the data with LZW, but adds a header also. If you really want this, imread can import the data again.
I'd prefer a direct approach, e.g. FEX: lzw compression or FEX: lzw image codec.
  4 件のコメント
samet ercetin
samet ercetin 2018 年 2 月 27 日
Code is that;
clc;
clear;
clear all;
%Generates bits with equal probabilities
n=60000;
prob = [.5 .5]
Input=[0 1]
fp =randsrc(1,n,[Input;prob])
input = uint8(fp);
imwrite(input,'1KB.gif');
fp2 = fopen('1KB.gif','wb');
output = uint8(fread(fp2));
let me explain clearly what i want to do.
First i want to compress data which is formed binary data by using LZW.(I choose the gif transformation for that because it looks easier)
i can compress data by using first step but i can't access the binary files after the compression. I need the compressed binary data after the compression. I couldn't access these data by using "imread".
At least, i want to decopress these data. I want to convert them first binary format.
Is it possible by using "gif" transformation?
Jan
Jan 2018 年 2 月 27 日
"GIF" is not a "transformation" or a LZW compression method, but a format of image files. Although the data are compressed by LZW, it contains color tables and further header information. Therefore it is a bad idea to use a GIF files as a compression method.
Although you can get the binary data of the GIF image file by fread, you will get the additional header information also.
Therefore I strongly recommend, to search in the FileExchange and the internet for "MATLAB lzw" and use one of the these tools. All you have to do is to download and run it. This will be less complicated than struggling with the creation of image files and trying to access the compressed binary data.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by