Search in sources :

Example 1 with GrayS16

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

the class FactoryDetectLineAlgs method lineRansac.

/**
 * Detects line segments inside an image using the {@link DetectLineSegmentsGridRansac} algorithm.
 *
 * @see DetectLineSegmentsGridRansac
 *
 * @param regionSize Size of the region considered.  Try 40 and tune.
 * @param thresholdEdge Threshold for determining which pixels belong to an edge or not. Try 30 and tune.
 * @param thresholdAngle Tolerance in angle for allowing two edgels to be paired up, in radians.  Try 2.36
 * @param connectLines Should lines be connected and optimized.
 * @param imageType Type of single band input image.
 * @param derivType Image derivative type.
 * @return Line segment detector
 */
public static <I extends ImageGray<I>, D extends ImageGray<D>> DetectLineSegmentsGridRansac<I, D> lineRansac(int regionSize, double thresholdEdge, double thresholdAngle, boolean connectLines, Class<I> imageType, Class<D> derivType) {
    ImageGradient<I, D> gradient = FactoryDerivative.sobel(imageType, derivType);
    ModelManagerLinePolar2D_F32 manager = new ModelManagerLinePolar2D_F32();
    GridLineModelDistance distance = new GridLineModelDistance((float) thresholdAngle);
    GridLineModelFitter fitter = new GridLineModelFitter((float) thresholdAngle);
    ModelMatcher<LinePolar2D_F32, Edgel> matcher = new Ransac<>(123123, manager, fitter, distance, 25, 1);
    GridRansacLineDetector<D> alg;
    if (derivType == GrayF32.class) {
        alg = (GridRansacLineDetector) new ImplGridRansacLineDetector_F32(regionSize, 10, matcher);
    } else if (derivType == GrayS16.class) {
        alg = (GridRansacLineDetector) new ImplGridRansacLineDetector_S16(regionSize, 10, matcher);
    } else {
        throw new IllegalArgumentException("Unsupported derivative type");
    }
    ConnectLinesGrid connect = null;
    if (connectLines)
        connect = new ConnectLinesGrid(Math.PI * 0.01, 1, 8);
    return new DetectLineSegmentsGridRansac<>(alg, connect, gradient, thresholdEdge, imageType, derivType);
}
Also used : LinePolar2D_F32(georegression.struct.line.LinePolar2D_F32) ModelManagerLinePolar2D_F32(georegression.fitting.line.ModelManagerLinePolar2D_F32) ModelManagerLinePolar2D_F32(georegression.fitting.line.ModelManagerLinePolar2D_F32) GrayS16(boofcv.struct.image.GrayS16) GridRansacLineDetector(boofcv.alg.feature.detect.line.GridRansacLineDetector) DetectLineSegmentsGridRansac(boofcv.abst.feature.detect.line.DetectLineSegmentsGridRansac) Ransac(org.ddogleg.fitting.modelset.ransac.Ransac) DetectLineSegmentsGridRansac(boofcv.abst.feature.detect.line.DetectLineSegmentsGridRansac) ConnectLinesGrid(boofcv.alg.feature.detect.line.ConnectLinesGrid)

Example 2 with GrayS16

use of boofcv.struct.image.GrayS16 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 GrayS16

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

the class TestImplEnhanceFilter method sharpenBorder4.

public void sharpenBorder4(ImageGray input, ImageGray output) {
    ImageGray expected;
    GImageMiscOps.fillUniform(input, rand, 0, 10);
    if (input.getDataType().isInteger()) {
        BoofTesting.callStaticMethod(ImplEnhanceFilter.class, "sharpenBorder4", input, output, 0, 255);
        expected = new GrayS16(input.width, input.height);
        ImageBorder_S32 border = BoofDefaults.borderDerivative_I32();
        border.setImage(input);
        ConvolveJustBorder_General_SB.convolve(ImplEnhanceFilter.kernelEnhance4_I32, border, (GrayS16) expected);
        GPixelMath.boundImage(expected, 0, 255);
    } else {
        BoofTesting.callStaticMethod(ImplEnhanceFilter.class, "sharpenBorder4", input, output, 0f, 255f);
        expected = new GrayF32(input.width, input.height);
        ImageBorder_F32 border = BoofDefaults.borderDerivative_F32();
        border.setImage((GrayF32) input);
        ConvolveJustBorder_General_SB.convolve(ImplEnhanceFilter.kernelEnhance4_F32, border, (GrayF32) expected);
        GPixelMath.boundImage(expected, 0, 255);
    }
    BoofTesting.assertEquals(expected, output, 1e-5);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) GrayS16(boofcv.struct.image.GrayS16) ImageGray(boofcv.struct.image.ImageGray) ImageBorder_F32(boofcv.core.image.border.ImageBorder_F32) ImageBorder_S32(boofcv.core.image.border.ImageBorder_S32)

Example 4 with GrayS16

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

the class TestImplEnhanceFilter method sharpenBorder8.

public void sharpenBorder8(ImageGray input, ImageGray output) {
    ImageGray expected;
    GImageMiscOps.fillUniform(input, rand, 0, 10);
    if (input.getDataType().isInteger()) {
        BoofTesting.callStaticMethod(ImplEnhanceFilter.class, "sharpenBorder8", input, output, 0, 255);
        expected = new GrayS16(input.width, input.height);
        ImageBorder_S32 border = BoofDefaults.borderDerivative_I32();
        border.setImage(input);
        ConvolveJustBorder_General_SB.convolve(ImplEnhanceFilter.kernelEnhance8_I32, border, (GrayS16) expected);
        GPixelMath.boundImage(expected, 0, 255);
    } else {
        BoofTesting.callStaticMethod(ImplEnhanceFilter.class, "sharpenBorder8", input, output, 0f, 255f);
        expected = new GrayF32(input.width, input.height);
        ImageBorder_F32 border = BoofDefaults.borderDerivative_F32();
        border.setImage((GrayF32) input);
        ConvolveJustBorder_General_SB.convolve(ImplEnhanceFilter.kernelEnhance8_F32, border, (GrayF32) expected);
        GPixelMath.boundImage(expected, 0, 255);
    }
    BoofTesting.assertEquals(expected, output, 1e-5);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) GrayS16(boofcv.struct.image.GrayS16) ImageGray(boofcv.struct.image.ImageGray) ImageBorder_F32(boofcv.core.image.border.ImageBorder_F32) ImageBorder_S32(boofcv.core.image.border.ImageBorder_S32)

Example 5 with GrayS16

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

the class DerivativeHelperFunctions method processBorderHorizontal.

public static void processBorderHorizontal(GrayS16 orig, GrayS16 deriv, Kernel1D_S32 kernel, ImageBorder_S32 borderType) {
    borderType.setImage(orig);
    ConvolveJustBorder_General_SB.horizontal(kernel, borderType, deriv);
    GrayS16 origSub;
    GrayS16 derivSub;
    origSub = orig.subimage(0, 0, orig.width, 2, null);
    derivSub = deriv.subimage(0, 0, orig.width, 2, null);
    ConvolveImageNoBorder.horizontal(kernel, origSub, derivSub);
    origSub = orig.subimage(0, orig.height - 2, orig.width, orig.height, null);
    derivSub = deriv.subimage(0, orig.height - 2, orig.width, orig.height, null);
    ConvolveImageNoBorder.horizontal(kernel, origSub, derivSub);
}
Also used : GrayS16(boofcv.struct.image.GrayS16)

Aggregations

GrayS16 (boofcv.struct.image.GrayS16)63 GrayU8 (boofcv.struct.image.GrayU8)45 Test (org.junit.Test)39 ImageBorder_S32 (boofcv.core.image.border.ImageBorder_S32)15 GrayF32 (boofcv.struct.image.GrayF32)13 Random (java.util.Random)8 CompareDerivativeToConvolution (boofcv.alg.filter.derivative.CompareDerivativeToConvolution)7 BorderIndex1D_Extend (boofcv.core.image.border.BorderIndex1D_Extend)4 ImageBorder1D_S32 (boofcv.core.image.border.ImageBorder1D_S32)4 ImageGray (boofcv.struct.image.ImageGray)4 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)3 BufferedImage (java.awt.image.BufferedImage)3 WrapDisparitySadRect (boofcv.abst.feature.disparity.WrapDisparitySadRect)2 DisparitySelect (boofcv.alg.feature.disparity.DisparitySelect)2 ImageBorder_F32 (boofcv.core.image.border.ImageBorder_F32)2 ListDisplayPanel (boofcv.gui.ListDisplayPanel)2 Kernel1D_S32 (boofcv.struct.convolve.Kernel1D_S32)2 FDistort (boofcv.abst.distort.FDistort)1 DetectLineSegmentsGridRansac (boofcv.abst.feature.detect.line.DetectLineSegmentsGridRansac)1 EdgeContour (boofcv.alg.feature.detect.edge.EdgeContour)1