Search in sources :

Example 6 with PixelTransformAffine_F32

use of boofcv.alg.distort.PixelTransformAffine_F32 in project BoofCV by lessthanoptimal.

the class TestBinaryEllipseDetectorPixel method undistortContour_WithDistortion.

/**
 * Undistort the image when distortion model is provided
 */
@Test
public void undistortContour_WithDistortion() {
    List<Point2D_I32> input = new ArrayList<>();
    FastQueue<Point2D_F64> output = new FastQueue<>(Point2D_F64.class, true);
    for (int i = 0; i < 10; i++) {
        input.add(new Point2D_I32(i, i));
    }
    BinaryEllipseDetectorPixel alg = new BinaryEllipseDetectorPixel();
    alg.setLensDistortion(new PixelTransformAffine_F32(new Affine2D_F32(1, 0, 0, 1, 10.0f, 0)));
    alg.undistortContour(input, output);
    assertEquals(input.size(), output.size);
    for (int i = 0; i < input.size(); i++) {
        Point2D_I32 p = input.get(i);
        assertEquals(p.x + 10, output.get(i).x, 1e-8);
        assertEquals(p.y, output.get(i).y, 1e-8);
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) Affine2D_F32(georegression.struct.affine.Affine2D_F32) FastQueue(org.ddogleg.struct.FastQueue) ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) Test(org.junit.Test)

Example 7 with PixelTransformAffine_F32

use of boofcv.alg.distort.PixelTransformAffine_F32 in project BoofCV by lessthanoptimal.

the class TestDetectPolygonBinaryGrayRefine method checkDetected_LensDistortion.

private void checkDetected_LensDistortion(Class imageType, double tol) {
    renderDistortedRectangles(true, imageType);
    Affine2D_F32 a = new Affine2D_F32();
    UtilAffine.convert(transform, a);
    PixelTransform2_F32 tranFrom = new PixelTransformAffine_F32(a);
    PixelTransform2_F32 tranTo = new PixelTransformAffine_F32(a.invert(null));
    int numberOfSides = 4;
    DetectPolygonBinaryGrayRefine alg = createAlg(imageType, numberOfSides, numberOfSides);
    alg.setLensDistortion(image.width, image.height, tranTo, tranFrom);
    alg.process(image, binary);
    List<DetectPolygonFromContour.Info> found = alg.getPolygonInfo();
    assertEquals(rectangles.size(), found.size());
    for (int i = 0; i < found.size(); i++) {
        Polygon2D_F64 p = found.get(i).polygon;
        assertEquals(1, findMatchesOriginal(p, tol));
        assertEquals(black, found.get(i).edgeInside, 3);
        assertEquals(white, found.get(i).edgeOutside, white * 0.05);
    }
    // ----------- see if distortion is cleared properly
    alg.clearLensDistortion();
    alg.process(image, binary);
    found = alg.getPolygonInfo();
    assertEquals(rectangles.size(), found.size());
    // nothing should match now
    for (int i = 0; i < found.size(); i++) {
        Polygon2D_F64 p = found.get(i).polygon;
        assertEquals(0, findMatchesOriginal(p, tol));
    }
}
Also used : Affine2D_F32(georegression.struct.affine.Affine2D_F32) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32)

Example 8 with PixelTransformAffine_F32

use of boofcv.alg.distort.PixelTransformAffine_F32 in project BoofCV by lessthanoptimal.

the class TestFDistort method affine.

@Test
public void affine() {
    ImageMiscOps.fillUniform(input, rand, 0, 200);
    Affine2D_F32 affine = new Affine2D_F32(2, 0.1f, -0.2f, 1.1f, 3, 4.5f);
    PixelTransform2_F32 transform = new PixelTransformAffine_F32(affine.invert(null));
    new FDistort(input, output).affine(2, 0.1f, -0.2f, 1.1f, 3, 4.5f).borderExt().apply();
    InterpolatePixelS<GrayU8> interp = FactoryInterpolation.bilinearPixelS(input, null);
    interp.setBorder(FactoryImageBorderAlgs.extend(input));
    interp.setImage(input);
    if (input.getDataType().isInteger()) {
        for (int y = 0; y < output.height; y++) {
            for (int x = 0; x < output.width; x++) {
                transform.compute(x, y);
                float val = interp.get(transform.distX, transform.distY);
                assertEquals((int) val, output.get(x, y), 1e-4);
            }
        }
    } else {
        for (int y = 0; y < output.height; y++) {
            for (int x = 0; x < output.width; x++) {
                transform.compute(x, y);
                float val = interp.get(transform.distX, transform.distY);
                assertEquals(val, output.get(x, y), 1e-4);
            }
        }
    }
}
Also used : Affine2D_F32(georegression.struct.affine.Affine2D_F32) GrayU8(boofcv.struct.image.GrayU8) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32) Test(org.junit.Test)

Example 9 with PixelTransformAffine_F32

use of boofcv.alg.distort.PixelTransformAffine_F32 in project BoofCV by lessthanoptimal.

the class PyramidFloatGaussianScale method process.

@Override
public void process(T input) {
    super.initialize(input.width, input.height);
    if (isSaveOriginalReference())
        throw new IllegalArgumentException("The original reference cannot be saved");
    if (tempImage == null) {
        tempImage = (T) input.createNew(input.width, input.height);
    }
    for (int i = 0; i < scale.length; i++) {
        T prev = i == 0 ? input : getLayer(i - 1);
        T layer = getLayer(i);
        // Apply the requested blur to the previous layer
        BlurStorageFilter<T> blur = (BlurStorageFilter<T>) FactoryBlurFilter.gaussian(layer.getImageType(), sigmaLayers[i], -1);
        tempImage.reshape(prev.width, prev.height);
        blur.process(prev, tempImage);
        // Resample the blurred image
        if (scale[i] == 1) {
            layer.setTo(tempImage);
        } else {
            PixelTransformAffine_F32 model = DistortSupport.transformScale(layer, tempImage, null);
            DistortImageOps.distortSingle(tempImage, layer, true, model, interpolate);
        }
    }
}
Also used : PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) BlurStorageFilter(boofcv.abst.filter.blur.BlurStorageFilter)

Example 10 with PixelTransformAffine_F32

use of boofcv.alg.distort.PixelTransformAffine_F32 in project BoofCV by lessthanoptimal.

the class PyramidFloatScale method process.

@Override
public void process(T input) {
    super.initialize(input.width, input.height);
    if (isSaveOriginalReference())
        throw new IllegalArgumentException("The original reference cannot be saved");
    for (int i = 0; i < scale.length; i++) {
        T prev = i == 0 ? input : getLayer(i - 1);
        T layer = getLayer(i);
        PixelTransformAffine_F32 model = DistortSupport.transformScale(layer, prev, null);
        DistortImageOps.distortSingle(prev, layer, true, model, interpolate);
    }
}
Also used : PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32)

Aggregations

PixelTransformAffine_F32 (boofcv.alg.distort.PixelTransformAffine_F32)16 Affine2D_F32 (georegression.struct.affine.Affine2D_F32)13 PixelTransform2_F32 (boofcv.struct.distort.PixelTransform2_F32)6 Test (org.junit.Test)5 GrayU8 (boofcv.struct.image.GrayU8)3 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)3 Affine2D_F64 (georegression.struct.affine.Affine2D_F64)2 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)2 ArrayList (java.util.ArrayList)2 BlurStorageFilter (boofcv.abst.filter.blur.BlurStorageFilter)1 PixelTransformHomography_F32 (boofcv.alg.distort.PixelTransformHomography_F32)1 InterpolatePixelS (boofcv.alg.interpolate.InterpolatePixelS)1 GrayF32 (boofcv.struct.image.GrayF32)1 EllipseRotated_F64 (georegression.struct.curve.EllipseRotated_F64)1 Homography2D_F32 (georegression.struct.homography.Homography2D_F32)1 Point2D_F64 (georegression.struct.point.Point2D_F64)1 Point2D_I32 (georegression.struct.point.Point2D_I32)1 Se2_F32 (georegression.struct.se.Se2_F32)1 InvertibleTransformSequence (georegression.transform.InvertibleTransformSequence)1 FastQueue (org.ddogleg.struct.FastQueue)1