Search in sources :

Example 21 with Kernel1D_F32

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

the class TestFilterSequence method compareToManualSequence.

/**
 * Perform a sequence of convolutions manually. Should produce the same results
 */
@Test
void compareToManualSequence() {
    Kernel1D_F32 ker1 = FactoryKernel.random1D_F32(kernelWidth, radius, 0, 5, rand);
    Kernel1D_F32 ker2 = FactoryKernel.random1D_F32(kernelWidth + 2, radius + 1, 0, 5, rand);
    Kernel1D_F32 ker3 = FactoryKernel.random1D_F32(kernelWidth + 4, radius + 2, 0, 5, rand);
    GrayF32 input = new GrayF32(width, height);
    ImageMiscOps.fillUniform(input, rand, 0, 10);
    GrayF32 found = new GrayF32(width, height);
    GrayF32 expected = new GrayF32(width, height);
    ImageType<GrayF32> imageType = ImageType.single(GrayF32.class);
    FilterImageInterface f1 = FactoryConvolve.convolve(ker1, imageType, imageType, BorderType.SKIP, true);
    FilterImageInterface f2 = FactoryConvolve.convolve(ker2, imageType, imageType, BorderType.SKIP, true);
    FilterImageInterface f3 = FactoryConvolve.convolve(ker3, imageType, imageType, BorderType.SKIP, true);
    FilterSequence sequence = new FilterSequence(f1, f2, f3);
    sequence.process(input, found);
    assertEquals(radius + 2, sequence.borderHorizontal);
    assertEquals(radius + 2, sequence.borderVertical);
    GrayF32 tmp1 = new GrayF32(width, height);
    GrayF32 tmp2 = new GrayF32(width, height);
    ConvolveImageNoBorder.horizontal(ker1, input, tmp1);
    ConvolveImageNoBorder.horizontal(ker2, tmp1, tmp2);
    ConvolveImageNoBorder.horizontal(ker3, tmp2, expected);
    BoofTesting.assertEquals(expected, found, 1e-4f);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Kernel1D_F32(boofcv.struct.convolve.Kernel1D_F32) Test(org.junit.jupiter.api.Test)

Example 22 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. 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
 * @param work (Optional) Storage for work array
 */
public static void vertical(GrayF32 input, GrayF32 output, int offset, int length, @Nullable GrowArray<DogArray_F32> workspaces) {
    output.reshape(input);
    if (BOverrideConvolveImageMean.invokeNativeVertical(input, output, offset, length))
        return;
    Kernel1D_F32 kernel = FactoryKernel.table1D_F32(offset, length, true);
    if (length > input.height) {
        ConvolveImageNormalized.vertical(kernel, input, output);
    } else {
        ConvolveNormalized_JustBorder_SB.vertical(kernel, input, output);
        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 23 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. 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 length How long the mean filter is
 */
public static void horizontal(GrayF32 input, GrayF32 output, int offset, int length, @Nullable ImageBorder_F32 binput) {
    output.reshape(input.width, output.height);
    if (binput != null) {
        binput.setImage(input);
        Kernel1D_F32 kernel = FactoryKernel.table1D_F32(offset, length, true);
        ConvolveJustBorder_General_SB.horizontal(kernel, binput, output);
    }
    if (length <= input.width) {
        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 24 with Kernel1D_F32

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

the class BlurImageOps method gaussian.

/**
 * Applies Gaussian blur.
 *
 * @param input Input image. Not modified.
 * @param output (Optional) Storage for output image, Can be null. Modified.
 * @param sigmaX Gaussian distribution's sigma along x-axis. If &le; 0 then will be selected based on radius.
 * @param radiusX Radius of the Gaussian blur function along x-axis. If &le; 0 then radius will be determined by sigma.
 * @param sigmaY Gaussian distribution's sigma along y-axis. If &le; 0 then will be selected based on radius.
 * @param radiusY Radius of the Gaussian blur function along y-axis. If &le; 0 then radius will be determined by sigma.
 * @param storage (Optional) Storage for intermediate results. Same size as input image. Can be null.
 * @return Output blurred image.
 */
public static GrayF32 gaussian(GrayF32 input, @Nullable GrayF32 output, double sigmaX, int radiusX, double sigmaY, int radiusY, @Nullable GrayF32 storage) {
    output = InputSanityCheck.declareOrReshape(input, output);
    storage = InputSanityCheck.declareOrReshape(input, storage);
    boolean processed = BOverrideBlurImageOps.invokeNativeGaussian(input, output, sigmaX, radiusX, sigmaY, radiusY, storage);
    if (!processed) {
        Kernel1D_F32 kernelX = FactoryKernelGaussian.gaussian(Kernel1D_F32.class, sigmaX, radiusX);
        Kernel1D_F32 kernelY = sigmaX == sigmaY && radiusX == radiusY ? kernelX : FactoryKernelGaussian.gaussian(Kernel1D_F32.class, sigmaY, radiusY);
        ConvolveImageNormalized.horizontal(kernelX, input, storage);
        ConvolveImageNormalized.vertical(kernelY, storage, output);
    }
    return output;
}
Also used : 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