# IMAGE PROCESSING

" Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference "-Robert Frost

### Circle

Did you come here by searching for ‘How to draw a circle in MATLAB’ then definitely at the end of the article you will draw a circle.
Let me first discuss how to draw a circle and then we will see about concentric circles.
The equation of the circle: (x-x1).^2 +(y-y1).^2=r^2.
where x and y are the centre of the circle and r is the radius.
Here I am not using any plot function, just the equation of the circle.

Initialize the image with 255 and find the centre of the image. The variable ‘sz’ changes the size of the image. The image is a square matrix. Then ‘rad’ contains the radius of the circle.
sz=300;
clear RGB
RGB(1:sz,1:sz,1:3)=255;

I am storing the x co-ordinates in x and y co-ordinates in y.

[x y]= find(RGB==255);

‘xc’ and ‘yc’ contains the midpoint of the circle.

xc=ceil((sz+1)/2);
yc=ceil((sz+1)/2);

Here I am finding the points which satisfy the equation. To avoid for loop I am using the ‘find’ function.

d=find(((x-xc).^2+(y-yc).^2) <= r);

The points that are stored in d contains the index value for x and y that satisfies the equation.
for i=1:size(d,1)

RGB(x(d(i)),y(d(i)),:)=0;

end
 Before edge detection

The rest of the procedure is same. I found the edge and I strengthen the edge by dilating.

B=rgb2gray(RGB);

ED=edge(B);
SE=strel('disk',1);
cir=~imdilate(ED,SE);
figure,imshow(cir);

Concentric circles:

The procedure is same but I use loop to produce ‘n’ no.of circles.
for i=1:8

for j=1:size(r,1)

if(mod(i,2)==0)
RGB(x(r(j)),y(r(j)),:)=255;
end
if(mod(i,3)==1)
RGB(x(r(j)),y(r(j)),:)=0;
end

end
end

 Before edge detection

 final image

Check some optical Illusion concept on circle using MATLAB: http://angeljohnsy.blogspot.com/2014/06/optical-illusion-circle.html

If you find any difficulty in the code, Mail me, I will send the code.

Like "IMAGE PROCESSING" page

lrq3000 said...

Hello,

Thank you for this great tutorial.

You can simplify the rendering of the solution by replacing the loop for i=1:size(d,1) ... simply by: RGB(d)=0; since d already contains the index of the element at the intersection of x and y.

Ahmed Daw said...

Ahmed Daw said...

really I need ur help?

Emmanual Robin said...

how to fill circle with the color inside and outside with different color

Emmanual Robin said...

how will i fill the circle with the different colors with inside as well as outside?

Aaron Angel said...

@Emmanual Robin

Use 'bwlabel' function and 'label2rgb' function.

Unknown said...

how to find the centroid of a hand and its fingertip from the centroid ....can you help me n coding

Zaàfoury Rabàà said...

how to draw a circle trigonometry around an image in matlab