Search in sources :

Example 1 with GrayU8

use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.

the class FactoryStereoDisparity method regionSparseWta.

/**
 * WTA algorithms that computes disparity on a sparse per-pixel basis as requested..
 *
 * @param minDisparity Minimum disparity that it will check. Must be ≥ 0 and < maxDisparity
 * @param maxDisparity Maximum disparity that it will calculate. Must be > 0
 * @param regionRadiusX Radius of the rectangular region along x-axis.
 * @param regionRadiusY Radius of the rectangular region along y-axis.
 * @param maxPerPixelError Maximum allowed error in a region per pixel.  Set to < 0 to disable.
 * @param texture Tolerance for how similar optimal region is to other region.  Closer to zero is more tolerant.
 *                Try 0.1
 * @param subpixelInterpolation true to turn on sub-pixel interpolation
 * @param imageType Type of input image.
 * @param <T> Image type
 * @return Sparse disparity algorithm
 */
public static <T extends ImageGray<T>> StereoDisparitySparse<T> regionSparseWta(int minDisparity, int maxDisparity, int regionRadiusX, int regionRadiusY, double maxPerPixelError, double texture, boolean subpixelInterpolation, Class<T> imageType) {
    double maxError = (regionRadiusX * 2 + 1) * (regionRadiusY * 2 + 1) * maxPerPixelError;
    if (imageType == GrayU8.class) {
        DisparitySparseSelect<int[]> select;
        if (subpixelInterpolation)
            select = selectDisparitySparseSubpixel_S32((int) maxError, texture);
        else
            select = selectDisparitySparse_S32((int) maxError, texture);
        DisparitySparseScoreSadRect<int[], GrayU8> score = scoreDisparitySparseSadRect_U8(minDisparity, maxDisparity, regionRadiusX, regionRadiusY);
        return new WrapDisparitySparseSadRect(score, select);
    } else if (imageType == GrayF32.class) {
        DisparitySparseSelect<float[]> select;
        if (subpixelInterpolation)
            select = selectDisparitySparseSubpixel_F32((int) maxError, texture);
        else
            select = selectDisparitySparse_F32((int) maxError, texture);
        DisparitySparseScoreSadRect<float[], GrayF32> score = scoreDisparitySparseSadRect_F32(minDisparity, maxDisparity, regionRadiusX, regionRadiusY);
        return new WrapDisparitySparseSadRect(score, select);
    } else
        throw new RuntimeException("Image type not supported: " + imageType.getSimpleName());
}
Also used : GrayF32(boofcv.struct.image.GrayF32) WrapDisparitySparseSadRect(boofcv.abst.feature.disparity.WrapDisparitySparseSadRect) DisparitySparseSelect(boofcv.alg.feature.disparity.DisparitySparseSelect) GrayU8(boofcv.struct.image.GrayU8) DisparitySparseScoreSadRect(boofcv.alg.feature.disparity.DisparitySparseScoreSadRect)

Example 2 with GrayU8

use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.

the class FactoryStereoDisparity method regionWta.

/**
 * <p>
 * Crates algorithms for computing dense disparity images up to pixel level accuracy.
 * </p>
 *
 * <p>
 * NOTE: For RECT_FIVE the size of the sub-regions it uses is what is specified.
 * </p>
 *
 * @param minDisparity Minimum disparity that it will check. Must be &ge; 0 and &lt; maxDisparity
 * @param maxDisparity Maximum disparity that it will calculate. Must be &gt; 0
 * @param regionRadiusX Radius of the rectangular region along x-axis.
 * @param regionRadiusY Radius of the rectangular region along y-axis.
 * @param maxPerPixelError Maximum allowed error in a region per pixel.  Set to &lt; 0 to disable.
 * @param validateRtoL Tolerance for how difference the left to right associated values can be.  Try 6
 * @param texture Tolerance for how similar optimal region is to other region.  Closer to zero is more tolerant.
 *                Try 0.1
 * @param imageType Type of input image.
 * @return Rectangular region based WTA disparity.algorithm.
 */
public static <T extends ImageGray<T>> StereoDisparity<T, GrayU8> regionWta(DisparityAlgorithms whichAlg, int minDisparity, int maxDisparity, int regionRadiusX, int regionRadiusY, double maxPerPixelError, int validateRtoL, double texture, Class<T> imageType) {
    double maxError = (regionRadiusX * 2 + 1) * (regionRadiusY * 2 + 1) * maxPerPixelError;
    // 3 regions are used not just one in this case
    if (whichAlg == DisparityAlgorithms.RECT_FIVE)
        maxError *= 3;
    DisparitySelect select;
    if (imageType == GrayU8.class || imageType == GrayS16.class) {
        select = selectDisparity_S32((int) maxError, validateRtoL, texture);
    } else if (imageType == GrayF32.class) {
        select = selectDisparity_F32((int) maxError, validateRtoL, texture);
    } else {
        throw new IllegalArgumentException("Unknown image type");
    }
    DisparityScoreRowFormat<T, GrayU8> alg = null;
    switch(whichAlg) {
        case RECT:
            if (imageType == GrayU8.class) {
                alg = FactoryStereoDisparityAlgs.scoreDisparitySadRect_U8(minDisparity, maxDisparity, regionRadiusX, regionRadiusY, select);
            } else if (imageType == GrayS16.class) {
                alg = FactoryStereoDisparityAlgs.scoreDisparitySadRect_S16(minDisparity, maxDisparity, regionRadiusX, regionRadiusY, select);
            } else if (imageType == GrayF32.class) {
                alg = FactoryStereoDisparityAlgs.scoreDisparitySadRect_F32(minDisparity, maxDisparity, regionRadiusX, regionRadiusY, select);
            }
            break;
        case RECT_FIVE:
            if (imageType == GrayU8.class) {
                alg = FactoryStereoDisparityAlgs.scoreDisparitySadRectFive_U8(minDisparity, maxDisparity, regionRadiusX, regionRadiusY, select);
            } else if (imageType == GrayS16.class) {
                alg = FactoryStereoDisparityAlgs.scoreDisparitySadRectFive_S16(minDisparity, maxDisparity, regionRadiusX, regionRadiusY, select);
            } else if (imageType == GrayF32.class) {
                alg = FactoryStereoDisparityAlgs.scoreDisparitySadRectFive_F32(minDisparity, maxDisparity, regionRadiusX, regionRadiusY, select);
            }
            break;
        default:
            throw new IllegalArgumentException("Unknown algorithms " + whichAlg);
    }
    if (alg == null)
        throw new RuntimeException("Image type not supported: " + imageType.getSimpleName());
    return new WrapDisparitySadRect<>(alg);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) DisparitySelect(boofcv.alg.feature.disparity.DisparitySelect) GrayS16(boofcv.struct.image.GrayS16) GrayU8(boofcv.struct.image.GrayU8) WrapDisparitySadRect(boofcv.abst.feature.disparity.WrapDisparitySadRect)

Example 3 with GrayU8

use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.

the class TestDescribeImageDense_Convert method basic.

/**
 * Checks to see if it converts the input image and that other functions are correctly
 * implemented
 */
@Test
public void basic() {
    Dummy dummy = new Dummy();
    DescribeImageDense<GrayU8, TupleDesc_F64> alg = new DescribeImageDense_Convert(dummy, ImageType.single(GrayU8.class));
    GrayU8 foo = new GrayU8(10, 20);
    foo.set(5, 2, 10);
    alg.process(foo);
    assertTrue(dummy.process);
    assertEquals(5, alg.createDescription().size());
    assertTrue(TupleDesc_F64.class == alg.getDescriptionType());
    assertTrue(alg.getImageType().getDataType() == ImageDataType.U8);
    assertTrue(null != alg.getDescriptions());
    assertTrue(null != alg.getLocations());
}
Also used : TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 4 with GrayU8

use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.

the class TestGenericDenseDescribeImage method checkDescriptorScale.

@Test
public void checkDescriptorScale() {
    DummyFeature sparse = new DummyFeature();
    GrayU8 image = new GrayU8(100, 110);
    GenericDenseDescribeImageDense alg = new GenericDenseDescribeImageDense(sparse, 1, 1, 8, 9);
    alg.configure(1, 8, 9);
    alg.process(image);
    int found10 = alg.getDescriptions().size();
    alg.configure(1.5, 8, 9);
    alg.process(image);
    int found15 = alg.getDescriptions().size();
    alg.configure(0.75, 8, 9);
    alg.process(image);
    int found07a = alg.getDescriptions().size();
    alg.configure(0.75, 8 * 0.75, 9 * 0.75);
    alg.process(image);
    int found07b = alg.getDescriptions().size();
    // same sampling period, should have same number of samples
    assertTrue(found07a == found10);
    assertTrue(found10 == found15);
    // sampling period is shorter so there should be more features
    assertTrue(found07b > found10);
}
Also used : GrayU8(boofcv.struct.image.GrayU8) DescribeRegionPoint(boofcv.abst.feature.describe.DescribeRegionPoint) Test(org.junit.Test)

Example 5 with GrayU8

use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.

the class TestWrapDisparitySparseSadRect method compareToDense.

/**
 * Compare to the equivalent dense algorithm
 */
@Test
public void compareToDense() {
    // more stressful if not 0
    int minDisparity = 3;
    int maxDisparity = 12;
    GrayF32 left = new GrayF32(w, h);
    GrayF32 right = new GrayF32(w, h);
    StereoDisparity<GrayF32, GrayU8> validator = FactoryStereoDisparity.regionWta(DisparityAlgorithms.RECT, minDisparity, maxDisparity, r, r, -1, -1, -1, GrayF32.class);
    StereoDisparitySparse<GrayF32> alg = new WrapDisparitySparseSadRect<>(new ImplDisparitySparseScoreSadRect_F32(minDisparity, maxDisparity, r, r), new ImplSelectSparseBasicWta_F32());
    validator.process(left, right);
    GrayU8 expected = validator.getDisparity();
    alg.setImages(left, right);
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            if (alg.process(x, y)) {
                double found = alg.getDisparity();
                assertEquals(minDisparity + expected.get(x, y), (int) found);
            } else {
                assertTrue(expected.get(x, y) > (maxDisparity - minDisparity));
            }
        }
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ImplSelectSparseBasicWta_F32(boofcv.alg.feature.disparity.impl.ImplSelectSparseBasicWta_F32) GrayU8(boofcv.struct.image.GrayU8) ImplDisparitySparseScoreSadRect_F32(boofcv.alg.feature.disparity.impl.ImplDisparitySparseScoreSadRect_F32) Test(org.junit.Test)

Aggregations

GrayU8 (boofcv.struct.image.GrayU8)417 Test (org.junit.Test)242 BufferedImage (java.awt.image.BufferedImage)53 GrayS32 (boofcv.struct.image.GrayS32)52 GrayF32 (boofcv.struct.image.GrayF32)49 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)48 GrayS16 (boofcv.struct.image.GrayS16)45 Planar (boofcv.struct.image.Planar)28 ArrayList (java.util.ArrayList)22 File (java.io.File)17 ListDisplayPanel (boofcv.gui.ListDisplayPanel)16 RectangleLength2D_I32 (georegression.struct.shapes.RectangleLength2D_I32)16 ImageGray (boofcv.struct.image.ImageGray)15 EllipseRotated_F64 (georegression.struct.curve.EllipseRotated_F64)15 Random (java.util.Random)14 Point2D_F64 (georegression.struct.point.Point2D_F64)11 ImageRectangle (boofcv.struct.ImageRectangle)10 GrayU16 (boofcv.struct.image.GrayU16)10 Se3_F64 (georegression.struct.se.Se3_F64)10 Point3D_F64 (georegression.struct.point.Point3D_F64)9