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