use of boofcv.alg.interpolate.InterpolatePixelS 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.InterpolatePixelS in project BoofCV by lessthanoptimal.
the class TestImplPolynomialPixel_I method compareToBilinear.
/**
* Polynomial interpolation of order one is bilinear interpolation
*/
@Test
public void compareToBilinear() {
GrayU8 img = new GrayU8(width, height);
GrayU8 expected = new GrayU8(width, height);
GrayU8 found = new GrayU8(width, height);
GImageMiscOps.fillUniform(img, rand, 0, 255);
Affine2D_F32 tran = new Affine2D_F32(1, 0, 0, 1, 0.25f, 0.25f);
// set it up so that it will be equivalent to bilinear interpolation
InterpolatePixelS<GrayU8> alg = (InterpolatePixelS) new ImplPolynomialPixel_I(2, 0, 255);
alg.setBorder(FactoryImageBorder.singleValue(GrayU8.class, 0));
ImageDistort<GrayU8, GrayU8> distorter = FactoryDistort.distortSB(false, alg, GrayU8.class);
distorter.setModel(new PixelTransformAffine_F32(tran));
distorter.apply(img, found);
InterpolatePixelS<GrayU8> bilinear = FactoryInterpolation.bilinearPixelS(GrayU8.class, BorderType.ZERO);
distorter = FactoryDistort.distortSB(false, bilinear, GrayU8.class);
distorter.setModel(new PixelTransformAffine_F32(tran));
distorter.apply(img, expected);
BoofTesting.assertEquals(expected, found, 0);
}
use of boofcv.alg.interpolate.InterpolatePixelS in project BoofCV by lessthanoptimal.
the class TestImplPolynomialPixel_I method wrap.
@Override
protected InterpolatePixelS<GrayU8> wrap(GrayU8 image, int minValue, int maxValue) {
InterpolatePixelS ret = new ImplPolynomialPixel_I(DOF, minValue, maxValue);
ret.setImage(image);
return ret;
}
use of boofcv.alg.interpolate.InterpolatePixelS in project BoofCV by lessthanoptimal.
the class TestImplPolynomialPixel_I method compute.
@Override
protected float compute(GrayU8 img, float x, float y) {
// yes by using the same algorithm for this compute several unit tests are being defeated
// polynomial interpolation is more complex and a simple compute alg here is not possible
InterpolatePixelS a = new ImplPolynomialPixel_I(DOF, 0, 255);
a.setImage(img);
return a.get(x, y);
}
use of boofcv.alg.interpolate.InterpolatePixelS 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);
}
Aggregations