Problems with Matlab Projects? You may face many Problems, but do not worry we are ready to solve your Problems. All you need to do is just leave your Comments. We will assure you that you will find a solution to your project along with future tips. On Request we will Mail you Matlab Codes for Registered Members of this site only, at free service...Follow Me.

Circle matlab code


   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. 
First let me first discuss how to draw a circle and then we will see 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;
rad=100;
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);

r=rad.^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
    radius=(rad-10*i).^2;
    r=find(((x-xc).^2+(y-yc).^2)<=radius);
   
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


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

0 comments:

Post a Comment

Recent Comments

Popular Matlab Topics

Share your knowledge - help others

Crazy over Matlab Projects ? - Join Now - Follow Me

Sites U Missed to Visit ?

Related Posts Plugin for WordPress, Blogger...

Latest Articles

Special Search For Matlab Projects

MATLAB PROJECTS

counter

Bharadwaj. Powered by Blogger.