Code covered by the BSD License

# Automata Engineer 2010 NITK- Documented version

### Anurag Ranjan (view profile)

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

get_cir( bw )
```function [lcen, scen] = get_cir( bw )
%returns the centroids of the two circles, larger and smaller
%input: the inverted filtered bw image of the arena such that the circles
%       are white
bw=imrotate(bw,3);
leb=[0 0];
i=1;
bw = bwareaopen(bw,10);
[B,L] = bwboundaries(bw,'noholes');
stats = regionprops(L,'Area','Centroid');

%threshold = 0.94;
%imtool(bw)
% loop over the boundaries
for k = 1:length(B)

% obtain (X,Y) boundary coordinates corresponding to label 'k'
boundary = B{k};

% compute a simple estimate of the object's perimeter
delta_sq = diff(boundary).^2;
perimeter = sum(sqrt(sum(delta_sq,2)));

% obtain the area calculation corresponding to label 'k'
area = stats(k).Area;

% compute the roundness metric
metric = 4*pi*area/perimeter^2;
if (metric>0.8 && metric<1.2)
leb(i)=k;
%area(i)=stats(k).Area;
%cent(i)=stats(k).Centroid;
i=i+1;
end

%met(1,k)=metric;

% display the results
% metric_string = sprintf('%2.2f',metric);

% mark objects above the threshold with a black circle
%if metric > threshold
% centroid = stats(k).Centroid;
%plot(centroid(1),centroid(2),'ko');
%end

%text(boundary(1,2)-35,boundary(1,1)+13,metric_string,'Color','y',...
%    'FontSize',14,'FontWeight','bold');

end

%title(['Metrics closer to 1 indicate that ',...
%      'the object is approximately round']);

if(stats(leb(1)).Area > stats(leb(2)).Area)
lcen=stats(leb(1)).Centroid;
scen=stats(leb(2)).Centroid;
else
lcen=stats(leb(2)).Centroid;
scen=stats(leb(1)).Centroid;
end
%cent=[lcen scen];

% else retake image and try

end

```