use of boofcv.struct.image.GrayF32 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.GrayF32 in project BoofCV by lessthanoptimal.
the class FactoryOrientation method sift.
/**
* Creates an implementation of the SIFT orientation estimation algorithm
*
* @param configSS Configuration of the scale-space. null for default
* @param configOri Orientation configuration. null for default
* @param imageType Type of input image
* @return SIFT orientation image
*/
public static <T extends ImageGray<T>> OrientationImage<T> sift(ConfigSiftScaleSpace configSS, ConfigSiftOrientation configOri, Class<T> imageType) {
if (configSS == null)
configSS = new ConfigSiftScaleSpace();
configSS.checkValidity();
OrientationHistogramSift<GrayF32> ori = FactoryOrientationAlgs.sift(configOri, GrayF32.class);
SiftScaleSpace ss = new SiftScaleSpace(configSS.firstOctave, configSS.lastOctave, configSS.numScales, configSS.sigma0);
return new OrientationSiftToImage<>(ori, ss, imageType);
}
use of boofcv.struct.image.GrayF32 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));
}
}
}
}
use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.
the class GeneralNonMaxSuppressionChecks method checkSubImage.
/**
* When processing a sub-image it should produce the same results as when processing a regular image
*/
@Test
public void checkSubImage() {
init();
ImageMiscOps.fillGaussian(image, rand, 0, 2, -100, 100);
// make every pixel as a candidate since I'm not sure which ones are extremes.
for (int i = 0; i < image.height; i++) for (int j = 0; j < image.width; j++) {
if (candidatesMin != null)
candidatesMin.add(j, i);
if (candidatesMax != null)
candidatesMax.add(j, i);
}
// the original input image
foundMin.reset();
foundMax.reset();
alg.process(image, candidatesMin, candidatesMax, foundMin, foundMax);
int origMin = foundMin.size;
int origMax = foundMax.size;
// if sub-images are correctly handled this should produce identical results
GrayF32 sub = BoofTesting.createSubImageOf(image);
foundMin.reset();
foundMax.reset();
alg.process(sub, candidatesMin, candidatesMax, foundMin, foundMax);
int subMin = foundMin.size;
int subMax = foundMax.size;
assertEquals(origMin, subMin);
assertEquals(origMax, subMax);
}
use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.
the class TestNonMaxLimiter method checkLimit.
/**
* 4 features, but a max of 2 is requested.
*/
@Test
public void checkLimit() {
GrayF32 intensity = new GrayF32(30, 25);
intensity.set(10, 15, 20);
intensity.set(12, 20, 25);
intensity.set(1, 15, -20);
intensity.set(1, 20, -25);
NonMaxSuppression extractor = FactoryFeatureExtractor.nonmax(new ConfigExtract(1, 0, 0, true, true, true));
NonMaxLimiter limiter = new NonMaxLimiter(extractor, 2);
limiter.process(intensity);
FastQueue<NonMaxLimiter.LocalExtreme> found = limiter.getLocalExtreme();
assertEquals(2, found.size());
for (int i = 0; i < found.size(); i++) {
NonMaxLimiter.LocalExtreme a = found.get(i);
assertEquals(a.getValue(), intensity.get(a.location.x, a.location.y));
assertEquals(a.getValue() > 0, a.max);
assertEquals(25, a.intensity, 1e-8);
}
}
Aggregations