Understanding battery hough transform
I don't know if I am getting things right or something else. This is what the transformation of the charts looks like:
You just
loop through each pixel and calculate rho and theta with this formula: r = x.cos (ΞΈ) + y.sin (ΞΈ)
Most people put this formula in a loop of 0-> 180 or 0-360.
What for?
after that you put all values ββinto accumulator.
But for some dark and mysterious reason, all points on the same line will give the same values ββfor theta and r. How is this possible? I really do not understand.
I tried it, these were my results: I just put a straight black horizontal line on the image. The line was 10px long by 1px high. So I applied the formula, but instead of getting 1 place in my accumulator with a value of 10. I got 5 places with a value of 10, why?
this is my code if needed:
int outputImage[400][400];
int accumulator[5000][5000]; //random size
int i,j;
int r,t;
int x1,y1,x2,y2;
/* PUT ALL VALUES IN ACCU */
for(i=0;i<imageSize[0];i++)
{
for( j=0;j<imageSize[1];j++)
{
if (inputImage[i][j] == 0x00) //just to test everything, formula only applied on the black line
{
for( t=0;t<180;t++)
{
r = i * cos(t) + j*sin(t);
accumulator[r][t] ++;
}
}
}
}
/*READ ACCU, and draw lines */
for (i=0; i<5000;i++)
{
for (j=0;j<5000;j++)
{
if(accumulator[i][j] >= 10) // If accu value >= tresholdvalue, I believe we have a line
{
x1 = accumulator[i][j] * i / (cos(accumulator[i][j] * j));
y1 = 0;
x2 = 0;
y2 = accumulator[i][j] * i / (sin(accumulator[i][j] * j));
// now i just need to draw all the lines between x1y1 and x2y2
}
}
}
Thank!
source to share
No one has answered this question yet
Check out similar questions: