Image Processing Reference
In-Depth Information
%Hough Transform for Lines
function HTLine(inputimage)
%image size
[rows,columns]=size(inputimage);
%accumulator
acc1=zeros(rows,91);
acc2=zeros(columns,91);
%image
for x=1:columns
for y=1:rows
if(inputimage(y,x)==0
for m=-45:45
b=round(y-tan((m*pi)/180)*x);
if(b<rows & b>0)
acc1(b,m+45+1)=acc1(b,m+45+1)+1;
end
end
for m=45:135
b=round(x-y/tan((m*pi)/180));
if(b<columns & b>0)
acc2(b,m-45+1)=acc2(b,m-45+1)+1;
end
end
end
end
end
Code 5.3
Implementing the Hough transform for lines
The magnitude of the peak is proportional to the number of pixels in the line from which
it was generated. The edges of the wrench in Figures 5.7 (b) and 5.7 (c) define two main
lines. Image 5.7 (c) contains much more noise. This image was obtained by using a lower
threshold value in the edge detector operator which gave rise to more noise. The accumulator
results of the HT for the images in Figures 5.7 (b) and 5.7 (c) are shown in Figures 5.7 (e)
and 5.7 (f), respectively. We can observe the two accumulator arrays are broadly similar in
shape, and that the peak in each is at the same place. The co-ordinates of the peaks are at
combinations of parameters of the lines that best fit the image. The extra number of edge
points in the noisy image of the wrench gives rise to more votes in the accumulator space,
as can be seen by the increased number of votes in Figure 5.7 (f) compared with Figure
5.7 (e). Since the peak is in the same place, this shows that the HT can indeed tolerate noise.
The results of extraction, when superimposed on the edge image, are shown in Figures
5.7 (g) to (i). Only the two lines corresponding to significant peaks have been drawn for the
image of the wrench. Here, we can see that the parameters describing the lines have been
extracted well. Note that the end points of the lines are not delivered by the HT, only the
parameters that describe them. You have to go back to the image to obtain line length.
Search WWH ::




Custom Search