Search in sources :

Example 11 with DogArray_F64

use of org.ddogleg.struct.DogArray_F64 in project BoofCV by lessthanoptimal.

the class ImplConvolveMean method vertical.

public static void vertical(GrayF64 input, GrayF64 output, int offset, int length, @Nullable GrowArray<DogArray_F64> workspaces) {
    workspaces = BoofMiscOps.checkDeclare(workspaces, DogArray_F64::new);
    // CONCURRENT_REMOVE_LINE
    final DogArray_F64 work = workspaces.grow();
    final int backStep = length * input.stride;
    final int offsetEnd = length - offset - 1;
    final double divisor = length;
    // To reduce cache misses it is processed along rows instead of going down columns, which is
    // more natural for a vertical convolution. For parallel processes this requires building
    // a book keeping array for each thread.
    // CONCURRENT_BELOW BoofConcurrency.loopBlocks(offset, output.height - offsetEnd, length, workspaces, (work, y0,y1)->{
    final int y0 = offset, y1 = output.height - offsetEnd;
    double[] totals = BoofMiscOps.checkDeclare(work, input.width, false);
    for (int x = 0; x < input.width; x++) {
        int indexIn = input.startIndex + (y0 - offset) * input.stride + x;
        int indexOut = output.startIndex + output.stride * y0 + x;
        double total = 0;
        int indexEnd = indexIn + input.stride * length;
        for (; indexIn < indexEnd; indexIn += input.stride) {
            total += input.data[indexIn];
        }
        totals[x] = total;
        output.data[indexOut] = (total / divisor);
    }
    // change the order it is processed in to reduce cache misses
    for (int y = y0 + 1; y < y1; y++) {
        int indexIn = input.startIndex + (y + offsetEnd) * input.stride;
        int indexOut = output.startIndex + y * output.stride;
        for (int x = 0; x < input.width; x++, indexIn++, indexOut++) {
            double total = totals[x] - (input.data[indexIn - backStep]);
            totals[x] = total += input.data[indexIn];
            output.data[indexOut] = (total / divisor);
        }
    }
// CONCURRENT_INLINE });
}
Also used : DogArray_F64(org.ddogleg.struct.DogArray_F64)

Example 12 with DogArray_F64

use of org.ddogleg.struct.DogArray_F64 in project BoofCV by lessthanoptimal.

the class ShapeFittingOps method averageCircle_F64.

/**
 * Computes a circle which has it's center at the mean position of the provided points and radius is equal to the
 * average distance of each point from the center. While fast to compute the provided circle is not a best
 * fit circle by any reasonable metric, except for special cases.
 *
 * @param points (Input) Set of unordered points. Not modified.
 * @param optional (Optional) Used internally to store the distance of each point from the center. Can be null.
 * @param outputStorage (Output/Optional) Storage for results. If null then a new circle instance will be returned.
 * @return The found circle fit.
 */
public static FitData<Circle2D_F64> averageCircle_F64(List<Point2D_F64> points, @Nullable DogArray_F64 optional, @Nullable FitData<Circle2D_F64> outputStorage) {
    if (outputStorage == null) {
        outputStorage = new FitData<>(new Circle2D_F64());
    }
    if (optional == null) {
        optional = new DogArray_F64();
    }
    Circle2D_F64 circle = outputStorage.shape;
    int N = points.size();
    // find center of the circle by computing the mean x and y
    double sumX = 0, sumY = 0;
    for (int i = 0; i < N; i++) {
        Point2D_F64 p = points.get(i);
        sumX += p.x;
        sumY += p.y;
    }
    optional.reset();
    double centerX = circle.center.x = sumX / (double) N;
    double centerY = circle.center.y = sumY / (double) N;
    double meanR = 0;
    for (int i = 0; i < N; i++) {
        Point2D_F64 p = points.get(i);
        double dx = p.x - centerX;
        double dy = p.y - centerY;
        double r = Math.sqrt(dx * dx + dy * dy);
        optional.push(r);
        meanR += r;
    }
    meanR /= N;
    circle.radius = meanR;
    // compute radius variance
    double variance = 0;
    for (int i = 0; i < N; i++) {
        double diff = optional.get(i) - meanR;
        variance += diff * diff;
    }
    outputStorage.error = variance / N;
    return outputStorage;
}
Also used : Circle2D_F64(georegression.struct.trig.Circle2D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) DogArray_F64(org.ddogleg.struct.DogArray_F64)

Example 13 with DogArray_F64

use of org.ddogleg.struct.DogArray_F64 in project BoofCV by lessthanoptimal.

the class WrapAssociateGreedy2D method associate.

@Override
public void associate() {
    unassocSrc.reset();
    alg.associate();
    DogArray_I32 pairs = alg.getPairs();
    DogArray_F64 score = alg.getFitQuality();
    matches.reset();
    for (int i = 0; i < pairs.size; i++) {
        int dst = pairs.data[i];
        if (dst >= 0)
            matches.grow().setTo(i, dst, score.data[i]);
        else
            unassocSrc.add(i);
    }
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32) DogArray_F64(org.ddogleg.struct.DogArray_F64)

Example 14 with DogArray_F64

use of org.ddogleg.struct.DogArray_F64 in project BoofCV by lessthanoptimal.

the class TestCompleteSift method basic.

/**
 * Doesn't do much more than see if it blows up and the expected size of objects is returned
 */
@Test
void basic() {
    GrayF32 image = new GrayF32(300, 290);
    GImageMiscOps.fillUniform(image, rand, 0, 200);
    CompleteSift alg = createAlg();
    alg.process(image);
    assertEquals(128, alg.getDescriptorLength());
    DogArray_F64 orientations = alg.getOrientations();
    FastAccess<ScalePoint> locations = alg.getLocations();
    FastAccess<TupleDesc_F64> descriptions = alg.getDescriptions();
    assertTrue(orientations.size > 10);
    assertEquals(orientations.size, locations.size);
    assertEquals(orientations.size, descriptions.size);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) ScalePoint(boofcv.struct.feature.ScalePoint) DogArray_F64(org.ddogleg.struct.DogArray_F64) Test(org.junit.jupiter.api.Test)

Example 15 with DogArray_F64

use of org.ddogleg.struct.DogArray_F64 in project BoofCV by lessthanoptimal.

the class CompleteSift method describeDetections.

/**
 * Computes one or more descriptors for every point in the passed in list
 */
protected void describeDetections(List<SiftPoint> detections) {
    for (int detIdx = 0; detIdx < detections.size(); detIdx++) {
        SiftPoint p = detections.get(detIdx);
        // Would it be faster if all features that come from the same images were processed at once?
        // Would it reduce context switching?
        // Gradient image is offset by one
        GrayF32 derivX = gradient.getDerivX(p.octaveIdx, (byte) (p.scaleIdx - 1));
        GrayF32 derivY = gradient.getDerivY(p.octaveIdx, (byte) (p.scaleIdx - 1));
        orientation.setImageGradient(derivX, derivY);
        describe.setImageGradient(derivX, derivY);
        double pixelScaleToInput = scaleSpace.pixelScaleCurrentToInput(p.octaveIdx);
        // adjust the image for the down sampling in each octave
        double localX = p.pixel.x / pixelScaleToInput;
        double localY = p.pixel.y / pixelScaleToInput;
        double localSigma = p.scale / pixelScaleToInput;
        // find potential orientations first
        orientation.process(localX, localY, localSigma);
        // describe each feature
        DogArray_F64 angles = orientation.getOrientations();
        for (int angleIdx = 0; angleIdx < angles.size; angleIdx++) {
            describe.process(localX, localY, localSigma, angles.get(angleIdx), features.grow());
            orientations.add(angles.get(angleIdx));
            locations.add(p);
        }
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) SiftPoint(boofcv.alg.feature.detect.interest.SiftDetector.SiftPoint) SiftPoint(boofcv.alg.feature.detect.interest.SiftDetector.SiftPoint) ScalePoint(boofcv.struct.feature.ScalePoint) DogArray_F64(org.ddogleg.struct.DogArray_F64)

Aggregations

DogArray_F64 (org.ddogleg.struct.DogArray_F64)16 Test (org.junit.jupiter.api.Test)5 Circle2D_F64 (georegression.struct.trig.Circle2D_F64)4 DogArray_I32 (org.ddogleg.struct.DogArray_I32)4 ScalePoint (boofcv.struct.feature.ScalePoint)3 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)3 GrayF32 (boofcv.struct.image.GrayF32)3 ArrayList (java.util.ArrayList)3 Point2D_F64 (georegression.struct.point.Point2D_F64)2 Point2D_I32 (georegression.struct.point.Point2D_I32)2 SiftDetector (boofcv.alg.feature.detect.interest.SiftDetector)1 SiftPoint (boofcv.alg.feature.detect.interest.SiftDetector.SiftPoint)1 ConfigFiducialImage (boofcv.factory.fiducial.ConfigFiducialImage)1 ConfigThreshold (boofcv.factory.filter.binary.ConfigThreshold)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 GrayU8 (boofcv.struct.image.GrayU8)1 Point3D_F64 (georegression.struct.point.Point3D_F64)1 BufferedImage (java.awt.image.BufferedImage)1