Code covered by the BSD License  

Highlights from
Automata Engineer 2010 NITK- Documented version

image thumbnail

Automata Engineer 2010 NITK- Documented version

by

 

The documented version of the code which solves the problem statement of Automata Engineer 2010 NITK

getadmat( are,wall )
function [ adj_mat ] = getadmat( are,wall )
%%getadmat is used to get the adjecency matrix representing the arena
%input matrices: are and wall are filtered bw images of arena and wall 
wall_dil=imdilate(wall,strel('square',3));
wall3=imrotate(wall_dil,10);
im_eroded=imerode(are,strel('square',3));
are3=imrotate(im_eroded,10);
[wall_lab,test]=bwlabel(are3,4);
cenar=regionprops(wall_lab,'Centroid','Area');

adj_mat=[1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
         0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
         0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
         0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
         0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
         0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
         0 1 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
         0 0 1 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
         0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
         0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
         0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
         0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
         0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0;
         0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0;
         0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0;
         0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0;
         0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0;
         0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0;
         0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0;
         0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0;
         0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 1 0 0 0 0 0;
         0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 0 0 0 0;
         0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 0 0;
         0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 0;
         0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0;
         0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 1;
         0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0;
         0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0;
         0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1 0;
         0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 1;
         0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1];

for i=2:5
wall_co=[(cenar(i).Centroid(1)+cenar(i+1).Centroid(1))/2,(cenar(i).Centroid(2)+cenar(i+1).Centroid(2))/2];
wall_coint=int16(wall_co);
if(wall3(wall_coint(2),wall_coint(1))==1)
    adj_mat(i,(i+1))=0;
    adj_mat((i+1),i)=0;
end
    
end
%wallhor1

for i=7:10
wall_co=[(cenar(i).Centroid(1)+cenar(i+1).Centroid(1))/2,(cenar(i).Centroid(2)+cenar(i+1).Centroid(2))/2];
wall_coint=int16(wall_co);
if(wall3(wall_coint(2),wall_coint(1))==1)
    adj_mat(i,(i+1))=0;
    adj_mat((i+1),i)=0;
end

end
%wallhor2

for i=12:15
wall_co=[(cenar(i).Centroid(1)+cenar(i+1).Centroid(1))/2,(cenar(i).Centroid(2)+cenar(i+1).Centroid(2))/2];
wall_coint=int16(wall_co);
if(wall3(wall_coint(2),wall_coint(1))==1)
    adj_mat(i,(i+1))=0;
    adj_mat((i+1),i)=0;
end

end
%wallhor3

for i=17:20
wall_co=[(cenar(i).Centroid(1)+cenar(i+1).Centroid(1))/2,(cenar(i).Centroid(2)+cenar(i+1).Centroid(2))/2];
wall_coint=int16(wall_co);
if(wall3(wall_coint(2),wall_coint(1))==1)
    adj_mat(i,(i+1))=0;
    adj_mat((i+1),i)=0;
end

end
%wallhor4

for i=22:25
wall_co=[(cenar(i).Centroid(1)+cenar(i+1).Centroid(1))/2,(cenar(i).Centroid(2)+cenar(i+1).Centroid(2))/2];
wall_coint=int16(wall_co);
if(wall3(wall_coint(2),wall_coint(1))==1)
    adj_mat(i,(i+1))=0;
    adj_mat((i+1),i)=0;
end

end
%wallhor5

%wallhor6=[];
for i=27:30
wall_co=[(cenar(i).Centroid(1)+cenar(i+1).Centroid(1))/2,(cenar(i).Centroid(2)+cenar(i+1).Centroid(2))/2];
wall_coint=int16(wall_co);
if(wall3(wall_coint(2),wall_coint(1))==1)
    adj_mat(i,(i+1))=0;
    adj_mat((i+1),i)=0;
end

end
%wallhor6

%wall_hor_mat=[wallhor1 wallhor2 wallhor3 wallhor4 wallhor5 wallhor6];

for i=[2,7,12,17,22]
wall_co=[(cenar(i).Centroid(1)+cenar(i+5).Centroid(1))/2,(cenar(i).Centroid(2)+cenar(i+5).Centroid(2))/2];
wall_coint=int16(wall_co);
if(wall3(wall_coint(2),wall_coint(1))==1)
    adj_mat(i,(i+5))=0;
    adj_mat((i+5),i)=0;
end

end
%wallver1

%wallver2=[];
for i=[3,8,13,18,23]
wall_co=[(cenar(i).Centroid(1)+cenar(i+5).Centroid(1))/2,(cenar(i).Centroid(2)+cenar(i+5).Centroid(2))/2];
wall_coint=int16(wall_co);
if(wall3(wall_coint(2),wall_coint(1))==1)
    adj_mat(i,(i+5))=0;
    adj_mat((i+5),i)=0;
end
end
%wallver2

%wallver3=[];
for i=[4,9,14,19,24]
wall_co=[(cenar(i).Centroid(1)+cenar(i+5).Centroid(1))/2,(cenar(i).Centroid(2)+cenar(i+5).Centroid(2))/2];
wall_coint=int16(wall_co);
if(wall3(wall_coint(2),wall_coint(1))==1)
    adj_mat(i,(i+5))=0;
    adj_mat((i+5),i)=0;
end
end
%wallver3

%wallver4=[];
for i=[5,10,15,20,25]
wall_co=[(cenar(i).Centroid(1)+cenar(i+5).Centroid(1))/2,(cenar(i).Centroid(2)+cenar(i+5).Centroid(2))/2];
wall_coint=int16(wall_co);
if(wall3(wall_coint(2),wall_coint(1))==1)
    adj_mat(i,(i+5))=0;
    adj_mat((i+5),i)=0;
end
end
%wallver4

%wallver5=[];
for i=[6,11,16,21,26]
wall_co=[(cenar(i).Centroid(1)+cenar(i+5).Centroid(1))/2,(cenar(i).Centroid(2)+cenar(i+5).Centroid(2))/2];
wall_coint=int16(wall_co);
if(wall3(wall_coint(2),wall_coint(1))==1)
    adj_mat(i,(i+5))=0;
    adj_mat((i+5),i)=0;
end
end
%wallver5


%wall_ver_mat=[wallver1; wallver2; wallver3; wallver4; wallver5];


%   Detailed explanation goes here


end

Contact us