Search in sources :

Example 21 with Planar

use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.

the class TestGradientReduceToSingle method maxf_plfu8_u8.

@Test
public void maxf_plfu8_u8() {
    Planar<GrayU8> inX = new Planar<>(GrayU8.class, width, height, numbands);
    Planar<GrayU8> inY = new Planar<>(GrayU8.class, width, height, numbands);
    GrayU8 outX = new GrayU8(width, height);
    GrayU8 outY = new GrayU8(width, height);
    GImageMiscOps.fillUniform(inX, rand, 0, 100);
    GImageMiscOps.fillUniform(inY, rand, 0, 100);
    GradientReduceToSingle.maxf(inX, inY, outX, outY);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            int maxNorm = 0;
            int maxValueX = -Integer.MAX_VALUE;
            int maxValueY = -Integer.MAX_VALUE;
            for (int i = 0; i < numbands; i++) {
                int dx = inX.getBand(i).get(x, y);
                int dy = inY.getBand(i).get(x, y);
                int r = dx * dx + dy * dy;
                if (r > maxNorm) {
                    maxNorm = r;
                    maxValueX = dx;
                    maxValueY = dy;
                }
            }
            assertEquals(maxValueX, outX.get(x, y), 1e-4f);
            assertEquals(maxValueY, outY.get(x, y), 1e-4f);
        }
    }
}
Also used : Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 22 with Planar

use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.

the class TestLikelihoodHistCoupled_PL_U8 method singleColor.

@Test
public void singleColor() {
    LikelihoodHistCoupled_PL_U8 alg = new LikelihoodHistCoupled_PL_U8(255, 11);
    Planar<GrayU8> image = new Planar<>(GrayU8.class, 30, 40, 3);
    RectangleLength2D_I32 r = new RectangleLength2D_I32(3, 4, 12, 8);
    setColor(image, r, 100, 105, 12);
    alg.setImage(image);
    alg.createModel(r);
    assertEquals(1.0f, alg.compute(3, 4), 1e-4);
    assertEquals(1.0f, alg.compute(14, 11), 1e-4);
    assertEquals(0, alg.compute(10, 30), 1e-4);
}
Also used : RectangleLength2D_I32(georegression.struct.shapes.RectangleLength2D_I32) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 23 with Planar

use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.

the class TestLikelihoodHistCoupled_PL_U8 method multipleColors.

@Test
public void multipleColors() {
    LikelihoodHistCoupled_PL_U8 alg = new LikelihoodHistCoupled_PL_U8(255, 11);
    Planar<GrayU8> image = new Planar<>(GrayU8.class, 30, 40, 3);
    RectangleLength2D_I32 r0 = new RectangleLength2D_I32(3, 4, 8, 8);
    RectangleLength2D_I32 r1 = new RectangleLength2D_I32(11, 4, 4, 8);
    setColor(image, r0, 100, 105, 12);
    setColor(image, r1, 50, 200, 50);
    RectangleLength2D_I32 region = new RectangleLength2D_I32(3, 4, 12, 8);
    alg.setImage(image);
    alg.createModel(region);
    float v0 = alg.compute(3, 4);
    float v1 = alg.compute(11, 4);
    assertEquals(1.0f, v0 + v1, 1e-4);
    assertTrue(v0 > v1);
}
Also used : RectangleLength2D_I32(georegression.struct.shapes.RectangleLength2D_I32) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 24 with Planar

use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.

the class TestLikelihoodHueSatHistCoupled_PL_U8 method convertToHueSat.

@Test
public void convertToHueSat() {
    LikelihoodHueSatHistCoupled_PL_U8 alg = new LikelihoodHueSatHistCoupled_PL_U8(255, 30);
    Planar<GrayU8> image = new Planar<>(GrayU8.class, 30, 40, 3);
    setColor(image, 5, 6, 120, 50, 255);
    alg.setImage(image);
    alg.createModel(new RectangleLength2D_I32(5, 6, 1, 1));
    float[] hsv = new float[3];
    ColorHsv.rgbToHsv(120, 50, 255, hsv);
    int indexH = (int) (hsv[0] / alg.sizeH);
    int indexS = (int) (hsv[1] / alg.sizeS);
    int index = indexH * 30 + indexS;
    assertEquals(1.0, alg.bins[index], 1e-4);
}
Also used : RectangleLength2D_I32(georegression.struct.shapes.RectangleLength2D_I32) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 25 with Planar

use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.

the class TestLikelihoodHueSatHistCoupled_PL_U8 method numBins.

@Test
public void numBins() {
    LikelihoodHueSatHistCoupled_PL_U8 alg = new LikelihoodHueSatHistCoupled_PL_U8(255, 30);
    Planar<GrayU8> image = new Planar<>(GrayU8.class, 30, 40, 3);
    // make sure the upper limit is handled correctly
    setColor(image, 5, 6, 255, 255, 255);
    alg.setImage(image);
    alg.createModel(new RectangleLength2D_I32(5, 6, 1, 1));
    assertEquals(30, alg.numHistogramBins);
    assertEquals(30 * 30, alg.bins.length);
    // it comes out to a slightly larger size on purpose
    assertEquals(2 * Math.PI, alg.sizeH * 30, 0.01);
    assertEquals(1.0, alg.sizeS * 30, 0.01);
}
Also used : RectangleLength2D_I32(georegression.struct.shapes.RectangleLength2D_I32) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Aggregations

Planar (boofcv.struct.image.Planar)73 Test (org.junit.Test)39 GrayF32 (boofcv.struct.image.GrayF32)34 GrayU8 (boofcv.struct.image.GrayU8)28 BufferedImage (java.awt.image.BufferedImage)21 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)20 RectangleLength2D_I32 (georegression.struct.shapes.RectangleLength2D_I32)12 File (java.io.File)9 Bitmap (android.graphics.Bitmap)4 ListDisplayPanel (boofcv.gui.ListDisplayPanel)4 ImageGray (boofcv.struct.image.ImageGray)4 ConfigGeneralDetector (boofcv.abst.feature.detect.interest.ConfigGeneralDetector)3 LensDistortionUniversalOmni (boofcv.alg.distort.universal.LensDistortionUniversalOmni)3 MediaManager (boofcv.io.MediaManager)3 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)3 CameraPinhole (boofcv.struct.calib.CameraPinhole)3 GrayU16 (boofcv.struct.image.GrayU16)3 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)3 Se3_F64 (georegression.struct.se.Se3_F64)3 DescribeRegionPoint (boofcv.abst.feature.describe.DescribeRegionPoint)2