Search in sources :

Example 1 with GrowArray

use of pabeles.concurrency.GrowArray in project BoofCV by lessthanoptimal.

the class TestEnhanceImageOps method equalizeLocal.

public void equalizeLocal(GrayI input, GrayI found) {
    GrayI expected = (GrayI) GeneralizedImageOps.createSingleBand(input.getClass(), input.width, input.height);
    GImageMiscOps.fillUniform(input, rand, 0, 9);
    GrowArray<DogArray_I32> workArrays = new GrowArray<>(DogArray_I32::new);
    for (int radius = 1; radius < 11; radius++) {
        BoofTesting.callStaticMethod(ImplEnhanceHistogram.class, "equalizeLocalNaive", input, radius, histogramLength, expected, workArrays);
        BoofTesting.callStaticMethod(EnhanceImageOps.class, "equalizeLocal", input, radius, found, histogramLength, workArrays);
        BoofTesting.assertEquals(expected, found, 1e-10);
    }
}
Also used : GrowArray(pabeles.concurrency.GrowArray) GrayI(boofcv.struct.image.GrayI) DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 2 with GrowArray

use of pabeles.concurrency.GrowArray in project BoofCV by lessthanoptimal.

the class TestImplEnhanceHistogram method equalizeLocalRow.

public void equalizeLocalRow(GrayI input, GrayI found) {
    GrayI expected = GeneralizedImageOps.createSingleBand(input.getClass(), input.width, input.height);
    GrowArray<DogArray_I32> workArrays = new GrowArray<>(DogArray_I32::new);
    GImageMiscOps.fillUniform(input, rand, 0, 9);
    // check the top row
    for (int radius = 1; radius < 6; radius++) {
        // fill with zeros so it can be tested using checkBorderZero
        GImageMiscOps.fill(found, 0);
        BoofTesting.callStaticMethod(ImplEnhanceHistogram.class, "equalizeLocalNaive", input, radius, histogramLength, expected, workArrays);
        BoofTesting.callStaticMethod(ImplEnhanceHistogram.class, "equalizeLocalRow", input, radius, histogramLength, 0, found, workArrays);
        GrayI subExpected = (GrayI) expected.subimage(0, 0, width, radius, null);
        GrayI subFound = (GrayI) found.subimage(0, 0, width, radius, null);
        // check solution
        BoofTesting.assertEquals(subExpected, subFound, 1e-10);
        checkZeroOutsideRows(found, 0, radius);
    }
    // check the bottom row
    for (int radius = 1; radius < 6; radius++) {
        // fill with zeros so it can be tested using checkBorderZero
        GImageMiscOps.fill(found, 0);
        int start = input.height - radius;
        BoofTesting.callStaticMethod(ImplEnhanceHistogram.class, "equalizeLocalNaive", input, radius, histogramLength, expected, workArrays);
        BoofTesting.callStaticMethod(ImplEnhanceHistogram.class, "equalizeLocalRow", input, radius, histogramLength, start, found, workArrays);
        GrayI subExpected = (GrayI) expected.subimage(0, start, width, height, null);
        GrayI subFound = (GrayI) found.subimage(0, start, width, height, null);
        // check solution
        BoofTesting.assertEquals(subExpected, subFound, 1e-10);
        checkZeroOutsideRows(found, start, height);
    }
}
Also used : GrowArray(pabeles.concurrency.GrowArray) GrayI(boofcv.struct.image.GrayI) DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 3 with GrowArray

use of pabeles.concurrency.GrowArray in project BoofCV by lessthanoptimal.

the class TestImplConvolveMean_MT method compareToSingle.

/**
 * Compares results to single threaded
 */
@Test
void compareToSingle() {
    int count = 0;
    Method[] methods = ImplConvolveMean_MT.class.getMethods();
    for (Method m : methods) {
        String name = m.getName();
        if (!(name.equals("horizontal") || name.equals("vertical")))
            continue;
        // look up the test method
        Class[] params = m.getParameterTypes();
        Method testM = BoofTesting.findMethod(ImplConvolveMean.class, name, params);
        ImageBase input = GeneralizedImageOps.createImage(params[0], width, height, 2);
        ImageBase expected = GeneralizedImageOps.createImage(params[1], width, height, 2);
        ImageBase found = GeneralizedImageOps.createImage(params[1], width, height, 2);
        // System.out.println("Method "+name+" "+input.getImageType());
        GImageMiscOps.fillUniform(input, rand, 0, 200);
        try {
            if (name.equals("horizontal")) {
                testM.invoke(null, input, expected, 4, 8);
                m.invoke(null, input, found, 4, 8);
            } else {
                GrowArray workspaces = GeneralizedImageOps.createGrowArray(input.imageType);
                testM.invoke(null, input, expected, 4, 8, workspaces);
                m.invoke(null, input, found, 4, 8, workspaces);
            }
        } catch (Exception e) {
            e.printStackTrace();
            fail("Exception");
        }
        BoofTesting.assertEquals(expected, found, 1);
        count++;
    }
    assertEquals(10, count);
}
Also used : GrowArray(pabeles.concurrency.GrowArray) Method(java.lang.reflect.Method) ImageBase(boofcv.struct.image.ImageBase) Test(org.junit.jupiter.api.Test)

Example 4 with GrowArray

use of pabeles.concurrency.GrowArray in project BoofCV by lessthanoptimal.

the class ImageLocalNormalization method zeroMeanStdOne.

/*
	 * <p>Normalizes the input image such that local statics are a zero mean and with standard deviation
	 * of 1. The image border is handled by truncating the kernel and renormalizing it so that it's sum is
	 * still one.</p>
	 *
	 * <p>output[x,y] = (input[x,y]-mean[x,y])/(stdev[x,y] + delta)</p>
	 *
	 * @param input Input image
	 * @param maxPixelValue maximum value of a pixel element in the input image. -1 = compute max value. Typically
	 * this is 255 or 1.
	 * @param delta A small value used to avoid divide by zero errors. Typical 1e-4f for 32 bit and 1e-8 for 64bit
	 * @param output Storage for output
	 */
public void zeroMeanStdOne(int radius, T input, double maxPixelValue, double delta, T output) {
    // check preconditions and initialize data structures
    initialize(input, output);
    // avoid overflow issues by ensuring that the max pixel value is 1
    T adjusted = ensureMaxValueOfOne(input, maxPixelValue);
    // take advantage of 2D gaussian kernels being separable
    if (border == null) {
        GrowArray work = GeneralizedImageOps.createGrowArray(input.getImageType());
        GBlurImageOps.mean(adjusted, localMean, radius, output, work);
        GPixelMath.pow2(adjusted, pow2);
        GBlurImageOps.mean(pow2, localPow2, radius, output, work);
    } else {
        throw new IllegalArgumentException("Only renormalize border supported here so far. This can be changed...");
    }
    // Compute the final output
    if (imageType == GrayF32.class)
        computeOutput((GrayF32) input, (float) delta, (GrayF32) output, (GrayF32) adjusted);
    else
        computeOutput((GrayF64) input, delta, (GrayF64) output, (GrayF64) adjusted);
}
Also used : GrayF64(boofcv.struct.image.GrayF64) GrayF32(boofcv.struct.image.GrayF32) GrowArray(pabeles.concurrency.GrowArray)

Example 5 with GrowArray

use of pabeles.concurrency.GrowArray in project BoofCV by lessthanoptimal.

the class TestImplEnhanceHistogram method equalizeLocalNaive.

public void equalizeLocalNaive(GrayI input, GrayI output) {
    GrayI tmp = GeneralizedImageOps.createSingleBand(input.getClass(), input.width, input.height);
    GrowArray<DogArray_I32> workArrays = new GrowArray<>(DogArray_I32::new);
    GImageMiscOps.fillUniform(input, rand, 0, 9);
    for (int radius = 1; radius < 11; radius++) {
        BoofTesting.callStaticMethod(ImplEnhanceHistogram.class, "equalizeLocalNaive", input, radius, histogramLength, output, workArrays);
        int width = 2 * radius + 1;
        for (int y = 0; y < height; y++) {
            int y0 = y - radius;
            int y1 = y + radius + 1;
            if (y0 < 0) {
                y0 = 0;
                y1 = y0 + width;
                if (y1 > input.height)
                    y1 = input.height;
            } else if (y1 > input.height) {
                y1 = input.height;
                y0 = y1 - width;
                if (y0 < 0)
                    y0 = 0;
            }
            for (int x = 0; x < input.width; x++) {
                int x0 = x - radius;
                int x1 = x + radius + 1;
                if (x0 < 0) {
                    x0 = 0;
                    x1 = x0 + width;
                    if (x1 > input.width)
                        x1 = input.width;
                } else if (x1 > input.width) {
                    x1 = input.width;
                    x0 = x1 - width;
                    if (x0 < 0)
                        x0 = 0;
                }
                // use the full image algorithm
                int[] histogram = new int[10];
                int[] transform = new int[10];
                GrayI subIn = (GrayI) input.subimage(x0, y0, x1, y1, null);
                GrayI subOut = (GrayI) tmp.subimage(x0, y0, x1, y1, null);
                GImageStatistics.histogram(subIn, 0, histogram);
                EnhanceImageOps.equalize(histogram, transform);
                GEnhanceImageOps.applyTransform(subIn, transform, 0, subOut);
                int expected = subOut.get(x - x0, y - y0);
                int found = output.get(x, y);
                assertEquals(expected, found, x + " " + y);
            }
        }
    }
}
Also used : GrowArray(pabeles.concurrency.GrowArray) GrayI(boofcv.struct.image.GrayI) DogArray_I32(org.ddogleg.struct.DogArray_I32)

Aggregations

GrowArray (pabeles.concurrency.GrowArray)7 GrayI (boofcv.struct.image.GrayI)5 DogArray_I32 (org.ddogleg.struct.DogArray_I32)5 GrayF32 (boofcv.struct.image.GrayF32)1 GrayF64 (boofcv.struct.image.GrayF64)1 ImageBase (boofcv.struct.image.ImageBase)1 Method (java.lang.reflect.Method)1 Test (org.junit.jupiter.api.Test)1