Search in sources :

Example 1 with QuickSort_F32

use of org.ddogleg.sorting.QuickSort_F32 in project BoofCV by lessthanoptimal.

the class LineImageOps method pruneSimilarLines.

/**
 * Prunes similar looking lines, but keeps the lines with the most intensity.
 *
 * @param lines
 * @param intensity
 * @param toleranceAngle
 * @return
 */
public static List<LineParametric2D_F32> pruneSimilarLines(List<LineParametric2D_F32> lines, float[] intensity, float toleranceAngle, float toleranceDist, int imgWidth, int imgHeight) {
    int[] indexSort = new int[intensity.length];
    QuickSort_F32 sort = new QuickSort_F32();
    sort.sort(intensity, 0, lines.size(), indexSort);
    float[] theta = new float[lines.size()];
    List<LineSegment2D_F32> segments = new ArrayList<>(lines.size());
    for (int i = 0; i < lines.size(); i++) {
        LineParametric2D_F32 l = lines.get(i);
        theta[i] = UtilAngle.atanSafe(l.getSlopeY(), l.getSlopeX());
        segments.add(convert(l, imgWidth, imgHeight));
    }
    for (int i = segments.size() - 1; i >= 0; i--) {
        LineSegment2D_F32 a = segments.get(indexSort[i]);
        if (a == null)
            continue;
        for (int j = i - 1; j >= 0; j--) {
            LineSegment2D_F32 b = segments.get(indexSort[j]);
            if (b == null)
                continue;
            if (UtilAngle.distHalf(theta[indexSort[i]], theta[indexSort[j]]) > toleranceAngle)
                continue;
            Point2D_F32 p = Intersection2D_F32.intersection(a, b, null);
            if (p != null && p.x >= 0 && p.y >= 0 && p.x < imgWidth && p.y < imgHeight) {
                segments.set(indexSort[j], null);
            } else {
                float distA = Distance2D_F32.distance(a, b.a);
                float distB = Distance2D_F32.distance(a, b.b);
                if (distA <= toleranceDist || distB < toleranceDist) {
                    segments.set(indexSort[j], null);
                }
            }
        }
    }
    List<LineParametric2D_F32> ret = new ArrayList<>();
    for (int i = 0; i < segments.size(); i++) {
        if (segments.get(i) != null) {
            ret.add(lines.get(i));
        }
    }
    return ret;
}
Also used : QuickSort_F32(org.ddogleg.sorting.QuickSort_F32) LineSegment2D_F32(georegression.struct.line.LineSegment2D_F32) ArrayList(java.util.ArrayList) Point2D_F32(georegression.struct.point.Point2D_F32) ClosestPoint2D_F32(georegression.metric.ClosestPoint2D_F32) LineParametric2D_F32(georegression.struct.line.LineParametric2D_F32)

Example 2 with QuickSort_F32

use of org.ddogleg.sorting.QuickSort_F32 in project BoofCV by lessthanoptimal.

the class LineImageOps method pruneRelativeIntensity.

public static List<LineParametric2D_F32> pruneRelativeIntensity(List<LineParametric2D_F32> lines, float[] intensity, float fraction) {
    int[] indexSort = new int[intensity.length];
    QuickSort_F32 sort = new QuickSort_F32();
    sort.sort(intensity, 0, lines.size(), indexSort);
    float threshold = intensity[indexSort[lines.size() - 1]] * fraction;
    List<LineParametric2D_F32> ret = new ArrayList<>();
    for (int i = 0; i < lines.size(); i++) {
        if (intensity[i] >= threshold) {
            ret.add(lines.get(i));
        }
    }
    return ret;
}
Also used : QuickSort_F32(org.ddogleg.sorting.QuickSort_F32) ArrayList(java.util.ArrayList) LineParametric2D_F32(georegression.struct.line.LineParametric2D_F32)

Aggregations

LineParametric2D_F32 (georegression.struct.line.LineParametric2D_F32)2 ArrayList (java.util.ArrayList)2 QuickSort_F32 (org.ddogleg.sorting.QuickSort_F32)2 ClosestPoint2D_F32 (georegression.metric.ClosestPoint2D_F32)1 LineSegment2D_F32 (georegression.struct.line.LineSegment2D_F32)1 Point2D_F32 (georegression.struct.point.Point2D_F32)1