Search in sources :

Example 11 with Affine2D_F32

use of georegression.struct.affine.Affine2D_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 12 with Affine2D_F32

use of georegression.struct.affine.Affine2D_F32 in project BoofCV by lessthanoptimal.

the class BenchmarkPixelTransform method main.

public static void main(String[] args) {
    Random rand = new Random(234);
    Affine2D_F32 affine = new Affine2D_F32((float) rand.nextGaussian(), (float) rand.nextGaussian(), (float) rand.nextGaussian(), (float) rand.nextGaussian(), (float) rand.nextGaussian(), (float) rand.nextGaussian());
    Homography2D_F32 homography = new Homography2D_F32((float) rand.nextGaussian(), (float) rand.nextGaussian(), (float) rand.nextGaussian(), (float) rand.nextGaussian(), (float) rand.nextGaussian(), (float) rand.nextGaussian(), (float) rand.nextGaussian(), (float) rand.nextGaussian(), (float) rand.nextGaussian());
    System.out.println("=========  Profile Image Size " + imgWidth + " x " + imgHeight + " ==========");
    System.out.println();
    benchmark(new PixelTransformHomography_F32(homography), "Homography");
    benchmark(new PixelTransformAffine_F32(affine), "Affine");
}
Also used : Random(java.util.Random) Affine2D_F32(georegression.struct.affine.Affine2D_F32) Homography2D_F32(georegression.struct.homography.Homography2D_F32)

Example 13 with Affine2D_F32

use of georegression.struct.affine.Affine2D_F32 in project BoofCV by lessthanoptimal.

the class TestImplPolynomialPixel_F32 method compareToBilinear.

/**
 * Polynomial interpolation of order one is bilinear interpolation
 */
@Test
public void compareToBilinear() {
    GrayF32 img = new GrayF32(width, height);
    GrayF32 expected = new GrayF32(width, height);
    GrayF32 found = new GrayF32(width, height);
    GImageMiscOps.fillUniform(img, rand, 0, 255);
    Affine2D_F32 tran = new Affine2D_F32(1, 0, 0, 1, 0.25f, 0.25f);
    // set it up so that it will be equivalent to bilinear interpolation
    ImplPolynomialPixel_F32 alg = new ImplPolynomialPixel_F32(2, 0, 255);
    alg.setBorder(FactoryImageBorder.singleValue(GrayF32.class, 0));
    ImageDistort<GrayF32, GrayF32> distorter = FactoryDistort.distortSB(false, alg, GrayF32.class);
    distorter.setModel(new PixelTransformAffine_F32(tran));
    distorter.apply(img, found);
    InterpolatePixelS<GrayF32> bilinear = FactoryInterpolation.bilinearPixelS(GrayF32.class, null);
    bilinear.setBorder(FactoryImageBorder.singleValue(GrayF32.class, 0));
    distorter = FactoryDistort.distortSB(false, bilinear, GrayF32.class);
    distorter.setModel(new PixelTransformAffine_F32(tran));
    distorter.apply(img, expected);
    BoofTesting.assertEquals(expected, found, 1e-4f);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Affine2D_F32(georegression.struct.affine.Affine2D_F32) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) Test(org.junit.Test)

Example 14 with Affine2D_F32

use of georegression.struct.affine.Affine2D_F32 in project BoofCV by lessthanoptimal.

the class TestDetectPolygonFromContour 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;
    DetectPolygonFromContour alg = createDetector(imageType, numberOfSides, numberOfSides);
    alg.setLensDistortion(image.width, image.height, tranTo, tranFrom);
    alg.process(image, binary);
    FastQueue<DetectPolygonFromContour.Info> found = alg.getFound();
    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);
    }
}
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 15 with Affine2D_F32

use of georegression.struct.affine.Affine2D_F32 in project BoofCV by lessthanoptimal.

the class DistortSupport method transformScale.

/**
 * Computes a transform which is used to rescale an image.  The scale is computed
 * directly from the size of the two input images and independently scales
 * the x and y axises.
 */
public static PixelTransformAffine_F32 transformScale(ImageBase from, ImageBase to, PixelTransformAffine_F32 distort) {
    if (distort == null)
        distort = new PixelTransformAffine_F32();
    float scaleX = (float) (to.width) / (float) (from.width);
    float scaleY = (float) (to.height) / (float) (from.height);
    Affine2D_F32 affine = distort.getModel();
    affine.set(scaleX, 0, 0, scaleY, 0, 0);
    return distort;
}
Also used : Affine2D_F32(georegression.struct.affine.Affine2D_F32) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32)

Aggregations

Affine2D_F32 (georegression.struct.affine.Affine2D_F32)21 PixelTransformAffine_F32 (boofcv.alg.distort.PixelTransformAffine_F32)13 Test (org.junit.Test)11 PixelTransform2_F32 (boofcv.struct.distort.PixelTransform2_F32)6 GrayU8 (boofcv.struct.image.GrayU8)3 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)3 Affine2D_F64 (georegression.struct.affine.Affine2D_F64)2 Homography2D_F32 (georegression.struct.homography.Homography2D_F32)2 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)2 RectangleLength2D_F32 (georegression.struct.shapes.RectangleLength2D_F32)2 RectangleLength2D_I32 (georegression.struct.shapes.RectangleLength2D_I32)2 ArrayList (java.util.ArrayList)2 PixelTransformHomography_F32 (boofcv.alg.distort.PixelTransformHomography_F32)1 InterpolatePixelS (boofcv.alg.interpolate.InterpolatePixelS)1 GrayF32 (boofcv.struct.image.GrayF32)1 ImageGray (boofcv.struct.image.ImageGray)1 Planar (boofcv.struct.image.Planar)1 EllipseRotated_F64 (georegression.struct.curve.EllipseRotated_F64)1 Point2D_F32 (georegression.struct.point.Point2D_F32)1 Point2D_F64 (georegression.struct.point.Point2D_F64)1