KELOMPOK 12_Kompresi BWT
-
Upload
nuragisna-eka-sukmadiyana -
Category
Documents
-
view
223 -
download
0
Transcript of KELOMPOK 12_Kompresi BWT
-
8/2/2019 KELOMPOK 12_Kompresi BWT
1/15
KELOMPOK 12
Tugas Kompresi Menggunakan Metode Burrows Wheeler
Transform (BWT) Menggunakan MatLab
Disusun oleh :
Nur Agisna Eka Sukmadiyana (109091000026)
Miftakhul Hasan (109091000133)
Kelas: TI 6A Multimedia
PROGRAM STUDI TEKNIK INFORMATIKA
FAKULTAS SAINS DAN TEKNOLOGI
UIN SYARIF HIDAYATULLAH JAKARTA
2012
-
8/2/2019 KELOMPOK 12_Kompresi BWT
2/15
Kompresi menggunakan metode Burrows Wheeler
Source :clear all;clc;file_open=fopen('test.txt','r');
file_read=fread(file_open,'uint8');fclose(file_open);a=file_read;b=zeros(1,2*length(a));
for sort_len=1:length(b)if(sort_len>length(a))b(sort_len)=a(sort_len-length(a));
elseb(sort_len)=a(sort_len);
endenda=char(a);
b=char(b);to_sort=zeros(length(a),length(a));for row_sort=1:length(a)
to_sort(row_sort,:)=b(row_sort:length(a)+row_sort-1);endchar(to_sort);[lexi_sorted_data,ind]=sortrows(to_sort);char(lexi_sorted_data);
encoded_data=lexi_sorted_data(:,length(a));primary_index=find(ind==2);out_data=[encoded_data',primary_index];file_bwt=fopen('bwt.cmp','w');fwrite(file_bwt,out_data,'uint8');fclose(file_bwt);
%%%%%%%%%%%%%%%%BWT DECODING STARTSdec_bwt_file=fopen('bwt.cmp','r');dec_bwt_read=fread(dec_bwt_file,'uint8');fclose(dec_bwt_file);
encoded_data=dec_bwt_read(1:length(dec_bwt_read)-1);primary_index=dec_bwt_read(length(dec_bwt_read));
sorted_data=sort(encoded_data);
vector_flag=ones(1,length(encoded_data))';vector=zeros(1,length(encoded_data))';%%%%%%%preparing vector tablefor i=1:length(sorted_data)
for j=1:length(sorted_data)if(encoded_data(j)==sorted_data(i) && vector_flag(j))
% clc;% encoded_data(j);% sorted_data(i);
vector_flag(j);
-
8/2/2019 KELOMPOK 12_Kompresi BWT
3/15
vector(i)=j;vector_flag(j)=0;break
endend
end
index=primary_index;reconst_data=zeros(1,length(encoded_data));%getting original data backfor i=1:length(encoded_data)
reconst_data(i)=encoded_data(index);index=vector(index);
end
char(lexi_sorted_data(:,length(a)))primary_index=find(ind==2)
char(reconst_data)
-
8/2/2019 KELOMPOK 12_Kompresi BWT
4/15
Hasil Terjemahan Kompresi
ans =
-
8/2/2019 KELOMPOK 12_Kompresi BWT
5/15
m
r
n
A
l
r
M
n
m
_
r
r
h
h
.
t
t
@
a
-
8/2/2019 KELOMPOK 12_Kompresi BWT
6/15
A
a
i
o
t
I
i
a
a
c
h
a
a
m
m
k
k
o
primary_index =
-
8/2/2019 KELOMPOK 12_Kompresi BWT
7/15
9
ans =
MA Imran Akthar
>>
PrintScreen :
-
8/2/2019 KELOMPOK 12_Kompresi BWT
8/15
-
8/2/2019 KELOMPOK 12_Kompresi BWT
9/15
Program BWT Decoder
function bwtdec%bwtdec is a BWT decoder% type bwtdec at the command prompt% this particular function reads the transformed(BWT)% file bwt.txt and then geets the original file back% as orig_text% BE SURE that the transformed file BWT.TXT is in the% current directory%copyright
-
8/2/2019 KELOMPOK 12_Kompresi BWT
10/15
%MA Imran [email protected]%please send me ur feedback and suggestion%do check out my other files at MATLAB CENTRAL FILE EXCHANGE
%http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectType=author&objectId=1093740
clear all;clc;dec_bwt_file=fopen('bwt.cmp','r');dec_bwt_read=fread(dec_bwt_file,'uint8');fclose(dec_bwt_file);disp('BWT DECODING Started');
encoded_data=dec_bwt_read(1:length(dec_bwt_read)-1);primary_index=dec_bwt_read(length(dec_bwt_read));
sorted_data=sort(encoded_data);vector_flag=ones(1,length(encoded_data))';
vector=zeros(1,length(encoded_data))';%%%%%%%preparing vector tablefor i=1:length(sorted_data)
for j=1:length(sorted_data)if(encoded_data(j)==sorted_data(i) && vector_flag(j))
% clc;% encoded_data(j);% sorted_data(i);
vector_flag(j);vector(i)=j;vector_flag(j)=0;break
endend
end
index=primary_index;reconst_data=zeros(1,length(encoded_data));%getting original data backfor i=1:length(encoded_data)
reconst_data(i)=encoded_data(index);index=vector(index);
end
% char(lexi_sorted_data(:,length(a)));% primary_index=find(ind==2);
% char(reconst_data);
rec_file=fopen('orig_file.txt','w');fwrite(rec_file,reconst_data,'uint8');fclose(rec_file);disp('BWT Decosing over..');disp('file writeen back as orig_file.txt')
-
8/2/2019 KELOMPOK 12_Kompresi BWT
11/15
Hasil Decoder :
-
8/2/2019 KELOMPOK 12_Kompresi BWT
12/15
Program BWT Encoder
Source :function bwtenc%bwtenc is a BWT encoder% type bwtenc at the command prompt and
% a user interface is dispalyed.% currently,its just text file.u can select just text files% for now.%the BWT transformed file is written as bwt.cmp in the%current directory%copyright%MA Imran [email protected]%please send me ur feedback and suggestion%do check out my other files at MATLAB CENTRAL FILE EXCHANGE
-
8/2/2019 KELOMPOK 12_Kompresi BWT
13/15
%http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectType=author&objectId=1093740
clear all;
clc;path=pwd;[filename, pathname] = uigetfile('*.txt', 'Pick a file');cd(pathname)file_open=fopen(filename,'r');file_read=fread(file_open,'uint8');fclose(file_open);cd(path)disp('precessing..BWT Transform');a=file_read;b=zeros(1,2*length(a));
for sort_len=1:length(b)
if(sort_len>length(a))b(sort_len)=a(sort_len-length(a));else
b(sort_len)=a(sort_len);endenda=char(a);b=char(b);to_sort=zeros(length(a),length(a));for row_sort=1:length(a)
to_sort(row_sort,:)=b(row_sort:length(a)+row_sort-1);endchar(to_sort);[lexi_sorted_data,ind]=sortrows(to_sort);char(lexi_sorted_data);
encoded_data=lexi_sorted_data(:,length(a));primary_index=find(ind==2);out_data=[encoded_data',primary_index];file_bwt=fopen('bwt.cmp','w');fwrite(file_bwt,out_data,'uint8');fclose(file_bwt);disp('BWT Transform over');disp('file written to bwt.cmp');
-
8/2/2019 KELOMPOK 12_Kompresi BWT
14/15
Hasil Encoder :
-
8/2/2019 KELOMPOK 12_Kompresi BWT
15/15