I am trying to understand exactly how it works. I believe I understand the concept:
For all edge pixels, find all lines that go through it, and for each of these lines up the accumulator array values (corresponding to the slope and y-intercept) by 1. The lines that cross through many edge points will have many votes in the accumulator array.
What I don't understand is in the code I have found for implementing it. First, I believe we can assume that, after an edge detector has been applied, edge pixels have a non-zero value while non-edges are 0. In the code from my textbook, the program searches for all points with ZERO VALUE and, for all lines passing through, increases the corresponding accumulator values by 1. I thought it would look for lines passing through the edge points (NON-ZERO), not empty space? Can someone explain to me this part?
The following is the Matlab code I have found in an image processing textbook. I haven't tested it as I am working with C++. The %messages are my understanding of what a particular line does:
function HTline(inputimage)
[rows,columns] = size(inputimage);
acc1 = zeros(rows,91);
acc2 = zeros(columns,91);
for x = 1:columns
for y = 1:rows
if(inputimage(x,y)==0 %If pixel=0, i.e., non-edge
for m = -45:45 %For a certain range of slope values
b = round(y-tan((m*pi)/180)*x); %Calculate y-intercept for slope values
if (b<rows & b>0) %If y-intercept is within the image height
acc1(b,m+45+1)=acc1(b,m+45+1)+1; %Increase accumulator values. What?
end
end
for m=45:135 %etc
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
William, it depends on how you define where an edge lies. Typically the image is converted to some binary mask and edge values are stores as trues (1s) and non-edge values are stored as false (0s) so your concerns seem correct. Maybe if you could add some context or some paraphrasing from your book then maybe they can provide justification for why they use false (0s) for edge values, but either representation does not provide an advantage over the other; it's simply convention.
Note that the way you're doing hough transform is an older technique. Most modern techniques use "foot of normal" parameterization (rho/theta) to account for situations where a line is vertical. Furthermore, some will use a sobel filter to directly calculate the gradient vector of edge points, which point in the direction normal to the line. This allows you to directly compute a single rho/theta value for edge points instead of calculating all possibilities of lines going through these points (as is done in your code).
But anyway, for your case, the slope and intercept are used to parameterize the lines. These values are binned and then placed in an accumulator as shown in your code. For a single edge point, there are an infinite number of lines which could pass through it, but these lines are made finite by using only binned values of the slope and intercept. In your case you use 91 possible values for the slope. Points which are collinear will result in certain "bins" accumulating more values than others. These local peaks in the accumulator indicate where lines (or more specifically edges if an edge detector is used) lie within the image. A good example of this is given in the wikipedia article for the hough transform. Hopefully this helps with your question.