use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.
the class TestImplIntegralImageOps method convolveBorder.
public void convolveBorder(Method m) throws InvocationTargetException, IllegalAccessException {
Kernel2D_S32 kernel = new Kernel2D_S32(3, new int[] { 1, 1, 1, 2, 2, 2, 1, 1, 1 });
GrayU8 input = new GrayU8(width, height);
GrayS32 expected = new GrayS32(width, height);
GImageMiscOps.fillUniform(input, rand, 0, 10);
ImageBorder_S32 border = FactoryImageBorderAlgs.value(input, 0);
ConvolveImage.convolve(kernel, input, expected, border);
Class[] paramType = m.getParameterTypes();
Class inputType = paramType[0];
Class outputType = paramType[2];
ImageGray inputII = GeneralizedImageOps.createSingleBand(inputType, width, height);
ImageGray integral = GeneralizedImageOps.createSingleBand(outputType, width, height);
ImageGray expectedII = GeneralizedImageOps.createSingleBand(outputType, width, height);
ImageGray found = GeneralizedImageOps.createSingleBand(outputType, width, height);
GConvertImage.convert(input, inputII);
GConvertImage.convert(expected, expectedII);
GIntegralImageOps.transform(inputII, integral);
IntegralKernel kernelII = new IntegralKernel(2);
kernelII.blocks[0] = new ImageRectangle(-2, -2, 1, 1);
kernelII.blocks[1] = new ImageRectangle(-2, -1, 1, 0);
kernelII.scales = new int[] { 1, 1 };
m.invoke(null, integral, kernelII, found, 4, 5);
BoofTesting.assertEqualsBorder(expected, found, 1e-4f, 4, 5);
}
use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.
the class TestImplPolynomialPixel_I method compareToBilinear.
/**
* Polynomial interpolation of order one is bilinear interpolation
*/
@Test
public void compareToBilinear() {
GrayU8 img = new GrayU8(width, height);
GrayU8 expected = new GrayU8(width, height);
GrayU8 found = new GrayU8(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
InterpolatePixelS<GrayU8> alg = (InterpolatePixelS) new ImplPolynomialPixel_I(2, 0, 255);
alg.setBorder(FactoryImageBorder.singleValue(GrayU8.class, 0));
ImageDistort<GrayU8, GrayU8> distorter = FactoryDistort.distortSB(false, alg, GrayU8.class);
distorter.setModel(new PixelTransformAffine_F32(tran));
distorter.apply(img, found);
InterpolatePixelS<GrayU8> bilinear = FactoryInterpolation.bilinearPixelS(GrayU8.class, BorderType.ZERO);
distorter = FactoryDistort.distortSB(false, bilinear, GrayU8.class);
distorter.setModel(new PixelTransformAffine_F32(tran));
distorter.apply(img, expected);
BoofTesting.assertEquals(expected, found, 0);
}
use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.
the class TestImplWaveletTransformNaive method testEncodeDecode_I32.
private void testEncodeDecode_I32(int widthOrig, int heightOrig, int widthOut, int heightOut) {
GrayU8 orig = new GrayU8(widthOrig, heightOrig);
ImageMiscOps.fillUniform(orig, rand, 0, 10);
GrayS32 transformed = new GrayS32(widthOut, heightOut);
GrayU8 reconstructed = new GrayU8(widthOrig, heightOrig);
BoofTesting.checkSubImage(this, "checkTransforms_I", true, orig, transformed, reconstructed);
}
use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.
the class ExampleStereoDisparity method rectify.
/**
* Rectified the input images using known calibration.
*/
public static RectifyCalibrated rectify(GrayU8 origLeft, GrayU8 origRight, StereoParameters param, GrayU8 rectLeft, GrayU8 rectRight) {
// Compute rectification
RectifyCalibrated rectifyAlg = RectifyImageOps.createCalibrated();
Se3_F64 leftToRight = param.getRightToLeft().invert(null);
// original camera calibration matrices
DMatrixRMaj K1 = PerspectiveOps.calibrationMatrix(param.getLeft(), (DMatrixRMaj) null);
DMatrixRMaj K2 = PerspectiveOps.calibrationMatrix(param.getRight(), (DMatrixRMaj) null);
rectifyAlg.process(K1, new Se3_F64(), K2, leftToRight);
// rectification matrix for each image
DMatrixRMaj rect1 = rectifyAlg.getRect1();
DMatrixRMaj rect2 = rectifyAlg.getRect2();
// New calibration matrix,
DMatrixRMaj rectK = rectifyAlg.getCalibrationMatrix();
// Adjust the rectification to make the view area more useful
RectifyImageOps.allInsideLeft(param.left, rect1, rect2, rectK);
// undistorted and rectify images
FMatrixRMaj rect1_F32 = new FMatrixRMaj(3, 3);
FMatrixRMaj rect2_F32 = new FMatrixRMaj(3, 3);
ConvertMatrixData.convert(rect1, rect1_F32);
ConvertMatrixData.convert(rect2, rect2_F32);
ImageDistort<GrayU8, GrayU8> imageDistortLeft = RectifyImageOps.rectifyImage(param.getLeft(), rect1_F32, BorderType.SKIP, origLeft.getImageType());
ImageDistort<GrayU8, GrayU8> imageDistortRight = RectifyImageOps.rectifyImage(param.getRight(), rect2_F32, BorderType.SKIP, origRight.getImageType());
imageDistortLeft.apply(origLeft, rectLeft);
imageDistortRight.apply(origRight, rectRight);
return rectifyAlg;
}
use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.
the class ExampleStereoDisparity method main.
public static void main(String[] args) {
String calibDir = UtilIO.pathExample("calibration/stereo/Bumblebee2_Chess/");
String imageDir = UtilIO.pathExample("stereo/");
StereoParameters param = CalibrationIO.load(new File(calibDir, "stereo.yaml"));
// load and convert images into a BoofCV format
BufferedImage origLeft = UtilImageIO.loadImage(imageDir, "chair01_left.jpg");
BufferedImage origRight = UtilImageIO.loadImage(imageDir, "chair01_right.jpg");
GrayU8 distLeft = ConvertBufferedImage.convertFrom(origLeft, (GrayU8) null);
GrayU8 distRight = ConvertBufferedImage.convertFrom(origRight, (GrayU8) null);
// rectify images
GrayU8 rectLeft = distLeft.createSameShape();
GrayU8 rectRight = distRight.createSameShape();
rectify(distLeft, distRight, param, rectLeft, rectRight);
// compute disparity
GrayU8 disparity = denseDisparity(rectLeft, rectRight, 5, 10, 60);
// GrayF32 disparity = denseDisparitySubpixel(rectLeft,rectRight,5,10,60);
// show results
BufferedImage visualized = VisualizeImageData.disparity(disparity, null, 10, 60, 0);
ListDisplayPanel gui = new ListDisplayPanel();
gui.addImage(rectLeft, "Rectified");
gui.addImage(visualized, "Disparity");
ShowImages.showWindow(gui, "Stereo Disparity", true);
}
Aggregations