%%PART#1**************************************************************
%eng9999
Img = imread('04.bmp');
%imshow(Img);
GrayImg=rgb2gray(Img);
%imshow(GrayImg);
Edges=edge(GrayImg,'sobel');
imshow(Edges);
[m,n]=size(Edges);
%%PART#2******************************************************************
%eng9999
Count=0;
Count1=0;
for y = 1 : n
	for x = 1 : m
		Count1 = Count1+ 1;
		R(y,x)=Edges(Count1);
		if R(y,x) >0
			Count = Count+ 1;
			X(Count) = y;
			Y(Count) = x;
		end
	end
end
%%PART#3***********************************************************************
% AL AZHAR UNIVERSITY _ FACULTY OF ENGINEERING _ COMPUTER & SYSTEMS DEPARTMENT
% Ahmed Samieh      Asm4pic@yahoo.com
% Faster Way
x1=X(1);
y1=Y(1);
%x2=X(Count/3); % I Can't Remember How to Get The Integer Value of (Count/3)
x2 =X(11);      % if you Know How to get The integer Activeate the last line and delate this line
%y2=Y(Count/3);
y2=Y(11);
%x3=X(2* Count/3);
x3=X(Count - 11);
%y3=Y(2* Count/3)
y3=Y(Count - 11);
Slop1 = ( y2 - y1 ) / ( x2 - x1 );
Slop2 = ( y3 - y2 ) / ( x3 - x2 );
xc1 = ( x1 + x2 ) / 2 ;
xc2 = ( x2 + x3 ) / 2 ;
yc1 = ( y1 + y2 ) / 2 ;
yc2 = ( y2 + y3 ) / 2 ;
Center_X = ( 1 / (( 1 / Slop1 ) - ( 1 / Slop2 )) ) * ( ( xc1 / Slop1 ) + yc1 - ( xc2 / Slop2 ) - yc2 )
Center_Y = ( ( xc1 - Center_X ) / Slop1 ) + yc1
%******************************************************************************