You are on page 1of 6

Nhóm 9.

Thông tin số 18N40


Nguyễn Anh Tuấn
Nguyễn Văn Trường
Trương Việt Nam Trân

Bài Tập 2C :
Code Matlab :

clc;
makeupW=['11011 ';
'10010 ';
'010111'];

makeupB=[ '0000001111 ';


'000011001000';
'000011001001'];

terminatingW=['00110101';
'000111 ';
'0111 ';
'1000 ';
'1011 ';
'1100 ';
'1110 ';
'1111 ';
'10011 ';
'10100 ';
'00111 ';
'01000 ';
'001000 ';
'000011 ';
'110100 ';
'110101 ';
'101010 ';
'101011 ';
'0100111 ';
'0001100 ';
'0001000 ';
'0010111 ';
'0000011 ';
'0000100 ';
'0101000 ';
'0101011 ';
'0010011 ';
'0100100 ';
'0011000 ';
'00000010';
'00000011';
'00011010';
'00011011';
'00010010';
'00010011';
'00010100';
'00010101';
'00010110';
'00010111';
'00101000';
'00101001';
'00101010';
'00101011';
'00101100';
'00101101';
'00000100';
'00000101';
'00001010';
'00001011';
'01010010';
'01010011';
'01010100';
'01010101';
'00100100';
'00100101';
'01011000';
'01011001';
'01011010';
'01011011';
'01001010';
'01001011';
'00110010';
'00110011';
'00110100'];

terminatingB=['0000110111 ';
'010 ';
'11 ';
'10 ';
'011 ';
'0011 ';
'0010 ';
'000111 ';
'000101 ';
'000100 ';
'0000100 ';
'0000101 ';
'0000111 ';
'00000100 ';
'00000111 ';
'000011000 ';
'0000010111 ';
'0000011000 ';
'0000001000 ';
'00001100111 ';
'00001101000 ';
'00001101100 ';
'00000110111 ';
'00000101000 ';
'00000010111 ';
'00000011000 ';
'000011001010';
'000011001011';
'000011001100';
'000011001101';
'000001101000';
'000001101001';
'000001101010';
'000001101011';
'000011010010';
'000011010011';
'000011010100';
'000011010101';
'000011010110';
'000011010111';
'000001101100';
'000001101101';
'000011011010';
'000011011011';
'000001010100';
'000001010101';
'000001010110';
'000001010111';
'000001100100';
'000001100101';
'000001010010';
'000001010011';
'000000100100';
'000000110111';
'000000111000';
'000000100111';
'000000101000';
'000001011000';
'000001011001';
'000000101011';
'000000101100';
'000001011010';
'000001100110';
'000001100111'];

im=imread('TestFax.bmp');
mat=[];
for i= 1:250
j=2;
count=1;
while (j <= 250)
if j<250
if im(i,j-1) == im(i,j)
count=count+1;
else
mat= cat(1,mat,[count im(i,j-1)]);
count=1;
end
else
if im(i,j-1) == im(i,j)
count=count+1;
mat= cat(1,mat,[count im(i,j)]);
else
mat= cat(1,mat,[count im(i,j-1)]);
count=1;
mat= cat(1,mat,[count im(i,j)]);
end
end
j=j+1;
end
end
mahoa=[];
for i=1:length(mat)
a=double(floor(double(mat(i,1))/192));
b=double(floor(double((mat(i,1))-a*192)/128));
c=double(floor(double((mat(i,1))-a*192-b*128)/64));
d=double(mat(i,1))-a*192-b*128-c*64;
fax='';
if mat(i,2)==255
if a==1
fax=string(makeupW(3,:));
end
if b==1
fax=fax+ string(makeupW(2,:));
end
if c==1
fax= fax + string(makeupW(1,:));
end
fax = fax + string(terminatingW(d+1,:));

else
if a==1
fax=string(makeupB(3,:));
end
if b==1
fax=fax + string(makeupB(2,:));
end
if c==1
fax= fax + string(makeupB(1,:));
end

fax=fax + string(terminatingB(d+1,:));

end
mahoa=cat(1,mahoa,fax);
end
giaima1=[];
for i=1:length(mahoa)
a=char(strtrim(mahoa(i)));
j=2;
q=1;
bw=0;
len=0;
while(j <= length(a))
for k=1:3
if ss(strtrim(makeupW(k,:)),a(q:j))
bw=255;
len=len + 64*k;
q=j;
break;
elseif ss(strtrim(makeupB(k,:)),a(q:j))
bw=0;
len=len + 64*k;
q=j;
break;
end
end
for k=1:64
if ss(strtrim(terminatingW(k,:)),a(q:j))
bw=255;
len=len + k-1;
q=j;
break;
elseif ss(strtrim(terminatingB(k,:)),a(q:j))

bw=0;
len=len +k-1;
q=j;
break;
end
end

j=j+1;
end
giaima1=cat(1,giaima1,[len bw]);
end

n=length(giaima1);
im2=[];
low=1;
high=1;
while( high<=n)
count=0;
while( count<250)
count=count+giaima1(high,1);
if count < 250
high=high+1;
end
end
mat2=[];
for j=low:high
if giaima1(j,2)==255
mat2=cat(2,mat2,linspace(255,255,giaima1(j,1)));
else
mat2=cat(2,mat2,linspace(0,0,giaima1(j,1)));
end
end
im2=cat(1,im2,mat2);
low=high+1;
high=high+1;
end
function x=ss(a,b)
x=0;
if length(a)==length(b)
for i=1:length(a)
if a(i)==b(i)
x=1;
else
x= 0;
break;
end
end
end
end

You might also like