Search in sources :

Example 11 with PixelTransformAffine_F32

use of boofcv.alg.distort.PixelTransformAffine_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 12 with PixelTransformAffine_F32

use of boofcv.alg.distort.PixelTransformAffine_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 13 with PixelTransformAffine_F32

use of boofcv.alg.distort.PixelTransformAffine_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)

Example 14 with PixelTransformAffine_F32

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

the class DistortSupport method transformRotate.

/**
 * Creates a {@link boofcv.alg.distort.PixelTransformAffine_F32} from the dst image into the src image.
 *
 * @param x0 Center of rotation in input image coordinates.
 * @param y0 Center of rotation in input image coordinates.
 * @param x1 Center of rotation in output image coordinates.
 * @param y1 Center of rotation in output image coordinates.
 * @param angle Angle of rotation.
 */
public static PixelTransformAffine_F32 transformRotate(float x0, float y0, float x1, float y1, float angle) {
    // make the coordinate system's origin the image center
    Se2_F32 imageToCenter = new Se2_F32(-x0, -y0, 0);
    Se2_F32 rotate = new Se2_F32(0, 0, angle);
    Se2_F32 centerToImage = new Se2_F32(x1, y1, 0);
    InvertibleTransformSequence sequence = new InvertibleTransformSequence();
    sequence.addTransform(true, imageToCenter);
    sequence.addTransform(true, rotate);
    sequence.addTransform(true, centerToImage);
    Se2_F32 total = new Se2_F32();
    sequence.computeTransform(total);
    Se2_F32 inv = total.invert(null);
    Affine2D_F32 affine = ConvertTransform_F32.convert(inv, (Affine2D_F32) null);
    PixelTransformAffine_F32 distort = new PixelTransformAffine_F32();
    distort.set(affine);
    return distort;
}
Also used : InvertibleTransformSequence(georegression.transform.InvertibleTransformSequence) Affine2D_F32(georegression.struct.affine.Affine2D_F32) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) Se2_F32(georegression.struct.se.Se2_F32)

Example 15 with PixelTransformAffine_F32

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

the class UtilImageMotion method createPixelTransform.

/**
 * Given a motion model create a PixelTransform used to distort the image
 *
 * @param transform Motion transform
 * @return PixelTransform_F32 used to distort the image
 */
public static PixelTransform2_F32 createPixelTransform(InvertibleTransform transform) {
    PixelTransform2_F32 pixelTran;
    if (transform instanceof Homography2D_F64) {
        Homography2D_F32 t = ConvertFloatType.convert((Homography2D_F64) transform, null);
        pixelTran = new PixelTransformHomography_F32(t);
    } else if (transform instanceof Homography2D_F32) {
        pixelTran = new PixelTransformHomography_F32((Homography2D_F32) transform);
    } else if (transform instanceof Affine2D_F64) {
        Affine2D_F32 t = UtilAffine.convert((Affine2D_F64) transform, null);
        pixelTran = new PixelTransformAffine_F32(t);
    } else if (transform instanceof Affine2D_F32) {
        pixelTran = new PixelTransformAffine_F32((Affine2D_F32) transform);
    } else {
        throw new RuntimeException("Unknown model type");
    }
    return pixelTran;
}
Also used : Affine2D_F64(georegression.struct.affine.Affine2D_F64) Affine2D_F32(georegression.struct.affine.Affine2D_F32) PixelTransformHomography_F32(boofcv.alg.distort.PixelTransformHomography_F32) Homography2D_F32(georegression.struct.homography.Homography2D_F32) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) Homography2D_F64(georegression.struct.homography.Homography2D_F64) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_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