Search in sources :

Example 26 with GImageGray

use of boofcv.core.image.GImageGray in project BoofCV by lessthanoptimal.

the class TestImageMiscOps method testAddGaussian_Single.

private void testAddGaussian_Single(Method m) throws InvocationTargetException, IllegalAccessException {
    double mean = 10;
    Class[] paramTypes = m.getParameterTypes();
    ImageGray orig = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
    GImageMiscOps.fill(orig, mean);
    m.invoke(null, orig, rand, 2.0, 0, 255);
    double stdev2 = 0;
    GImageGray a = FactoryGImageGray.wrap(orig);
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            double value = a.get(j, i).doubleValue();
            stdev2 += (value - mean) * (value - mean);
        }
    }
    GImageMiscOps.fill(orig, mean);
    m.invoke(null, orig, rand, 10.0, 0, 255);
    double stdev10 = 0;
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            double value = a.get(j, i).doubleValue();
            stdev10 += (value - mean) * (value - mean);
        }
    }
    // see if the gaussian with the larger variance creates a noisier image
    assertTrue(stdev2 < stdev10);
}
Also used : FactoryGImageGray(boofcv.core.image.FactoryGImageGray) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray) GImageGray(boofcv.core.image.GImageGray)

Example 27 with GImageGray

use of boofcv.core.image.GImageGray in project BoofCV by lessthanoptimal.

the class TestImageMiscOps method testFillGaussian_Single.

private void testFillGaussian_Single(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramTypes = m.getParameterTypes();
    ImageGray orig = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
    if (orig.getDataType().isSigned())
        m.invoke(null, orig, rand, 0, 5, -2, 2);
    else {
        m.invoke(null, orig, rand, 5, 7, 0, 12);
    }
    int numZero = 0;
    GImageGray a = FactoryGImageGray.wrap(orig);
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            double value = a.get(j, i).doubleValue();
            if (orig.getDataType().isSigned()) {
                assertTrue("value = " + value, value >= -2 && value <= 2);
            } else {
                assertTrue("value = " + value, value >= 0 && value <= 12);
            }
            if (value == 0)
                numZero++;
        }
    }
    assertTrue(numZero < width * height);
}
Also used : FactoryGImageGray(boofcv.core.image.FactoryGImageGray) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray) GImageGray(boofcv.core.image.GImageGray)

Example 28 with GImageGray

use of boofcv.core.image.GImageGray in project BoofCV by lessthanoptimal.

the class TestImageMiscOps method testAddUniform_Single.

private void testAddUniform_Single(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramTypes = m.getParameterTypes();
    ImageGray orig = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
    GImageMiscOps.fill(orig, 1);
    if (orig.getDataType().isInteger()) {
        m.invoke(null, orig, rand, 1, 10);
    } else {
        m.invoke(null, orig, rand, 1, 10);
    }
    GImageGray a = FactoryGImageGray.wrap(orig);
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            double value = a.get(j, i).doubleValue();
            assertTrue(value >= -2 && value <= 11);
        }
    }
}
Also used : FactoryGImageGray(boofcv.core.image.FactoryGImageGray) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray) GImageGray(boofcv.core.image.GImageGray)

Example 29 with GImageGray

use of boofcv.core.image.GImageGray in project BoofCV by lessthanoptimal.

the class TestImplConvertBitmap method checkArrayToGray.

public void checkArrayToGray(Method m, Bitmap.Config config) {
    Bitmap orig = Bitmap.createBitmap(w, h, config);
    orig.setPixel(1, 2, 0xFF204010);
    Class[] params = m.getParameterTypes();
    try {
        ImageGray found = (ImageGray) params[2].getConstructor(int.class, int.class).newInstance(w, h);
        Object array;
        String info = params[2].getSimpleName();
        if (params[0] == int[].class) {
            info += " Array32";
            orig.copyPixelsToBuffer(IntBuffer.wrap(buffer32));
            array = buffer32;
        } else {
            info += " Array8";
            orig.copyPixelsToBuffer(ByteBuffer.wrap(buffer8));
            array = buffer8;
        }
        info += " " + config;
        m.invoke(null, array, config, found);
        GImageGray g = FactoryGImageGray.wrap(found);
        // should be 37 for both 8888 and 565
        assertEquals(info, 37, g.get(1, 2).intValue());
        assertEquals(info, 0, g.get(0, 0).intValue());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Bitmap(android.graphics.Bitmap) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray)

Example 30 with GImageGray

use of boofcv.core.image.GImageGray in project BoofCV by lessthanoptimal.

the class TestImplConvertBitmap method checkBitmapToGrayRGB.

public void checkBitmapToGrayRGB(Method m, Bitmap.Config config) {
    Bitmap orig = Bitmap.createBitmap(w, h, config);
    orig.setPixel(1, 2, 0xFF204010);
    Class[] params = m.getParameterTypes();
    String info = config + " " + params[1].getSimpleName();
    try {
        ImageGray found = (ImageGray) params[1].getConstructor(int.class, int.class).newInstance(w, h);
        m.invoke(null, orig, found);
        GImageGray g = FactoryGImageGray.wrap(found);
        // should be 37 for both 8888 and 565
        assertEquals(info, 37, g.get(1, 2).intValue());
        assertEquals(info, 0, g.get(0, 0).intValue());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Bitmap(android.graphics.Bitmap) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray)

Aggregations

FactoryGImageGray (boofcv.core.image.FactoryGImageGray)35 GImageGray (boofcv.core.image.GImageGray)35 ImageGray (boofcv.struct.image.ImageGray)17 Test (org.junit.Test)5 Bitmap (android.graphics.Bitmap)3 TupleDesc_B (boofcv.struct.feature.TupleDesc_B)2 Point2D_I32 (georegression.struct.point.Point2D_I32)2 IntegralKernel (boofcv.alg.transform.ii.IntegralKernel)1 ImageRectangle (boofcv.struct.ImageRectangle)1 GrayF32 (boofcv.struct.image.GrayF32)1 GrayU8 (boofcv.struct.image.GrayU8)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1