This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Hough transform troubleshooting

Hi,
I'm trying to implement Hough transform on DM642EVM. I'm using gradient information found earlier during edge detection.

However, when run the program, I always get the the value of maxvalu to be 1. So it will always inform me that the there is a line, even when there
isn't any. Help please.
Thanks,
Hanief

void simpleHT(
  unsigned char * edgeMap,    //input data from edge detection
  //unsigned char * restrict l_data,
  double * directionalMap,      //edge direction data from edge detection
  double * abspace,                //accumulator
  int i_cols,                                //columns = image width
  int i_rows                                //rows = image height
  ) {
  int scanRows = 0; int scanCols = 0; //int scanMaxVal = 0;
  int maxvalu = 0;
  int size = i_cols * i_rows;
  int rho, rhoNorm;
  int theta, tanTheta, denom;
  int TAN_TOO_BIG = 263; // tan(89.7821)
  int x1, y1;
  int xMax, yMax;
  memset(abspace, 0, size * sizeof(double));

/* perform Hough transform */
rhoNorm = (i_cols-1) / 865.33231;             //width=i_cols=720

for (scanRows = 0; scanRows < i_rows; scanRows++) {     //scanRows=y
  for (scanCols = 0; scanCols < i_cols; scanCols++) {           //scanCols=x
    if (edgeMap[scanCols + scanRows * i_cols] == 255) {      //if pixel (x, y) is an edge
      theta = (directionalMap[scanCols + scanRows * i_cols]);  //find theta
      tanTheta = tan (theta);
      if (tanTheta > TAN_TOO_BIG) {              //find rho
        // rho = x * cos(theta) + y * sin(theta)
        rho = scanRows; // y * sin (90)
      }
      else {
        denom = tanTheta * tanTheta + 1.0;
        y1 = (scanRows - scanCols * tanTheta) / denom;
        x1 = (scanCols * tanTheta * tanTheta - scanRows * tanTheta) / denom;
        rho = sqrt (x1 * x1 + y1 * y1);
      }
      if (abspace[scanCols + scanRows * i_cols] < 255)          //increment accumulator
  abspace[scanCols + scanRows * i_cols] +=1 ;
  }
  }
}

/* determine peak in Hough space and (theta, rho) coords */
for (scanRows = 0; scanRows < i_rows; scanRows++) {
  for (scanCols = 0; scanCols < i_cols; scanCols++) {
    if (abspace[scanCols + scanRows * i_cols] > maxvalu) {
      maxvalu = abspace[scanCols + scanRows * i_cols];           //find highest value in accumulator
      xMax = scanCols;
      yMax = scanRows;
    }
  }
}

/* inform user of result */
if (maxvalu > 0) {
  rho = xMax / rhoNorm;
  theta = yMax * PI / i_rows;
  puts ("Line located with parameters:\n");
  //printf ("\tpolar coords: (%5.2f, %5.2f) (rho [pixels], theta [radians])\n", rho, theta);
  //printf ("\tpolar coords: (%d,%d)\n", rho, theta);
  //printf ("Peak located at: (%d,%d)\n", xMax, yMax);

  //l_data[xMax + yMax * i_cols] = 255;     //this variable not used
}
else
  puts ("No line found.\n");

}