Search in sources :

Example 36 with ImageBase

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

the class TestBlurStorageFilter method gaussian.

@Test
public void gaussian() {
    for (ImageType c : imageTypes) {
        ImageBase input = c.createImage(width, height);
        ImageBase found = c.createImage(width, height);
        ImageBase expected = c.createImage(width, height);
        ImageBase storage = c.createImage(width, height);
        GImageMiscOps.fillUniform(input, rand, 0, 100);
        BlurStorageFilter alg = new BlurStorageFilter<>("gaussian", c, -1, 2);
        GBlurImageOps.gaussian(input, found, -1, 2, storage);
        alg.process(input, expected);
        BoofTesting.assertEquals(expected, found, 1e-4);
    }
}
Also used : ImageBase(boofcv.struct.image.ImageBase) ImageType(boofcv.struct.image.ImageType) Test(org.junit.Test)

Example 37 with ImageBase

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

the class TestImageStatistics method testMeanDiffAbs.

private void testMeanDiffAbs(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramTypes = m.getParameterTypes();
    ImageBase inputA = GeneralizedImageOps.createImage(paramTypes[0], width, height, numBands);
    ImageBase inputB = GeneralizedImageOps.createImage(paramTypes[1], width, height, numBands);
    int numBands = inputA.getImageType().getNumBands();
    if (inputA.getImageType().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, 0, 20);
    }
    Object result = m.invoke(null, inputA, inputB);
    double total = 0;
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            for (int k = 0; k < numBands; k++) {
                double a = GeneralizedImageOps.get(inputA, j, i, k);
                double b = GeneralizedImageOps.get(inputB, j, i, k);
                total += Math.abs(a - b);
            }
        }
    }
    double expected = total / (width * height * numBands);
    assertEquals(expected, ((Number) result).doubleValue(), 1e-4);
}
Also used : ImageBase(boofcv.struct.image.ImageBase)

Example 38 with ImageBase

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

the class TestImageStatistics method testMax.

private void testMax(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramTypes = m.getParameterTypes();
    ImageBase input = GeneralizedImageOps.createImage(paramTypes[0], width, height, numBands);
    if (input.getImageType().getDataType().isSigned()) {
        GImageMiscOps.fillUniform(input, rand, -20, -5);
        GeneralizedImageOps.setB(input, 0, 3, 0, -2);
        Number o = (Number) m.invoke(null, input);
        assertEquals(-2, o.doubleValue(), 1e-8);
    } else {
        GImageMiscOps.fillUniform(input, rand, 0, 200);
        double maxValue = input.getImageType().getDataType().getMaxValue();
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                double before = GeneralizedImageOps.get(input, x, y, 0);
                GeneralizedImageOps.setB(input, x, y, 0, maxValue);
                Number o = (Number) m.invoke(null, input);
                assertEquals(maxValue, o.doubleValue(), 1e-8);
                GeneralizedImageOps.setB(input, x, y, 0, before);
            }
        }
    }
}
Also used : ImageBase(boofcv.struct.image.ImageBase)

Example 39 with ImageBase

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

the class TestPixelMath method testMinusBounded.

private void testMinusBounded(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramTypes = m.getParameterTypes();
    boolean imageFirst = ImageBase.class.isAssignableFrom(paramTypes[0]);
    int indexImg = imageFirst ? 0 : 1;
    ImageBase input = GeneralizedImageOps.createImage(paramTypes[indexImg], width, height, numBands);
    ImageBase output = GeneralizedImageOps.createImage(paramTypes[indexImg], width, height, numBands);
    int numBands = input.getImageType().getNumBands();
    float val = imageFirst ? 2 : 32;
    float l = 9, u = 15;
    Object scalar, lower, upper;
    if (input.getImageType().getDataType().isInteger()) {
        if (imageFirst) {
            GImageMiscOps.fillUniform(input, rand, 10, 20);
        } else {
            GImageMiscOps.fillUniform(input, rand, 7, 15);
        }
        scalar = (int) val;
        lower = (int) l;
        upper = (int) u;
    } else {
        GImageMiscOps.fillUniform(input, rand, -20, 20);
        scalar = val;
        lower = l;
        upper = u;
    }
    Object[] args = imageFirst ? new Object[] { input, scalar, lower, upper, output } : new Object[] { scalar, input, lower, upper, output };
    m.invoke(null, args);
    GImageMultiBand a = FactoryGImageMultiBand.wrap(input);
    GImageMultiBand b = FactoryGImageMultiBand.wrap(output);
    float tol = input.getImageType().getDataType().isInteger() ? 1 : 1e-4f;
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            a.get(j, i, pixelA);
            b.get(j, i, pixelB);
            for (int k = 0; k < numBands; k++) {
                float expected = imageFirst ? pixelA[k] - val : val - pixelA[k];
                float found = pixelB[k];
                if (expected < l)
                    expected = l;
                if (expected > u)
                    expected = u;
                assertEquals(expected, found, tol);
            }
        }
    }
}
Also used : ImageBase(boofcv.struct.image.ImageBase)

Example 40 with ImageBase

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

the class TestPixelMath method testPlus.

private void testPlus(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramTypes = m.getParameterTypes();
    ImageBase input = GeneralizedImageOps.createImage(paramTypes[0], width, height, numBands);
    ImageBase output = GeneralizedImageOps.createImage(paramTypes[0], width, height, numBands);
    int numBands = input.getImageType().getNumBands();
    if (input.getImageType().getDataType().isSigned()) {
        GImageMiscOps.fillUniform(input, rand, -20, 20);
    } else {
        GImageMiscOps.fillUniform(input, rand, 0, 20);
    }
    if (input.getImageType().getDataType().isInteger())
        m.invoke(null, input, 2, output);
    else
        m.invoke(null, input, 2.0f, output);
    GImageMultiBand a = FactoryGImageMultiBand.wrap(input);
    GImageMultiBand b = FactoryGImageMultiBand.wrap(output);
    float tol = input.getImageType().getDataType().isInteger() ? 1 : 1e-4f;
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            a.get(j, i, pixelA);
            b.get(j, i, pixelB);
            for (int k = 0; k < numBands; k++) {
                assertEquals(pixelA[k] + 2, pixelB[k], tol);
            }
        }
    }
}
Also used : ImageBase(boofcv.struct.image.ImageBase)

Aggregations

ImageBase (boofcv.struct.image.ImageBase)54 ImageType (boofcv.struct.image.ImageType)14 Test (org.junit.Test)13 Se3_F64 (georegression.struct.se.Se3_F64)5 BufferedImage (java.awt.image.BufferedImage)5 SimpleImageSequence (boofcv.io.image.SimpleImageSequence)4 GrayU8 (boofcv.struct.image.GrayU8)4 MediaManager (boofcv.io.MediaManager)3 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)3 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)3 KernelBase (boofcv.struct.convolve.KernelBase)3 Point2D_F64 (georegression.struct.point.Point2D_F64)3 ConfigBackgroundBasic (boofcv.factory.background.ConfigBackgroundBasic)2 ConfigBackgroundGmm (boofcv.factory.background.ConfigBackgroundGmm)2 ImageGridPanel (boofcv.gui.image.ImageGridPanel)2 ImagePanel (boofcv.gui.image.ImagePanel)2 GrayF32 (boofcv.struct.image.GrayF32)2 Planar (boofcv.struct.image.Planar)2 File (java.io.File)2 FDistort (boofcv.abst.distort.FDistort)1