next up previous
Next: Appendix B Up: No Title Previous: References

Appendix A

Matlab code used for the Hough Transform of collinear points.

% Hough Transform MatLab code.
% Version 1.0: Looks for feature points in an image and plots
% the correspoding (r,theta) curve for each point.

% Written by Vicky Safouris and Steven Manos.
% Date last updated: Wednesday 24/5/2000.
% filename: /home/smanos/hought/htpoints.m

% Set up of input image array with 3 points with (x,y)
% coordinates of (20,70), (50,50) and (80,30).

im=zeros(100,100);
im(20,70)=1;
im(50,50)=1;
im(80,30)=1;

colormap(gray)

% Plot input image array.

subplot(211), image(im*80)
axis equal
axis([1 100 1 100])
axis xy
xlabel('x')
ylabel('y')
title('Input image')

% Set up of the accumulator array A(r,theta). r is the longest 
% line possible in the 100 by 100 pixel image, which is given 
% by floor(sqrt(100^2+100^2)) = 141. 360 gives the range of 
% theta we want to examine, being 1 to 360.

A=zeros(141,360);

% Here all the values of x and y are searched through to find
% any feature points. For each (x,y) feature point all the
% corresponding (r,theta) points are found. r negative is not
% 'voted for' in the accumulator cell.

for x=1:1:100;
 for y=1:1:100;
  if im(y,x)>=1;
   for theta=1:1:360;
    r=round(x*cos(theta*pi/180) + y*sin(theta*pi/180));
        if r<1
     r=1;
         A(r,theta)=A(r,theta);
        else
         A(r,theta)=A(r,theta)+1;
     end;
     end;
  end;
 end;
end;

% Plot accumulator array.

subplot(212), image(A*50)
axis equal
axis([1 360 1 141])
axis xy
ylabel('r')
xlabel('theta');
title('Accumulator array')



vicky safouris
2000-06-02