MantisBT - ITK
View Issue Details
0010250ITKpublic2010-02-08 08:392010-11-07 09:02
Alberto Gomez 
Luis Ibanez 
normalminorhave not tried
assignedopen 
Ubuntu9.10
ITK-3-16 
 
0010250: The Hough Transform filter computes the hough Transform in pixel coordinates and not in world coordinates
The class itk::HoughTransform2DLinesImageFilter computes the hough transform of an image for line detection. The output is the Hough Map, which is a 2D image where the x axis represents the angle of the line wrt the horizontal, and the y-axis the distance of the closest point from the line to the origin. To be coherent with all itk Filters, this distance should be given in world coordinates, but it is given in pixel coordinates. Then, one should compute the line parameters in pixel coordinate and convert the result to world coordinates. This should be chganged to directly do all computations in world coordinates
 //Make a binary image (not necessary)
 ThresholdFilter::Pointer thFilter = ThresholdFilter::New();
    thFilter->SetInput(image_in);
    thFilter->SetLowerThreshold(1);
    thFilter->SetUpperThreshold(255);
    thFilter->SetInsideValue(255);
    thFilter->SetOutsideValue(0);
// Contour detection
    GradientFilter::Pointer gradientFilter = GradientFilter::New();
    gradientFilter->SetInput(thFilter->GetOutput());
//compute Hough Transform to get 2 lines
    HoughFilter::Pointer houghFilter = HoughFilter::New();
    houghFilter->SetInput(gradientFilter->GetOutput());
    houghFilter->SetThreshold(1);
    houghFilter->SetNumberOfLines(2);
    houghFilter->Update();
    HoughFilter::LinesListType lines = houghFilter->GetLines();

// Get the lines' parameters
    vnl_matrix<double> M(2, 2);//Matrix containing the lines' vectors (in world coordinates)
    vnl_matrix<double> P(2, 2);//matrix containing the lines' points (in world coordinates)

typedef HoughFilter::LinesListType::const_iterator LineIterator;
    LineIterator itLines = lines.begin();


    itk::ContinuousIndex<double,2> localIndexTmp;
    itk::Point<double,2> pointTmp;
    // NOTE: the y component has to be inversed in physical coordinates for consistency in itk-vtk
    int i = 0;

    while (itLines != lines.end()) {

        typedef HoughFilter::LineType::PointListType PointListType;
        PointListType pointsList = (*itLines)->GetPoints();
        PointListType::const_iterator itPoints = pointsList.begin();
        double u[2];
        u[0] = (*itPoints).GetPosition()[0];
        u[1] = (*itPoints).GetPosition()[1];


        localIndexTmp[0]= u[0];localIndexTmp[1]= u[1];

    // STEP THAT SHOULD NOT BE NECESSARY image_in->TransformContinuousIndexToPhysicalPoint(localIndexTmp,pointTmp);
       // END OF STEP THAT SHOULD NOT BE NECESSARY
        //std::cout << "\tu_world " << pointTmp<<std::endl;
        P[0][ i ] = pointTmp[0];
        P[1][ i ] = -pointTmp[1];

        itPoints++;
        double u2[2];
        u2[0] = (*itPoints).GetPosition()[0];
        u2[1] = (*itPoints).GetPosition()[1];
        double v[2];
        //std::cout << "\tu2 " << u2[0]<<","<<u2[1]<<std::endl;
        v[0] = u[0] - u2[0];
        v[1] = u[1] - u2[1];


        localIndexTmp[0]= u2[0];localIndexTmp[1]= u2[1];


// STEP THAT SHOULD NOT BE NECESSARY
image_in->TransformContinuousIndexToPhysicalPoint(localIndexTmp,pointTmp);
// END OF STEP THAT SHOULD NOT BE NECESSARY
        double vWorld[2];
        vWorld[0] = P[0][ i ] -pointTmp[0];
        vWorld[1] =P[1][ i ]+pointTmp[1];

        double norm = sqrt(v[0] * v[0] + v[1] * v[1]);
        v[0] /= norm;
        v[1] /= norm;

        double normWorld = sqrt(vWorld[0] * vWorld[0] + vWorld[1] * vWorld[1]);

        vWorld[0] /= normWorld;
        vWorld[1] /= normWorld;
        M[0][i] = vWorld[0];
        M[1][i] = vWorld[1];
}
No tags attached.
Issue History
2010-02-08 08:39Alberto GomezNew Issue
2010-11-07 09:02Hans JohnsonStatusnew => assigned
2010-11-07 09:02Hans JohnsonAssigned To => Luis Ibanez

There are no notes attached to this issue.