-
Notifications
You must be signed in to change notification settings - Fork 0
/
findcentre.m
executable file
·46 lines (37 loc) · 1.26 KB
/
findcentre.m
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
function findcentre()
% findcentre finds the centre location of a circular image
global image_matrix
msgbox('Select approximate centre','Find Centre');
waitforbuttonpress;
[xapp, yapp] = ginput(1);
msgbox('Select maximum extent of useful image', 'Find Centre');
waitforbuttonpress;
[xmax, ymax] = ginput(1);
% Draw a series of lines radially outward from this point and calculate the
% profile along each line
nlines = 50;
delangle = 2*pi/nlines;
%rmax = size(image_matrix,2) - xapp;
rmax = sqrt((size(image_matrix,1) - yapp).^2 + (size(image_matrix,2) - xapp).^2);
xvec = zeros(0);
yvec = zeros(0);
for i=0:nlines-1
angle = i * delangle;
xi = xapp + rmax * cos(angle);
yi = yapp + rmax * sin(angle);
%Calculate profile
xprofile = [xapp xi];
yprofile = [yapp yi];
[cx, cy, prof] = improfile(image_matrix,xprofile,yprofile);
%Find co-ordinates of maximum
[profmax, indexmax] = min(prof);
xvec = [xvec; cx(indexmax)];
yvec = [yvec; cy(indexmax)];
text(cx(indexmax),cy(indexmax),'+','HorizontalAlignment','center');
end
% Fit to a circle
[xc,yc,R] = circfit(xvec,yvec);
% Plot the circle (overlaid)
hold on
text(xc,yc,'+','HorizontalAlignment','center');
circle([xc yc], R, 100);