You are on page 1of 12

BÀI TẬP

THÔNG TIN SỐ
Giáo viên hướng dẫn: Lê Hoàng Uyên Thục
Nhóm sinh viên thực hiện- Nhóm 22:
 Lê Anh Nhật 18DT3
 Trần Hửu Quân 18DT3
 Nguyễn Đắc Hùng Phú 18DT3

Đề bài:
Bài làm:

clear all;
close all;

im=imread('TestFax.bmp');
figure
imshow(im);
a=Encoder(im);
img=Decoder(a);
figure
imshow(img);

%ham nen
function img=Encoder(im)
ww={'11011','10010','010111'};
bb={'0000001111','000011001000','000011001001'};
Wn={'00110101','000111','0111','1000','1011','1100
','1110','1111','10011','10100','00111',...

'01000','001000','000011','110100','110101','10101
0','101011','0100111','0001100','0001000',...

'0010111','0000011','0000100','0101000','0101011',
'0010011','0100100','0011000','00000010',...

'00000011','00011010','00011011','00010010','00010
011','00010100','00010101','00010110','00010111',.
..

'00101000','00101001','00101010','00101011','00101
100','00101101','00000100','00000101','00001010',.
..

'00001011','01010010','01010011','01010100','01010
101','00100100','00100101','01011000','01011001',.
..

'01011010','01011011','01001010','01001011','00110
010','00110011','00110100'};

Bn={'0000110111','010','11','10','011','0011','001
0','000111','000101','000100','0000100',...

'0000101','0000111','00000100','00000111','0000110
00','0000010111','0000011000','0000001000',...

'00001100111','00001101000','00001101100','0000011
0111','00000101000','00000010111','00000011000',..
.

'000011001010','000011001011','00011001100','00001
1001101','000001101000','000001101001','0000011010
10',...

'000001101011','000011010010','000011010011','0000
11010100','000011010101','000011010110','000011010
111',...

'000001101100','000001101101','000011011010','0000
11011011','000001010100','000001010101','000001010
110',...

'000001010111','000001100100','000001100101','0000
01010010','000001010011','000000100100','000000110
111',...

'000000111000','000000100111','000000101000','0000
01011000','000001011001','000000101011','000000101
100',...
'000001011010','000001100110','000001100111'};
s=size(im);
i=1;
img=[];
while(i<=s(1))
j=1;
w=0;
b=0;
while(j<=s(2))
while(im(i,j)==255)
w=w+1;
b=0;
j=j+1;
if (j>250)
break;
end
end
if (w>=192)
temp=char(ww(3));
img=ADD(img,temp);
w=w-192;
else
if (w>=128)
temp=char(ww(2));
img=ADD(img,temp);
w=w-128;
else
if (w>=64)
temp=char(ww(1));
img=ADD(img,temp);
w=w-64;
end
end
end
if (w<=63)
temp=char(Wn(w+1));
img=ADD(img,temp);
end

if (j>250)
break;
end

while(im(i,j)==0)
b=b+1;
w=0;
j=j+1;
if (j>250)
break;
end
end

if (b>=192)
temp=char(bb(3));
img=ADD(img,temp);
b=b-192;
else
if (b>=128)
temp=char(bb(2));
img=ADD(img,temp);
b=b-128;
else
if (b>=64)
temp=char(bb(1));
img=ADD(img,temp);
b=b-64;
end
end
end
if (b<=63)
temp=char(Bn(b+1));
img=ADD(img,temp);
end
end
i=i+1;
end
end

%add
function f=ADD(f,t)
for i=1:length(t)
if t(i)=='0'
f=cat(2,f,0);
else
f=cat(2,f,1);
end
end
end

%giai ma
function img=Decoder(im)
ww={'11011','10010','010111'};

bb={'0000001111','000011001000','000011001001'};
wb=[64,128,192];

Wn={'00110101','000111','0111','1000','1011','1100
','1110','1111','10011','10100','00111',...

'01000','001000','000011','110100','110101','10101
0','101011','0100111','0001100','0001000',...

'0010111','0000011','0000100','0101000','0101011',
'0010011','0100100','0011000','00000010',...

'00000011','00011010','00011011','00010010','00010
011','00010100','00010101','00010110','00010111',.
..

'00101000','00101001','00101010','00101011','00101
100','00101101','00000100','00000101','00001010',.
..

'00001011','01010010','01010011','01010100','01010
101','00100100','00100101','01011000','01011001',.
..

'01011010','01011011','01001010','01001011','00110
010','00110011','00110100'};

Bn={'0000110111','010','11','10','011','0011','001
0','000111','000101','000100','0000100',...

'0000101','0000111','00000100','00000111','0000110
00','0000010111','0000011000','0000001000',...

'00001100111','00001101000','00001101100','0000011
0111','00000101000','00000010111','00000011000',..
.

'000011001010','000011001011','00011001100','00001
1001101','000001101000','000001101001','0000011010
10',...

'000001101011','000011010010','000011010011','0000
11010100','000011010101','000011010110','000011010
111',...

'000001101100','000001101101','000011011010','0000
11011011','000001010100','000001010101','000001010
110',...

'000001010111','000001100100','000001100101','0000
01010010','000001010011','000000100100','000000110
111',...
'000000111000','000000100111','000000101000','0000
01011000','000001011001','000000101011','000000101
100',...

'000001011010','000001100110','000001100111'};
color=2;
x=1;
y=1;
s=size(im);
i=1;
while i<=s(2)
temp='';
j=i;
line=1;

if color~=1
while(length(temp)<=6)

temp=char(strcat(temp,string(im(j))));
if length(temp)>=5
for t=1:3
if temp==string(ww(t))
for q=1:wb(t)
img(x,y)=1;
y=y+1;
if y>250
x=x+1;
y=1;
line=0;
end
end
i=j+1;
temp='';
break;
end
end
end
j=j+1;
if j>s(2)
break;
end
end
temp='';
j=i;
if j>s(2)
break;
end
while(length(temp)<=8)

temp=char(strcat(temp,string(im(j))));
if length(temp)>=4
for t=1:64
if temp==string(Wn(t))
for q=1:(t-1)
img(x,y)=1;
y=y+1;
if y>250
x=x+1;
y=1;
line=0;
end
end
i=j+1;
if line==1
color=1;
else
color=2;
end
temp='123456789';
break;
end
end
end
j=j+1;
if j>s(2)
break;
end
end
end
if line==1
if color~=0
j=i;
temp='';
while(length(temp)<=12)

temp=char(strcat(temp,string(im(j))));
if length(temp)>=10
for t=1:3
if temp==string(bb(t))
for q=1:wb(t)
img(x,y)=0;
y=y+1;
if y>250
x=x+1;
y=1;
line=0;
end
end
i=j+1;
temp='';
break;
end
end
end
j=j+1;
if j>s(2)
break;
end
end
temp='';
j=i;
if j>s(2)
break;
end
while(length(temp)<=12)

temp=char(strcat(temp,string(im(j))));
if length(temp)>=2
for t=1:64
if temp==string(Bn(t))
for q=1:(t-1)
img(x,y)=0;
y=y+1;
if y>250
x=x+1;
y=1;
line=0;
end
end
i=j+1;
if line==1
color=0;
else
color=2;
end

temp='1234567891234';
break;
end
end
end
j=j+1;
if j>s(2)
i=j;
break;
end
end
end
end
end
end

Kết quả:
Ta có số bit sau khi giải nén là: 8625 bit
Dung lượng trước khi nén: 64078 KB.
Dung lượng sau khi nén: 8625/8= 1078,125 KB
>> Tỷ lệ nén là: 64078/(8625/8)=59,4347
Nhận xét:
- Hình ảnh sau khi giải nén và hình ảnh ban đầu đều có lượng như
nhau (khi quan sát bằng mắt thường)
- Dung lượng ảnh sau khi giải nén giảm nhiều lần so với dung
lượng ban đầu
- Vì vậy chúng ta có thể kết luận ảnh sau khi giải nén sử dụng
phương pháp nén không suy hao có chất lượng cực tốt.

You might also like