Search code examples
c++image-processinghough-transform

About generalized hough transform code


I was looking for an implementation of Generalized Hough Transform,and then I found this website,which showed me a complete implementation of GHT .

I can totally understand how the algorithm processes except this:

Vec2i referenceP = Vec2i(id_max[0]*rangeXY+(rangeXY+1)/2, id_max[1]*rangeXY+(rangeXY+1)/2);  

which calculates the reference point of the object based on the maximum value of the hough space,then mutiplied by rangXY to get back to the corresponding position of origin image.(rangeXY is the dimensions in pixels of the squares in which the image is divided. )

I edited the code to

Vec2i referenceP = Vec2i(id_max[0]*rangeXY, id_max[1]*rangeXY); 

and I got another reference point then show all edgePoints in the image,which apparently not fit the shape.

I just cannot figure out what the factor(rangeXY+1)/2means.

Is there anyone who has implemented this code or familiared with the rationale of GHT can tell me what the factor rangeXYmeans? Thanks~


Solution

  • I am familiar with the classic Hough Transform, though not with the generalised one. However, I believe you give enough information in your question for me to answer it without being familiar with the algorithm in question.

    (rangeXY+1)/2 is simply integer division by 2 with rounding. For instance (4+1)/2 gives 2 while (5+1)/2 gives 3 (2.5 rounds up). Now, since rangeXY is the side of a square block of pixels and id_max is the position (index) of such a block, then id_max[dim]*rangeXY+(rangeXY+1)/2 gives the position of the central pixel in that block.

    On the other hand, when you simplified the expression to id_max[dim]*rangeXY, you were getting the position of the top-left rather than the central pixel.