Search in sources :

Example 6 with Kernel1D_F32

use of boofcv.struct.convolve.Kernel1D_F32 in project BoofCV by lessthanoptimal.

the class ConvolveImageMean method horizontal.

/**
 * Performs a horizontal 1D mean box filter. Borders are handled by reducing the box size.
 *
 * @param input The input image. Not modified.
 * @param output Where the resulting image is written to. Modified.
 * @param offset Start offset from pixel coordinate
 * @param length How long the mean filter is
 */
public static void horizontal(GrayF32 input, GrayF32 output, int offset, int length) {
    output.reshape(input);
    if (BOverrideConvolveImageMean.invokeNativeHorizontal(input, output, offset, length))
        return;
    Kernel1D_F32 kernel = FactoryKernel.table1D_F32(offset, length, true);
    if (length > input.width) {
        ConvolveImageNormalized.horizontal(kernel, input, output);
    } else {
        ConvolveNormalized_JustBorder_SB.horizontal(kernel, input, output);
        if (BoofConcurrency.USE_CONCURRENT) {
            ImplConvolveMean_MT.horizontal(input, output, offset, length);
        } else {
            ImplConvolveMean.horizontal(input, output, offset, length);
        }
    }
}
Also used : Kernel1D_F32(boofcv.struct.convolve.Kernel1D_F32)

Example 7 with Kernel1D_F32

use of boofcv.struct.convolve.Kernel1D_F32 in project BoofCV by lessthanoptimal.

the class ConvolveImageMean method vertical.

/**
 * Performs a vertical 1D mean box filter. Outside pixels are specified by a border.
 *
 * @param input The input image. Not modified.
 * @param output Where the resulting image is written to. Modified.
 * @param offset Start offset from pixel coordinate
 * @param binput Used to process image borders. If null borders are not processed.
 * @param work (Optional) Storage for work array
 */
public static void vertical(GrayF32 input, GrayF32 output, int offset, int length, @Nullable ImageBorder_F32 binput, @Nullable GrowArray<DogArray_F32> workspaces) {
    output.reshape(input);
    if (binput != null) {
        binput.setImage(input);
        Kernel1D_F32 kernel = FactoryKernel.table1D_F32(offset, length, true);
        ConvolveJustBorder_General_SB.vertical(kernel, binput, output);
    }
    if (length <= input.height) {
        if (BoofConcurrency.USE_CONCURRENT) {
            ImplConvolveMean_MT.vertical(input, output, offset, length, workspaces);
        } else {
            ImplConvolveMean.vertical(input, output, offset, length, workspaces);
        }
    }
}
Also used : Kernel1D_F32(boofcv.struct.convolve.Kernel1D_F32)

Example 8 with Kernel1D_F32

use of boofcv.struct.convolve.Kernel1D_F32 in project BoofCV by lessthanoptimal.

the class TestConvolveImageStandardSparse method checkMethod.

private void checkMethod(Method method, int width, int height, int kernelOffset, int kernelWidth, Random rand) {
    GrayU8 seedImage = new GrayU8(width, height);
    ImageMiscOps.fillUniform(seedImage, rand, 0, 255);
    // creates a floating point image with integer elements
    GrayF32 floatImage = new GrayF32(width, height);
    ConvertImage.convert(seedImage, floatImage);
    sumKernelI32 = 0;
    kernelI32 = FactoryKernelGaussian.gaussian(Kernel1D_S32.class, -1, kernelWidth / 2);
    kernelF32 = new Kernel1D_F32(kernelI32.width);
    for (int i = 0; i < kernelI32.width; i++) {
        kernelF32.data[i] = kernelI32.data[i];
        sumKernelI32 += kernelI32.data[i];
    }
    kernelI32.offset = kernelOffset;
    kernelF32.offset = kernelOffset;
    boolean isFloatingKernel = method.getParameterTypes()[0] == Kernel1D_F32.class;
    boolean isDivisor = method.getParameterTypes().length != 6;
    expectedOutput = computeExpected(seedImage, !isFloatingKernel, isDivisor);
    ImageGray inputImage = GConvertImage.convert(floatImage, null, (Class) method.getParameterTypes()[2]);
    Object inputKernel = isFloatingKernel ? kernelF32 : kernelI32;
    Object inputStorage = isFloatingKernel ? new float[kernelI32.width] : new int[kernelI32.width];
    checkResults(method, inputKernel, inputImage, inputStorage);
}
Also used : Kernel1D_S32(boofcv.struct.convolve.Kernel1D_S32) GrayF32(boofcv.struct.image.GrayF32) Kernel1D_F32(boofcv.struct.convolve.Kernel1D_F32) GrayU8(boofcv.struct.image.GrayU8) ImageGray(boofcv.struct.image.ImageGray)

Example 9 with Kernel1D_F32

use of boofcv.struct.convolve.Kernel1D_F32 in project BoofCV by lessthanoptimal.

the class TestPyramidDiscreteSampleBlur method checkSigmas.

/**
 * Makes sure the amount of Gaussian blur in each level is correctly computed
 */
@Test
void checkSigmas() {
    Kernel1D_F32 kernel = FactoryKernelGaussian.gaussian(Kernel1D_F32.class, -1, 3);
    var alg = new PyramidDiscreteSampleBlur<>(kernel, 3, ImageType.single(GrayF32.class), true, configLevels);
    alg.process(new GrayF32(100, 100));
    assertEquals(0, alg.getSigma(0), 1e-8);
    assertEquals(3, alg.getSigma(1), 1e-8);
    assertEquals(6.7082, alg.getSigma(2), 1e-3);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Kernel1D_F32(boofcv.struct.convolve.Kernel1D_F32) Test(org.junit.jupiter.api.Test)

Example 10 with Kernel1D_F32

use of boofcv.struct.convolve.Kernel1D_F32 in project BoofCV by lessthanoptimal.

the class TestPyramidDiscreteSampleBlur method _update.

public void _update(GrayF32 input) {
    Kernel1D_F32 kernel = FactoryKernelGaussian.gaussian(Kernel1D_F32.class, -1, 3);
    GrayF32 convImg = new GrayF32(width, height);
    GrayF32 convImg2 = new GrayF32(width / 2, height / 2);
    GrayF32 storage = new GrayF32(width, height);
    ConvolveImageNormalized.horizontal(kernel, input, storage);
    ConvolveImageNormalized.vertical(kernel, storage, convImg);
    var alg = new PyramidDiscreteSampleBlur<>(kernel, 3, ImageType.single(GrayF32.class), true, configLevels);
    alg.process(input);
    // top layer should be the same as the input layer
    BoofTesting.assertEquals(input, alg.getLayer(0), 1e-4f);
    // second layer should have the same values as the convolved image
    for (int i = 0; i < height; i += 2) {
        for (int j = 0; j < width; j += 2) {
            float a = convImg.get(j, i);
            float b = alg.getLayer(1).get(j / 2, i / 2);
            assertEquals(a, b, 1e-4);
        }
    }
    storage.reshape(width / 2, height / 2);
    ConvolveImageNormalized.horizontal(kernel, alg.getLayer(1), storage);
    ConvolveImageNormalized.vertical(kernel, storage, convImg2);
    // second layer should have the same values as the second convolved image
    for (int i = 0; i < height / 2; i += 2) {
        for (int j = 0; j < width / 2; j += 2) {
            float a = convImg2.get(j, i);
            float b = alg.getLayer(2).get(j / 2, i / 2);
            assertEquals(a, b, 1e-4);
        }
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Kernel1D_F32(boofcv.struct.convolve.Kernel1D_F32)

Aggregations

Kernel1D_F32 (boofcv.struct.convolve.Kernel1D_F32)24 GrayF32 (boofcv.struct.image.GrayF32)10 Test (org.junit.jupiter.api.Test)7 Kernel1D_S32 (boofcv.struct.convolve.Kernel1D_S32)3 Kernel2D_F32 (boofcv.struct.convolve.Kernel2D_F32)2 GrayU8 (boofcv.struct.image.GrayU8)2 ImageBorder1D_F32 (boofcv.struct.border.ImageBorder1D_F32)1 Kernel2D_S32 (boofcv.struct.convolve.Kernel2D_S32)1 GrayS16 (boofcv.struct.image.GrayS16)1 ImageGray (boofcv.struct.image.ImageGray)1 AffineTransform (java.awt.geom.AffineTransform)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1 Random (java.util.Random)1