Search in sources :

Example 11 with GImageGray

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

the class TestImplIntegralImageOps method convolveSparse.

public void convolveSparse(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramType = m.getParameterTypes();
    Class inputType = paramType[0];
    ImageGray integral = GeneralizedImageOps.createSingleBand(inputType, width, height);
    GImageMiscOps.fillUniform(integral, rand, 0, 1000);
    ImageGray expected = GeneralizedImageOps.createSingleBand(inputType, width, height);
    IntegralKernel kernel = new IntegralKernel(2);
    kernel.blocks[0] = new ImageRectangle(-2, -2, 1, 1);
    kernel.blocks[1] = new ImageRectangle(-2, -1, 1, 0);
    kernel.scales = new int[] { 1, 2 };
    GIntegralImageOps.convolve(integral, kernel, expected);
    GImageGray e = FactoryGImageGray.wrap(expected);
    double found0 = ((Number) m.invoke(null, integral, kernel, 0, 0)).doubleValue();
    double found1 = ((Number) m.invoke(null, integral, kernel, 10, 12)).doubleValue();
    double found2 = ((Number) m.invoke(null, integral, kernel, 19, 29)).doubleValue();
    assertEquals(e.get(0, 0).doubleValue(), found0, 1e-4f);
    assertEquals(e.get(10, 12).doubleValue(), found1, 1e-4f);
    assertEquals(e.get(19, 29).doubleValue(), found2, 1e-4f);
}
Also used : IntegralKernel(boofcv.alg.transform.ii.IntegralKernel) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageRectangle(boofcv.struct.ImageRectangle) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray)

Example 12 with GImageGray

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

the class TestImplIntegralImageOps method checkTransformResults.

public void checkTransformResults(Method m, ImageGray a, ImageGray b) throws InvocationTargetException, IllegalAccessException {
    m.invoke(null, a, b);
    GImageGray aa = FactoryGImageGray.wrap(a);
    GImageGray bb = FactoryGImageGray.wrap(b);
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            double total = 0;
            for (int i = 0; i <= y; i++) {
                for (int j = 0; j <= x; j++) {
                    total += aa.get(j, i).doubleValue();
                }
            }
            Assert.assertEquals(x + " " + y, total, bb.get(x, y).doubleValue(), 1e-1);
        }
    }
}
Also used : GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray)

Example 13 with GImageGray

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

the class GeneralBilinearPixelSingleChecks method compute.

@Override
protected float compute(T _img, float x, float y) {
    ImageBorder<?> imgB = FactoryImageBorder.wrap(BorderType.EXTENDED, _img);
    GImageGray img = FactoryGImageGray.wrap(imgB);
    int gX = (int) x;
    int gY = (int) y;
    float v0 = img.get(gX, gY).floatValue();
    float v1 = img.get(gX + 1, gY).floatValue();
    float v2 = img.get(gX, gY + 1).floatValue();
    float v3 = img.get(gX + 1, gY + 1).floatValue();
    x %= 1f;
    y %= 1f;
    float a = 1f - x;
    float b = 1f - y;
    return a * b * v0 + x * b * v1 + a * y * v2 + x * y * v3;
}
Also used : FactoryGImageGray(boofcv.core.image.FactoryGImageGray) GImageGray(boofcv.core.image.GImageGray)

Example 14 with GImageGray

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

the class TestImplConvertBitmap method checkGrayToArray.

public void checkGrayToArray(Method m, Bitmap.Config config) {
    Bitmap dst = Bitmap.createBitmap(w, h, config);
    Class[] params = m.getParameterTypes();
    try {
        ImageGray src = (ImageGray) params[0].getConstructor(int.class, int.class).newInstance(w, h);
        GeneralizedImageOps.set(src, 1, 2, 16);
        GeneralizedImageOps.set(src, 1, 3, 0xFF);
        Object array;
        String info = params[0].getSimpleName();
        if (params[2] == int[].class) {
            info += " Array32";
            array = buffer32;
        } else {
            info += " Array8";
            array = buffer8;
        }
        info += " " + config;
        m.invoke(null, src, array, config);
        if (params[2] == int[].class) {
            dst.copyPixelsFromBuffer(IntBuffer.wrap(buffer32));
        } else {
            dst.copyPixelsFromBuffer(ByteBuffer.wrap(buffer8));
        }
        GImageGray g = FactoryGImageGray.wrap(src);
        if (config == Bitmap.Config.ARGB_8888) {
            assertEquals(info, 0xFF101010, (int) dst.getPixel(1, 2));
            assertEquals(info, 0xFFFFFFFF, (int) dst.getPixel(1, 3));
        } else {
            assertEquals(info, expected565(16, 16, 16), (int) dst.getPixel(1, 2));
            assertEquals(info, expected565(255, 255, 255), (int) dst.getPixel(1, 3));
        }
        assertEquals(info, 0xFF000000, dst.getPixel(0, 0));
    } 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 15 with GImageGray

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

the class TestConvolveJustBorder_General_SB method compareResults.

@Override
protected void compareResults(Object targetResult, Object[] targetParam, Object validationResult, Object[] validationParam) {
    ImageGray targetOut = (ImageGray) targetParam[2];
    ImageGray validationOut = (ImageGray) validationParam[2];
    // remove the border
    computeBorder((KernelBase) targetParam[0], methodTest.getName());
    validationOut = (ImageGray) stripBorder(validationOut, borderX0, borderY0, borderX1, borderY1);
    GImageGray t = FactoryGImageGray.wrap(targetOut);
    GImageGray v = FactoryGImageGray.wrap(validationOut);
    for (int y = 0; y < targetOut.height; y++) {
        if (y >= borderX0 && y < targetOut.height - borderX1)
            continue;
        for (int x = 0; x < targetOut.width; x++) {
            if (x >= borderX0 && x < targetOut.width - borderY1)
                continue;
            assertEquals(x + " " + y, v.get(x, y).doubleValue(), t.get(x, y).doubleValue(), 1e-4f);
        }
    }
}
Also used : 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