Hough transform: Difference between revisions
Content deleted Content added
→{{header|Tcl}}: oops |
→{{header|MATLAB}}: Changed the code, made it more efficient. |
||
Line 142:
<lang MATLAB>function [rho,theta,houghSpace] = houghTransform(theImage,thetaSampleFrequency)
%Define the hough space
[width,height] = size(theImage);
Line 150 ⟶ 151:
numThetas = numel(theta);
houghSpace = zeros(numel(rho),numThetas);
accumulator = zeros(numel(theImage),numThetas);▼
%Find the "edge" pixels
[xIndicies,yIndicies] = find(theImage);
%Preallocate space for the accumulator array
numEdgePixels = numel(xIndicies);
%Preallocate cosine and sine calculations to increase speed. In
Line 163 ⟶ 169:
sine = (0:height-1)'*sin(theta); %Matrix Outerproduct
%
▲ accumulator(index,:) = cosine(x,:) + sine(y,:);
▲ if index < numel(theImage)
for i = (1:numThetas)
houghSpace(:,i) = hist(accumulator(:,i),rho);
|