Search in sources :

Example 1 with InterpolatePixelS

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);
}
Also used : InterpolatePixelS(boofcv.alg.interpolate.InterpolatePixelS) InterpolatePixelMB(boofcv.alg.interpolate.InterpolatePixelMB)

Example 2 with InterpolatePixelS

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);
}
Also used : InterpolatePixelS(boofcv.alg.interpolate.InterpolatePixelS) Affine2D_F32(georegression.struct.affine.Affine2D_F32) GrayU8(boofcv.struct.image.GrayU8) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) Test(org.junit.Test)

Example 3 with InterpolatePixelS

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;
}
Also used : InterpolatePixelS(boofcv.alg.interpolate.InterpolatePixelS)

Example 4 with InterpolatePixelS

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);
}
Also used : InterpolatePixelS(boofcv.alg.interpolate.InterpolatePixelS)

Example 5 with InterpolatePixelS

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);
}
Also used : InterpolatePixelS(boofcv.alg.interpolate.InterpolatePixelS) GrayF32(boofcv.struct.image.GrayF32) RectangleRotate_F32(boofcv.struct.RectangleRotate_F32) InterpolatePixelMB(boofcv.alg.interpolate.InterpolatePixelMB) Planar(boofcv.struct.image.Planar) Test(org.junit.Test)

Aggregations

InterpolatePixelS (boofcv.alg.interpolate.InterpolatePixelS)10 Test (org.junit.Test)5 InterpolatePixelMB (boofcv.alg.interpolate.InterpolatePixelMB)3 GrayF32 (boofcv.struct.image.GrayF32)3 RectangleRotate_F32 (boofcv.struct.RectangleRotate_F32)2 Point2Transform2_F32 (boofcv.struct.distort.Point2Transform2_F32)2 GrayU8 (boofcv.struct.image.GrayU8)2 Planar (boofcv.struct.image.Planar)2 ImageDistort (boofcv.alg.distort.ImageDistort)1 PixelTransformAffine_F32 (boofcv.alg.distort.PixelTransformAffine_F32)1 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)1 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)1 SequencePoint2Transform2_F32 (boofcv.struct.distort.SequencePoint2Transform2_F32)1 ImageDataType (boofcv.struct.image.ImageDataType)1 ImageGray (boofcv.struct.image.ImageGray)1 Affine2D_F32 (georegression.struct.affine.Affine2D_F32)1 Affine2D_F64 (georegression.struct.affine.Affine2D_F64)1 Point2D_F64 (georegression.struct.point.Point2D_F64)1