Search in sources :

Example 1 with PixelTransform2_F32

use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.

the class DistortImageOps method rotate.

/**
 * <p>
 * Rotates the image using the specified interpolation type.  The rotation is performed
 * around the specified center of rotation in the input image.
 * </p>
 *
 * <p>
 * Input coordinates (x,y) to output coordinate (x',y')<br>
 * x' = x_c + c*(x-x_c) - s(y - y_c)<br>
 * y' = y_c + s*(x-x_c) + c(y - y_c)
 * </p>
 *
 * @deprecated As of v0.19.  Use {@link FDistort} instead
 *
 * @param input Which which is being rotated.
 * @param output The image in which the output is written to.
 * @param borderType Describes how pixels outside the image border should be handled.
 * @param interpType Which type of interpolation will be used.
 * @param angleInputToOutput Angle of rotation in radians. From input to output, CCW rotation.
 */
@Deprecated
public static <T extends ImageBase<T>> void rotate(T input, T output, BorderType borderType, InterpolationType interpType, float angleInputToOutput) {
    // (output.width+1)%2;
    float offX = 0;
    // (output.height+1)%2;
    float offY = 0;
    PixelTransform2_F32 model = DistortSupport.transformRotate(input.width / 2, input.height / 2, output.width / 2 - offX, output.height / 2 - offY, angleInputToOutput);
    if (input instanceof ImageGray) {
        distortSingle((ImageGray) input, (ImageGray) output, model, interpType, borderType);
    } else if (input instanceof Planar) {
        distortPL((Planar) input, (Planar) output, model, borderType, interpType);
    }
}
Also used : Planar(boofcv.struct.image.Planar) ImageGray(boofcv.struct.image.ImageGray) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32)

Example 2 with PixelTransform2_F32

use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.

the class TestDistortSupport method distortRotate.

@Test
public void distortRotate() {
    PixelTransform2_F32 tran = DistortSupport.transformRotate(13f, 15.0f, 13f, 15f, (float) (-Math.PI / 2.0));
    // trivial case
    tran.compute(13, 15);
    assertEquals(13, tran.distX, 1e-4);
    assertEquals(15, tran.distY, 1e-4);
    // see how it handles the rotation
    tran.compute(15, 20);
    assertEquals(8, tran.distX, 1e-4);
    assertEquals(17, tran.distY, 1e-4);
}
Also used : PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32) Test(org.junit.Test)

Example 3 with PixelTransform2_F32

use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.

the class TestDistortSupport method distortScale.

@Test
public void distortScale() {
    GrayF32 a = new GrayF32(25, 30);
    GrayF32 b = new GrayF32(15, 25);
    PixelTransform2_F32 tran = DistortSupport.transformScale(a, b, null);
    // check edge cases at the image border
    tran.compute(0, 0);
    assertEquals(0, tran.distX, 1e-8);
    assertEquals(0, tran.distY, 1e-8);
    tran.compute(24, 29);
    assertEquals(24 * 15.0 / 25.0, tran.distX, 1e-4);
    assertEquals(29 * 25.0 / 30.0, tran.distY, 1e-4);
    // some point inside now
    tran.compute(5, 6);
    assertEquals(5.0 * 15.0 / 25.0, tran.distX, 1e-4);
    assertEquals(6.0 * 25.0 / 30.0, tran.distY, 1e-4);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32) Test(org.junit.Test)

Example 4 with PixelTransform2_F32

use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.

the class StitchingFromMotion2D method resizeStitchImage.

/**
 * Resizes the stitch image.  If no transform is provided then the old stitch region is simply
 * places on top of the new one and copied.  Pixels which do not exist in the old image are filled with zero.
 *
 * @param widthStitch The new width of the stitch image.
 * @param heightStitch The new height of the stitch image.
 * @param newToOldStitch (Optional) Transform from new stitch image pixels to old stick pixels.  Can be null.
 */
public void resizeStitchImage(int widthStitch, int heightStitch, IT newToOldStitch) {
    // copy the old image into the new one
    workImage.reshape(widthStitch, heightStitch);
    GImageMiscOps.fill(workImage, 0);
    if (newToOldStitch != null) {
        PixelTransform2_F32 newToOld = converter.convertPixel(newToOldStitch, null);
        distorter.setModel(newToOld);
        distorter.apply(stitchedImage, workImage);
        // update the transforms
        IT tmp = (IT) worldToCurr.createInstance();
        newToOldStitch.concat(worldToInit, tmp);
        worldToInit.set(tmp);
        computeCurrToInit_PixelTran();
    } else {
        int overlapWidth = Math.min(widthStitch, stitchedImage.width);
        int overlapHeight = Math.min(heightStitch, stitchedImage.height);
        GImageMiscOps.copy(0, 0, 0, 0, overlapWidth, overlapHeight, stitchedImage, workImage);
    }
    stitchedImage.reshape(widthStitch, heightStitch);
    I tmp = stitchedImage;
    stitchedImage = workImage;
    workImage = tmp;
    this.widthStitch = widthStitch;
    this.heightStitch = heightStitch;
}
Also used : PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32)

Example 5 with PixelTransform2_F32

use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.

the class MultiCameraToEquirectangular method addCamera.

/**
 * Adds a camera and attempts to compute the mask from the provided distortion model.  if a pixel is rendered
 * outside the bounds in the input image then it is masked out.  If the forwards/backwards transform is too
 * different then it is masked out.
 *
 * @param cameraToCommon Rigid body transform from this camera to the common frame the equirectangular image
 *                       is in
 * @param factory Distortion model
 * @param width Input image width
 * @param height Input image height
 */
public void addCamera(Se3_F32 cameraToCommon, LensDistortionWideFOV factory, int width, int height) {
    Point2Transform3_F32 p2s = factory.undistortPtoS_F32();
    Point3Transform2_F32 s2p = factory.distortStoP_F32();
    EquiToCamera equiToCamera = new EquiToCamera(cameraToCommon.getR(), s2p);
    GrayF32 equiMask = new GrayF32(equiWidth, equHeight);
    PixelTransform2_F32 transformEquiToCam = new PixelTransformCached_F32(equiWidth, equHeight, new PointToPixelTransform_F32(equiToCamera));
    Point3D_F32 p3b = new Point3D_F32();
    Point2D_F32 p2 = new Point2D_F32();
    for (int row = 0; row < equHeight; row++) {
        for (int col = 0; col < equiWidth; col++) {
            equiToCamera.compute(col, row, p2);
            int camX = (int) (p2.x + 0.5f);
            int camY = (int) (p2.y + 0.5f);
            if (Double.isNaN(p2.x) || Double.isNaN(p2.y) || camX < 0 || camY < 0 || camX >= width || camY >= height)
                continue;
            p2s.compute(p2.x, p2.y, p3b);
            if (Double.isNaN(p3b.x) || Double.isNaN(p3b.y) || Double.isNaN(p3b.z))
                continue;
            double angle = UtilVector3D_F32.acute(equiToCamera.unitCam, p3b);
            if (angle < maskToleranceAngle) {
                equiMask.set(col, row, 1);
            }
        }
    }
    cameras.add(new Camera(equiMask, transformEquiToCam));
}
Also used : Point3D_F32(georegression.struct.point.Point3D_F32) GrayF32(boofcv.struct.image.GrayF32) PointToPixelTransform_F32(boofcv.alg.distort.PointToPixelTransform_F32) Point2D_F32(georegression.struct.point.Point2D_F32) Point2Transform3_F32(boofcv.struct.distort.Point2Transform3_F32) Point3Transform2_F32(boofcv.struct.distort.Point3Transform2_F32) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32) PixelTransformCached_F32(boofcv.alg.distort.PixelTransformCached_F32)

Aggregations

PixelTransform2_F32 (boofcv.struct.distort.PixelTransform2_F32)17 Test (org.junit.Test)7 PixelTransformAffine_F32 (boofcv.alg.distort.PixelTransformAffine_F32)6 Affine2D_F32 (georegression.struct.affine.Affine2D_F32)6 GrayU8 (boofcv.struct.image.GrayU8)4 ImageDistort (boofcv.alg.distort.ImageDistort)2 PixelTransformCached_F32 (boofcv.alg.distort.PixelTransformCached_F32)2 InterpolatePixel (boofcv.alg.interpolate.InterpolatePixel)2 GrayF32 (boofcv.struct.image.GrayF32)2 Affine2D_F64 (georegression.struct.affine.Affine2D_F64)2 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)2 ArrayList (java.util.ArrayList)2 Estimate1ofEpipolar (boofcv.abst.geo.Estimate1ofEpipolar)1 PixelTransformHomography_F32 (boofcv.alg.distort.PixelTransformHomography_F32)1 PointToPixelTransform_F32 (boofcv.alg.distort.PointToPixelTransform_F32)1 CameraPinhole (boofcv.struct.calib.CameraPinhole)1 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)1 Point2Transform2_F32 (boofcv.struct.distort.Point2Transform2_F32)1