Drawing Circles Around Round Object

Drawing shapes to highlight certain objects could be done in several ways. Previous examples illustrate few ways of drawing object by overwriting pixel value as well as by adding a "patch" on top of an image. This example shows how to draw circles around a round object just simply using "plot" command

1. Original image

S = imread('pic13.jpg');
S = im2bw(S);
S2 = ~S;
imshow(S2);


2. Extracting required objects' properties. Required properties are centroid and the area of the round objects. The area property is used to compute the radius of the object.

S3 = bwlabel(S2);
S4 = regionprops(S3,'Centroid','area');
R = sqrt(S4(1).Area/pi);
h = S4(1).Centroid(1);
k = S4(1).Centroid(2);

3. Drawing circles around 1st object with different radius by refering to the radius of the object.

ratio = [2 1.5 1];
nR = round(R*ratio);
t = 0:pi/20:2*pi;
x1 = (h+nR'*cos(t))';
y1 = (k+nR'*sin(t))';
hold on;
plot(x1,y1);