use of boofcv.alg.interpolate.InterpolatePixelMB in project BoofCV by lessthanoptimal.
the class FactorySegmentationAlg method meanShift.
/**
* Creates an instance of {@link boofcv.alg.segmentation.ms.SegmentMeanShift}. Uniform distributions are used for spacial and color
* weights.
*
* @param config Specify configuration for mean-shift
* @param imageType Type of input image
* @return SegmentMeanShift
*/
public static <T extends ImageBase<T>> SegmentMeanShift<T> meanShift(@Nullable ConfigSegmentMeanShift config, ImageType<T> imageType) {
if (config == null)
config = new ConfigSegmentMeanShift();
int spacialRadius = config.spacialRadius;
float colorRadius = config.colorRadius;
int maxIterations = 20;
float convergenceTol = 0.1f;
SegmentMeanShiftSearch<T> search;
if (imageType.getFamily() == ImageType.Family.GRAY) {
InterpolatePixelS interp = FactoryInterpolation.bilinearPixelS(imageType.getImageClass(), BorderType.EXTENDED);
search = new SegmentMeanShiftSearchGray(maxIterations, convergenceTol, interp, spacialRadius, spacialRadius, colorRadius, config.fast);
} else {
InterpolatePixelMB interp = FactoryInterpolation.createPixelMB(0, 255, InterpolationType.BILINEAR, BorderType.EXTENDED, (ImageType) imageType);
search = new SegmentMeanShiftSearchColor(maxIterations, convergenceTol, interp, spacialRadius, spacialRadius, colorRadius, config.fast, imageType);
}
ComputeRegionMeanColor<T> regionColor = regionMeanColor(imageType);
MergeRegionMeanShift merge = new MergeRegionMeanShift(spacialRadius / 2 + 1, Math.max(1, colorRadius / 2));
MergeSmallRegions<T> prune = config.minimumRegionSize >= 2 ? new MergeSmallRegions<>(config.minimumRegionSize, config.connectRule, regionColor) : null;
return new SegmentMeanShift<>(search, merge, prune, config.connectRule);
}
use of boofcv.alg.interpolate.InterpolatePixelMB in project BoofCV by lessthanoptimal.
the class TestLocalWeightedHistogramRotRect method computeHistogram.
@Test
public void computeHistogram() {
Planar<GrayF32> image = new Planar<>(GrayF32.class, 40, 50, 3);
InterpolatePixelMB interp = FactoryInterpolation.createPixelPL(FactoryInterpolation.bilinearPixelS(GrayF32.class, BorderType.EXTENDED));
GImageMiscOps.fillUniform(image, rand, 0, 100);
interp.setImage(image);
RectangleRotate_F32 rect = new RectangleRotate_F32(20, 25, 10, 15, 0);
LocalWeightedHistogramRotRect alg = new LocalWeightedHistogramRotRect(10, 3, 12, 3, 255, interp);
alg.computeHistogram(image, rect);
float[] hist = alg.getHistogram().clone();
int[] histIndex = alg.getSampleHistIndex().clone();
// crude sanity check
int numNotZero = 0;
for (int i = 0; i < hist.length; i++) if (hist[i] != 0)
numNotZero++;
assertTrue(numNotZero > 0);
for (int i = 0; i < histIndex.length; i++) assertTrue(histIndex[i] != 0);
// should produce the same answer after a second call
alg.computeHistogram(image, rect);
for (int i = 0; i < hist.length; i++) assertEquals(hist[i], alg.getHistogram()[i], 1e-4);
for (int i = 0; i < histIndex.length; i++) assertEquals(histIndex[i], alg.getSampleHistIndex()[i], 1e-4);
}
use of boofcv.alg.interpolate.InterpolatePixelMB in project BoofCV by lessthanoptimal.
the class TestTrackerMeanShiftComaniciu2003 method track.
@Test
public void track() {
InterpolatePixelS interpSB = FactoryInterpolation.bilinearPixelS(GrayF32.class, BorderType.EXTENDED);
InterpolatePixelMB interpolate = FactoryInterpolation.createPixelPL(interpSB);
LocalWeightedHistogramRotRect calcHistogram = new LocalWeightedHistogramRotRect(30, 3, 10, 3, 255, interpolate);
TrackerMeanShiftComaniciu2003 alg = new TrackerMeanShiftComaniciu2003(false, 100, 1e-8f, 0.0f, 0.0f, 0.1f, calcHistogram);
Planar<GrayF32> image = new Planar<>(GrayF32.class, 100, 150, 3);
// odd width and height so samples land on pixels
render(image, 50, 40, 21, 31);
RectangleRotate_F32 found = new RectangleRotate_F32(50, 40, 21, 31, 0);
alg.initialize(image, found);
// test no change
alg.track(image);
check(alg.getRegion(), 50, 40, 21, 31, 0);
// test translation
render(image, 55, 34, 21, 31);
alg.track(image);
check(alg.getRegion(), 55, 34, 21, 31, 0);
// test scale
render(image, 55, 34, 23, 34);
alg.track(image);
assertEquals(alg.getRegion().cx, 55, 1f);
assertEquals(alg.getRegion().cy, 34, 1f);
assertEquals(alg.getRegion().width, 23, 1);
assertEquals(alg.getRegion().height, 34, 1);
}
use of boofcv.alg.interpolate.InterpolatePixelMB in project BoofCV by lessthanoptimal.
the class TestLocalWeightedHistogramRotRect method computeHistogramBorder_compare.
/**
* When given a region entirely inside, both inside and outside should produce identical solutions
*/
@Test
public void computeHistogramBorder_compare() {
Planar<GrayF32> image = new Planar<>(GrayF32.class, 40, 50, 3);
InterpolatePixelMB interp = FactoryInterpolation.createPixelPL(FactoryInterpolation.bilinearPixelS(GrayF32.class, BorderType.EXTENDED));
GImageMiscOps.fillUniform(image, rand, 0, 100);
interp.setImage(image);
RectangleRotate_F32 rect = new RectangleRotate_F32(20, 25, 10, 15, 0);
LocalWeightedHistogramRotRect alg = new LocalWeightedHistogramRotRect(10, 3, 12, 3, 255, interp);
alg.computeHistogramBorder(image, rect);
int[] insideHistIndex = alg.sampleHistIndex.clone();
float[] insideHist = alg.histogram.clone();
alg = new LocalWeightedHistogramRotRect(10, 3, 12, 3, 255, interp);
alg.computeHistogramInside(rect);
for (int i = 0; i < insideHist.length; i++) {
assertEquals(insideHist[i], alg.histogram[i], 1e-4f);
}
for (int i = 0; i < insideHistIndex.length; i++) {
assertEquals(insideHistIndex[i], alg.sampleHistIndex[i], 1e-4f);
}
}
use of boofcv.alg.interpolate.InterpolatePixelMB in project BoofCV by lessthanoptimal.
the class TestTrackerMeanShiftComaniciu2003 method updateLocation.
@Test
public void updateLocation() {
InterpolatePixelS interpSB = FactoryInterpolation.bilinearPixelS(GrayF32.class, BorderType.EXTENDED);
InterpolatePixelMB interpolate = FactoryInterpolation.createPixelPL(interpSB);
LocalWeightedHistogramRotRect calcHistogram = new LocalWeightedHistogramRotRect(30, 3, 10, 3, 255, interpolate);
TrackerMeanShiftComaniciu2003 alg = new TrackerMeanShiftComaniciu2003(false, 100, 1e-8f, 0.1f, 0.0f, 0.1f, calcHistogram);
Planar<GrayF32> image = new Planar<>(GrayF32.class, 100, 150, 3);
// odd width and height so samples land on pixels
render(image, 50, 40, 21, 31);
RectangleRotate_F32 found = new RectangleRotate_F32(50, 40, 21, 31, 0);
alg.initialize(image, found);
// test no change
alg.updateLocation(image, found);
check(found, 50, 40, 21, 31, 0);
// test translation
render(image, 55, 34, 21, 31);
alg.updateLocation(image, found);
check(found, 55, 34, 21, 31, 0);
}
Aggregations