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);
}
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 ≥ 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 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);
}
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);
}
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);
}
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);
}
Aggregations