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);
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations