-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEdge_Detection.asc
47 lines (37 loc) · 1.57 KB
/
Edge_Detection.asc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//Opens the image to be processed
Circle = imread('C:\Users\csrc-lab03\Desktop\yakal5.bmp');
Circle = rgb2gray(Circle)
//Use edge() function sobel
edge_sobel = edge(Circle,'canny');
imshow(edge_sobel);
imwrite(edge_sobel,'Circle_sobel.bmp');
//Edge pixel coordinates
[i_x,i_y] = find(edge_sobel);
//Locate centroid coordinates (in pixels) using average.
//sum([]) adds the elements in []. size([],2) gets the number of columns.
x_center = sum(i_x)/size(i_x,2);
y_center = sum(i_y)/size(i_y,2);
//Calculate position magnitude r and angle theta
x_loc = i_x - x_center;
y_loc = i_y - y_center;
r = sqrt((x_loc).^2+(y_loc).^2);
theta = atan((y_loc),(x_loc));
//Sort values according to increasing angle. gsort() function is used.
//theta_sorted is the sorted angle array, and is its corresponding index in the unsorted array
//'g' sorts all elements in 'i' increasing order
//Contains the values x and y pixels (transposed).
[theta_sorted, index] = gsort(theta','g','i');
xy_array = [x_loc;y_loc]'
//Sort x and y coordinates according to increasing angle.
xy_sorted = xy_array(index,:);
x_sorted = xy_sorted(:,1);
y_sorted = xy_sorted(:,2);
//Apply Green's finction in x_sorted and y_sorted. Obtain summations xdy and ydx for area computation.
xdy = sum(x_sorted(1:size(x_sorted,1)-1).*y_sorted(2:size(y_sorted,1)));
ydx = sum(y_sorted(1:size(y_sorted,1)-1).*x_sorted(2:size(x_sorted,1)));
Area_Comp = 0.5*(xdy - ydx);
//Compute Theoretical Area
Area_Theo = length(find(Circle==255));
//Compute % error
Error = 100*abs(Area_Comp - Area_Theo)/Area_Theo;
disp(Area_Comp); disp(Area_Theo); disp(Error);