use of boofcv.alg.distort.PixelTransformAffine_F32 in project BoofCV by lessthanoptimal.
the class TestBinaryEllipseDetectorPixel method undistortContour_WithDistortion.
/**
* Undistort the image when distortion model is provided
*/
@Test
public void undistortContour_WithDistortion() {
List<Point2D_I32> input = new ArrayList<>();
FastQueue<Point2D_F64> output = new FastQueue<>(Point2D_F64.class, true);
for (int i = 0; i < 10; i++) {
input.add(new Point2D_I32(i, i));
}
BinaryEllipseDetectorPixel alg = new BinaryEllipseDetectorPixel();
alg.setLensDistortion(new PixelTransformAffine_F32(new Affine2D_F32(1, 0, 0, 1, 10.0f, 0)));
alg.undistortContour(input, output);
assertEquals(input.size(), output.size);
for (int i = 0; i < input.size(); i++) {
Point2D_I32 p = input.get(i);
assertEquals(p.x + 10, output.get(i).x, 1e-8);
assertEquals(p.y, output.get(i).y, 1e-8);
}
}
use of boofcv.alg.distort.PixelTransformAffine_F32 in project BoofCV by lessthanoptimal.
the class TestDetectPolygonBinaryGrayRefine 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;
DetectPolygonBinaryGrayRefine alg = createAlg(imageType, numberOfSides, numberOfSides);
alg.setLensDistortion(image.width, image.height, tranTo, tranFrom);
alg.process(image, binary);
List<DetectPolygonFromContour.Info> found = alg.getPolygonInfo();
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);
}
// ----------- see if distortion is cleared properly
alg.clearLensDistortion();
alg.process(image, binary);
found = alg.getPolygonInfo();
assertEquals(rectangles.size(), found.size());
// nothing should match now
for (int i = 0; i < found.size(); i++) {
Polygon2D_F64 p = found.get(i).polygon;
assertEquals(0, findMatchesOriginal(p, tol));
}
}
use of boofcv.alg.distort.PixelTransformAffine_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 boofcv.alg.distort.PixelTransformAffine_F32 in project BoofCV by lessthanoptimal.
the class PyramidFloatGaussianScale method process.
@Override
public void process(T input) {
super.initialize(input.width, input.height);
if (isSaveOriginalReference())
throw new IllegalArgumentException("The original reference cannot be saved");
if (tempImage == null) {
tempImage = (T) input.createNew(input.width, input.height);
}
for (int i = 0; i < scale.length; i++) {
T prev = i == 0 ? input : getLayer(i - 1);
T layer = getLayer(i);
// Apply the requested blur to the previous layer
BlurStorageFilter<T> blur = (BlurStorageFilter<T>) FactoryBlurFilter.gaussian(layer.getImageType(), sigmaLayers[i], -1);
tempImage.reshape(prev.width, prev.height);
blur.process(prev, tempImage);
// Resample the blurred image
if (scale[i] == 1) {
layer.setTo(tempImage);
} else {
PixelTransformAffine_F32 model = DistortSupport.transformScale(layer, tempImage, null);
DistortImageOps.distortSingle(tempImage, layer, true, model, interpolate);
}
}
}
use of boofcv.alg.distort.PixelTransformAffine_F32 in project BoofCV by lessthanoptimal.
the class PyramidFloatScale method process.
@Override
public void process(T input) {
super.initialize(input.width, input.height);
if (isSaveOriginalReference())
throw new IllegalArgumentException("The original reference cannot be saved");
for (int i = 0; i < scale.length; i++) {
T prev = i == 0 ? input : getLayer(i - 1);
T layer = getLayer(i);
PixelTransformAffine_F32 model = DistortSupport.transformScale(layer, prev, null);
DistortImageOps.distortSingle(prev, layer, true, model, interpolate);
}
}
Aggregations