📄 proj2_code.txt
字号:
I = imread('coins','bmp');
Ig = rgb2gray(I);
E = edge(Ig,'canny',0.7);
imshow(E);
title('Result of Edge Detection');
F = zeros(size(E)); % initialize all the entries in the accumulator cells
for i=1:size(E,1), % for every i and j do
for j=1:size(E,2),
if (E(i,j) == 1) % check if it is an edge point
for a=1:size(E,1),
side = (a-i) * (a-i);
if (side <= 100)
s = 100 - side; % obtain s by circle equation
s1=sqrt(s);
% find the corresponding b and increment the cell value by 1
b = round(j - s1);
if (b > 0)
F(a,b) = F(a,b)+1;
end
b = round(j + s1);
if (b <= size(E,2))
F(a,b) = F(a,b)+1;
end
end
end
end
end
end
figure,imshow(uint8(F*20));
title('Accumulator cell');
value=max(max(F)); % find the maximum value in the accumulator cell
for a=1:4
for i=1:size(E,1) % check for every cells
for j=1:size(E,2)
if(F(i,j)==value) % check if it is the maximum value
x= i;
y= j;
% mark centres with crosses
for c=i-5:i+5
for d=j-1:j+1
F(c, d) = 0;
end
end
for d=j-5:j+5
for c=i-1:i+1
F(c, d) = 0;
end
end
Centre=[x;y]
end
end
end
value=max(max(F)); % find the next maximum value in the accumulator cell
end
figure,imshow(uint8(F*20))
title('Detection of centres(marked with cross)')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -