Search in sources :

Example 71 with ImageGray

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

the class TestImageStatistics method testVariance.

private void testVariance(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramTypes = m.getParameterTypes();
    ImageGray inputA = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
    if (inputA.getDataType().isSigned()) {
        GImageMiscOps.fillUniform(inputA, rand, -20, 20);
    } else {
        GImageMiscOps.fillUniform(inputA, rand, 0, 20);
    }
    double mean = 2.5;
    Object result = paramTypes[1] == double.class ? m.invoke(null, inputA, mean) : m.invoke(null, inputA, (float) mean);
    double total = 0;
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            double d = GeneralizedImageOps.get(inputA, j, i) - mean;
            total += d * d;
        }
    }
    double var = total / (width * height);
    assertEquals(var, ((Number) result).doubleValue(), 1e-4);
}
Also used : ImageGray(boofcv.struct.image.ImageGray)

Example 72 with ImageGray

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

the class TestPixelMath method testBound.

private void testBound(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramTypes = m.getParameterTypes();
    ImageGray input = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
    double max = 100;
    double min = -100;
    GImageMiscOps.fillUniform(input, rand, (int) min, (int) max);
    if (input.getDataType().isInteger()) {
        m.invoke(null, input, 2, 10);
    } else
        m.invoke(null, input, 2.0f, 10.0f);
    GImageGray a = FactoryGImageGray.wrap(input);
    if (input.getDataType().isInteger()) {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                int v = a.get(j, i).intValue();
                assertTrue(v >= 2 && v <= 10);
            }
        }
    } else {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                float v = a.get(j, i).floatValue();
                assertTrue(v >= 2f && v <= 10f);
            }
        }
    }
}
Also used : ImageGray(boofcv.struct.image.ImageGray)

Example 73 with ImageGray

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

the class TestPixelMath method testPow2.

private void testPow2(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramTypes = m.getParameterTypes();
    ImageGray inputA = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
    ImageGray inputB = GeneralizedImageOps.createSingleBand(paramTypes[1], width, height);
    GImageMiscOps.fillUniform(inputA, rand, -20, 20);
    GImageMiscOps.fillUniform(inputB, rand, -20, 20);
    m.invoke(null, inputA, inputB);
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            double a = GeneralizedImageOps.get(inputA, j, i);
            double b = GeneralizedImageOps.get(inputB, j, i);
            assertEquals(a * a, b, 1e-4);
        }
    }
}
Also used : ImageGray(boofcv.struct.image.ImageGray)

Example 74 with ImageGray

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

the class TestPixelMath method testMultiplyPixel.

private void testMultiplyPixel(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramTypes = m.getParameterTypes();
    ImageGray inputA = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
    ImageGray inputB = GeneralizedImageOps.createSingleBand(paramTypes[1], width, height);
    ImageGray output = GeneralizedImageOps.createSingleBand(paramTypes[2], width, height);
    GImageMiscOps.fillUniform(inputA, rand, -20, 20);
    GImageMiscOps.fillUniform(inputB, rand, -20, 20);
    m.invoke(null, inputA, inputB, output);
    GImageGray a = FactoryGImageGray.wrap(inputA);
    GImageGray b = FactoryGImageGray.wrap(inputB);
    GImageGray o = FactoryGImageGray.wrap(output);
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            assertEquals(a.get(j, i).doubleValue() * b.get(j, i).doubleValue(), o.get(j, i).doubleValue(), 1e-4);
        }
    }
}
Also used : ImageGray(boofcv.struct.image.ImageGray)

Example 75 with ImageGray

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

the class TestPixelMath method testAdd.

private void testAdd(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramTypes = m.getParameterTypes();
    ImageGray inputA = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
    ImageGray inputB = GeneralizedImageOps.createSingleBand(paramTypes[1], width, height);
    ImageGray inputC = GeneralizedImageOps.createSingleBand(paramTypes[2], width, height);
    if (inputA.getDataType().isSigned()) {
        GImageMiscOps.fillUniform(inputA, rand, -20, 20);
        GImageMiscOps.fillUniform(inputB, rand, -20, 20);
    } else {
        GImageMiscOps.fillUniform(inputA, rand, 0, 20);
        GImageMiscOps.fillUniform(inputB, rand, -20, 20);
    }
    m.invoke(null, inputA, inputB, inputC);
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            double a = GeneralizedImageOps.get(inputA, j, i);
            double b = GeneralizedImageOps.get(inputB, j, i);
            double c = GeneralizedImageOps.get(inputC, j, i);
            assertEquals(a + b, c, 1e-4);
        }
    }
}
Also used : ImageGray(boofcv.struct.image.ImageGray)

Aggregations

ImageGray (boofcv.struct.image.ImageGray)110 FactoryGImageGray (boofcv.core.image.FactoryGImageGray)43 GImageGray (boofcv.core.image.GImageGray)43 Test (org.junit.Test)26 GrayF32 (boofcv.struct.image.GrayF32)20 Method (java.lang.reflect.Method)17 GrayU8 (boofcv.struct.image.GrayU8)15 Bitmap (android.graphics.Bitmap)4 ImageBorder_S32 (boofcv.core.image.border.ImageBorder_S32)4 GrayS16 (boofcv.struct.image.GrayS16)4 GrayS32 (boofcv.struct.image.GrayS32)4 Planar (boofcv.struct.image.Planar)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 IntegralKernel (boofcv.alg.transform.ii.IntegralKernel)3 ImageRectangle (boofcv.struct.ImageRectangle)3 FDistort (boofcv.abst.distort.FDistort)2 ImageBorder_F32 (boofcv.core.image.border.ImageBorder_F32)2 FactoryDescribeImageDense (boofcv.factory.feature.dense.FactoryDescribeImageDense)2 Kernel2D_S32 (boofcv.struct.convolve.Kernel2D_S32)2 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)2