Search in sources :

Example 86 with ImageGray

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

the class TestImplConvolveMean method compareResults.

@Override
protected void compareResults(Object targetResult, Object[] targetParam, Object validationResult, Object[] validationParam) {
    ImageGray expected = (ImageGray) validationParam[2];
    ImageGray found = (ImageGray) targetParam[1];
    BoofTesting.assertEquals(expected, found, 1e-4);
}
Also used : ImageGray(boofcv.struct.image.ImageGray)

Example 87 with ImageGray

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

the class CompareDerivativeToConvolution method innerCompare.

protected void innerCompare(ImageGray inputImage, ImageGray... outputImages) {
    Class<?>[] param = m.getParameterTypes();
    int numImageOutputs = countImageOutputs(param);
    if (outputImages.length != numImageOutputs)
        throw new RuntimeException("Unexpected number of outputImages passed in");
    // declare and compute the validation results
    ImageGray[] expectedOutput = new ImageGray[param.length - 2];
    for (int i = 0; i < expectedOutput.length; i++) {
        expectedOutput[i] = (ImageGray) outputImages[i].createNew(inputImage.width, inputImage.height);
        outputFilters[i].process(inputImage, expectedOutput[i]);
    }
    // compute results from the test function
    Object[] testInputs = new Object[param.length];
    testInputs[0] = inputImage;
    for (int i = 1; i < numImageOutputs + 1; i++) {
        testInputs[i] = outputImages[i - 1];
    }
    if (param.length == numImageOutputs + 2) {
        if (processBorder) {
            testInputs[param.length - 1] = FactoryImageBorder.single(inputImage.getClass(), BorderType.EXTENDED);
        } else {
            testInputs[param.length - 1] = null;
        }
    }
    try {
        m.invoke(null, testInputs);
    } catch (IllegalAccessException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
    // assume the most extreme border is used
    int borderX0 = 0, borderY0 = 0, borderX1 = 0, borderY1 = 0;
    for (int i = 0; i < expectedOutput.length; i++) {
        Border b = borders[i];
        borderX0 = Math.max(borderX0, b.borderX0);
        borderX1 = Math.max(borderX1, b.borderX1);
        borderY0 = Math.max(borderY0, b.borderY0);
        borderY1 = Math.max(borderY1, b.borderY1);
    }
    // compare the results
    for (int i = 0; i < expectedOutput.length; i++) {
        BoofTesting.assertEqualsInner(expectedOutput[i], outputImages[i], 1e-4f, borderX0, borderY0, borderX1, borderY1, false);
        if (!processBorder)
            BoofTesting.checkBorderZero(outputImages[i], borderX0, borderY0, borderX1, borderY1);
    }
}
Also used : ImageGray(boofcv.struct.image.ImageGray) FactoryImageBorder(boofcv.core.image.border.FactoryImageBorder) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 88 with ImageGray

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

the class StandardGradientChecks method testSecondDerivative.

/**
 * The XY and YX second derivatives should be indential
 */
private void testSecondDerivative(Method m1, Method m2) {
    Class[] params = m1.getParameterTypes();
    ImageGray input = GeneralizedImageOps.createSingleBand(params[0], width, height);
    ImageGray derivX = GeneralizedImageOps.createSingleBand(params[1], width, height);
    ImageGray derivY = GeneralizedImageOps.createSingleBand(params[2], width, height);
    ImageGray derivXX = GeneralizedImageOps.createSingleBand(params[1], width, height);
    ImageGray derivYY = GeneralizedImageOps.createSingleBand(params[2], width, height);
    ImageGray derivXY = GeneralizedImageOps.createSingleBand(params[1], width, height);
    ImageGray derivYX = GeneralizedImageOps.createSingleBand(params[1], width, height);
    GImageMiscOps.fillUniform(input, rand, 0, 40);
    Object border;
    if (params[3] == ImageBorder_F32.class) {
        border = new ImageBorder1D_F32(BorderIndex1D_Wrap.class);
    } else {
        border = new ImageBorder1D_S32(BorderIndex1D_Wrap.class);
    }
    try {
        m1.invoke(null, input, derivX, derivY, border);
        m2.invoke(null, derivX, derivXX, derivXY, border);
        m2.invoke(null, derivY, derivYX, derivYY, border);
    } catch (IllegalAccessException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
    // BoofTesting.printDiff(derivXY,derivYX);
    BoofTesting.assertEquals(derivXY, derivYX, 1e-3f);
}
Also used : BorderIndex1D_Wrap(boofcv.core.image.border.BorderIndex1D_Wrap) ImageBorder1D_F32(boofcv.core.image.border.ImageBorder1D_F32) ImageGray(boofcv.struct.image.ImageGray) ImageBorder1D_S32(boofcv.core.image.border.ImageBorder1D_S32) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 89 with ImageGray

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

the class TestImplAverageDownSample method vertical_1_to_1.

@Test
public void vertical_1_to_1() throws InvocationTargetException, IllegalAccessException {
    List<Method> methods = find("vertical");
    for (Method m : methods) {
        Class typeSrc = m.getParameterTypes()[0];
        Class typeDst = m.getParameterTypes()[1];
        ImageGray src = GeneralizedImageOps.createSingleBand(typeSrc, 3, 6);
        ImageGray dst = GeneralizedImageOps.createSingleBand(typeDst, 3, 6);
        fillVertical(src);
        m.invoke(null, src, dst);
        for (int y = 0; y < src.height; y++) {
            for (int x = 0; x < src.width; x++) {
                assertEquals(y, GeneralizedImageOps.get(dst, x, y), 1e-4);
            }
        }
    }
    assertEquals(4, methods.size());
}
Also used : ImageGray(boofcv.struct.image.ImageGray) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 90 with ImageGray

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

the class TestImplAverageDownSample method vertical_2_to_1.

@Test
public void vertical_2_to_1() throws InvocationTargetException, IllegalAccessException {
    List<Method> methods = find("vertical");
    for (Method m : methods) {
        Class typeSrc = m.getParameterTypes()[0];
        Class typeDst = m.getParameterTypes()[1];
        // System.out.println(typeSrc+"   "+typeDst);
        ImageGray src = GeneralizedImageOps.createSingleBand(typeSrc, 3, 6);
        ImageGray dst = GeneralizedImageOps.createSingleBand(typeDst, 3, 3);
        fillVertical(src);
        m.invoke(null, src, dst);
        double[] expected;
        if (dst.getDataType().isInteger()) {
            expected = new double[] { 1, 3, 5 };
        } else {
            expected = new double[] { 0.5, 2.5, 4.5 };
        }
        for (int x = 0; x < src.width; x++) {
            for (int y = 0; y < dst.height; y++) {
                assertEquals(expected[y], GeneralizedImageOps.get(dst, x, y), 1e-4);
            }
        }
    }
    assertEquals(4, methods.size());
}
Also used : ImageGray(boofcv.struct.image.ImageGray) Method(java.lang.reflect.Method) Test(org.junit.Test)

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