use of boofcv.alg.interpolate.InterpolatePixelS in project BoofCV by lessthanoptimal.
the class LensDistortionOps method changeCameraModel.
/**
* Creates a distortion for modifying the input image from one camera model into another camera model. If
* requested the camera model can be further modified to ensure certain visibility requirements are meet
* and the adjusted camera model will be returned.
* @param type How it should modify the image model to ensure visibility of pixels.
* @param borderType How the image border is handled
* @param original The original camera model
* @param desired The desired camera model
* @param modified (Optional) The desired camera model after being rescaled. Can be null.
* @param imageType Type of image.
* @return Image distortion from original camera model to the modified one.
*/
public static <T extends ImageBase<T>, O extends CameraPinhole, D extends CameraPinhole> ImageDistort<T, T> changeCameraModel(AdjustmentType type, BorderType borderType, O original, D desired, D modified, ImageType<T> imageType) {
Class bandType = imageType.getImageClass();
boolean skip = borderType == BorderType.SKIP;
// it has to process the border at some point, so if skip is requested just skip stuff truly outside the image
if (skip)
borderType = BorderType.EXTENDED;
InterpolatePixelS interp = FactoryInterpolation.createPixelS(0, 255, InterpolationType.BILINEAR, borderType, bandType);
Point2Transform2_F32 undistToDist = transformChangeModel_F32(type, original, desired, true, modified);
ImageDistort<T, T> distort = FactoryDistort.distort(true, interp, imageType);
distort.setModel(new PointToPixelTransform_F32(undistToDist));
distort.setRenderAll(!skip);
return distort;
}
use of boofcv.alg.interpolate.InterpolatePixelS in project BoofCV by lessthanoptimal.
the class TestBaseDetectFiducialSquare method detectWithLensDistortion.
private void detectWithLensDistortion(List<Point2D_F64> expected, DetectCorner detector, CameraPinholeRadial intrinsic) {
// create a pattern with a corner for orientation and put it into the image
GrayU8 pattern = createPattern(6 * 20, true);
GrayU8 image = new GrayU8(width, height);
ImageMiscOps.fill(image, 255);
image.subimage(60, 300, 60 + pattern.width, 300 + pattern.height, null).setTo(pattern);
// place the pattern right next to one of the corners to maximize distortion
// add lens distortion
Point2Transform2_F32 distToUndistort = LensDistortionOps.narrow(intrinsic).undistort_F32(true, true);
Point2Transform2_F64 undistTodist = LensDistortionOps.narrow(intrinsic).distort_F64(true, true);
InterpolatePixelS interp = FactoryInterpolation.createPixelS(0, 255, InterpolationType.BILINEAR, BorderType.ZERO, GrayU8.class);
ImageDistort<GrayU8, GrayU8> distorter = FactoryDistort.distortSB(false, interp, GrayU8.class);
distorter.setModel(new PointToPixelTransform_F32(distToUndistort));
GrayU8 distorted = new GrayU8(width, height);
distorter.apply(image, distorted);
detector.configure(new LensDistortionRadialTangential(intrinsic), width, height, false);
detector.process(distorted);
assertEquals(1, detector.getFound().size());
FoundFiducial ff = detector.getFound().get(0);
// see if the returned corners
Point2D_F64 expectedDist = new Point2D_F64();
for (int j = 0; j < 4; j++) {
Point2D_F64 f = ff.distortedPixels.get(j);
Point2D_F64 e = expected.get((j + 1) % 4);
undistTodist.compute(e.x, e.y, expectedDist);
assertTrue(f.distance(expectedDist) <= 0.4);
}
// The check to see if square is correctly undistorted is inside the processing function itself
}
use of boofcv.alg.interpolate.InterpolatePixelS in project BoofCV by lessthanoptimal.
the class TestTrackerMeanShiftComaniciu2003 method updateLocation.
@Test
public void updateLocation() {
InterpolatePixelS interpSB = FactoryInterpolation.bilinearPixelS(GrayF32.class, BorderType.EXTENDED);
InterpolatePixelMB interpolate = FactoryInterpolation.createPixelPL(interpSB);
LocalWeightedHistogramRotRect calcHistogram = new LocalWeightedHistogramRotRect(30, 3, 10, 3, 255, interpolate);
TrackerMeanShiftComaniciu2003 alg = new TrackerMeanShiftComaniciu2003(false, 100, 1e-8f, 0.1f, 0.0f, 0.1f, calcHistogram);
Planar<GrayF32> image = new Planar<>(GrayF32.class, 100, 150, 3);
// odd width and height so samples land on pixels
render(image, 50, 40, 21, 31);
RectangleRotate_F32 found = new RectangleRotate_F32(50, 40, 21, 31, 0);
alg.initialize(image, found);
// test no change
alg.updateLocation(image, found);
check(found, 50, 40, 21, 31, 0);
// test translation
render(image, 55, 34, 21, 31);
alg.updateLocation(image, found);
check(found, 55, 34, 21, 31, 0);
}
use of boofcv.alg.interpolate.InterpolatePixelS in project BoofCV by lessthanoptimal.
the class GeneralChecksInterpolationPixelMB method compareToSingleBand.
/**
* Compares interpolation to two single band images and sees if they produce nearly identical results
*/
@Test
public void compareToSingleBand() {
T origMB = createImage(30, 40, 2);
GImageMiscOps.fillUniform(origMB, rand, 0, 100);
ImageDataType dataType = origMB.getImageType().getDataType();
ImageGray band0 = GeneralizedImageOps.createSingleBand(dataType, origMB.width, origMB.height);
ImageGray band1 = GeneralizedImageOps.createSingleBand(dataType, origMB.width, origMB.height);
for (int y = 0; y < origMB.height; y++) {
for (int x = 0; x < origMB.width; x++) {
double val0 = GeneralizedImageOps.get(origMB, x, y, 0);
double val1 = GeneralizedImageOps.get(origMB, x, y, 1);
GeneralizedImageOps.set(band0, x, y, val0);
GeneralizedImageOps.set(band1, x, y, val1);
}
}
InterpolatePixelS interpBand0 = wrapSingle(band0, 0, 255);
InterpolatePixelS interpBand1 = wrapSingle(band1, 0, 255);
InterpolatePixelMB<T> interpMB = wrap(origMB, 0, 255);
interpBand0.setBorder(FactoryImageBorder.genericValue(0, band0.getImageType()));
interpBand1.setBorder(FactoryImageBorder.genericValue(0, band1.getImageType()));
interpMB.setBorder(FactoryImageBorder.genericValue(0, interpMB.getImageType()));
interpBand0.setImage(band0);
interpBand1.setImage(band1);
interpMB.setImage(origMB);
float[] values = new float[2];
for (int y = 0; y < origMB.height - 1; y++) {
for (int x = 0; x < origMB.width - 1; x++) {
float val0 = interpBand0.get(x + 0.2f, y + 0.3f);
float val1 = interpBand1.get(x + 0.2f, y + 0.3f);
interpMB.get(x + 0.2f, y + 0.3f, values);
assertEquals(val0, values[0], 1e-4f);
assertEquals(val1, values[1], 1e-4f);
}
}
}
use of boofcv.alg.interpolate.InterpolatePixelS in project BoofCV by lessthanoptimal.
the class TestStitchingFromMotion2D method resizeStitchImage_Transform.
@Test
public void resizeStitchImage_Transform() {
HelperMotion motion = new HelperMotion();
InterpolatePixelS interp = FactoryInterpolation.createPixelS(0, 255, InterpolationType.BILINEAR, BorderType.EXTENDED, GrayF32.class);
ImageDistort distorter = FactoryDistort.distortSB(false, interp, GrayF32.class);
StitchingTransform trans = FactoryStitchingTransform.createAffine_F64();
StitchingFromMotion2D<GrayF32, Affine2D_F64> alg = new StitchingFromMotion2D<>(motion, distorter, trans, 0.3);
alg.configure(200, 300, null);
assertTrue(alg.process(image));
ImageMiscOps.fill(alg.getStitchedImage().subimage(2, 3, 30, 40, null), 1);
Affine2D_F64 transform = new Affine2D_F64(1, 0, 0, 1, -2, 4);
alg.resizeStitchImage(250, 400, transform);
// see if the image is where it should be
checkBlock(4, 0, 32, 36, alg.getStitchedImage());
// check the stitched image size
assertEquals(250, alg.getStitchedImage().width);
assertEquals(400, alg.getStitchedImage().height);
// check to see if translation was correctly applied
Affine2D_F64 found = alg.getWorldToCurr();
assertEquals(1 - 2, found.tx, 1e-5);
assertEquals(-2 + 4, found.ty, 1e-5);
}
Aggregations