Search in sources :

Example 16 with Kernel1D_F32

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

the class TestFactoryConvolve method convolve1D_F32.

@Test
void convolve1D_F32() {
    Kernel1D_F32 kernel = FactoryKernel.random1D_F32(kernelWidth, radius, 1, 6, rand);
    ConvolveInterface<GrayF32, GrayF32> conv;
    GrayF32 input = new GrayF32(width, height);
    GrayF32 found = new GrayF32(width, height);
    GrayF32 expected = new GrayF32(width, height);
    ImageMiscOps.fillUniform(input, rand, 0, 5);
    // CHECK NO BORDER
    conv = FactoryConvolve.convolve(kernel, input.imageType, found.imageType, BorderType.SKIP, true);
    conv.process(input, found);
    ConvolveImageNoBorder.horizontal(kernel, input, expected);
    BoofTesting.assertEquals(expected, found, 1e-4f);
    // CHECK EXTENDED
    conv = FactoryConvolve.convolve(kernel, input.imageType, found.imageType, BorderType.EXTENDED, true);
    conv.process(input, found);
    ConvolveImage.horizontal(kernel, input, expected, new ImageBorder1D_F32(BorderIndex1D_Extend::new));
    BoofTesting.assertEquals(expected, found, 1e-4f);
    // CHECK NORMALIZED
    conv = FactoryConvolve.convolve(kernel, input.imageType, found.imageType, BorderType.NORMALIZED, true);
    conv.process(input, found);
    ConvolveImageNormalized.horizontal(kernel, input, expected);
    BoofTesting.assertEquals(expected, found, 1e-4f);
}
Also used : Kernel1D_F32(boofcv.struct.convolve.Kernel1D_F32) ImageBorder1D_F32(boofcv.struct.border.ImageBorder1D_F32) Test(org.junit.jupiter.api.Test)

Example 17 with Kernel1D_F32

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

the class TestDataManipulationOps method create1D_F32.

@Test
void create1D_F32() {
    double[] array = new double[] { 1, 2, 3, 4, 5, 6 };
    Kernel1D_F32 kernel = DataManipulationOps.create1D_F32(array);
    assertEquals(array.length, kernel.getWidth());
    assertEquals(kernel.getOffset(), array.length / 2);
    for (int i = 0; i < array.length; i++) {
        assertEquals(array[i], kernel.get(i), 1e-4);
    }
}
Also used : Kernel1D_F32(boofcv.struct.convolve.Kernel1D_F32) Test(org.junit.jupiter.api.Test)

Example 18 with Kernel1D_F32

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

the class CommonBenchmarkConvolve_IL method setup.

public void setup(int radius) {
    Random rand = new Random(234);
    ImageMiscOps.fillUniform(input_U8, rand, 0, 20);
    ImageMiscOps.fillUniform(input_S16, rand, 0, 20);
    ImageMiscOps.fillUniform(input_S32, rand, 0, 20);
    ImageMiscOps.fillUniform(input_F32, rand, 0, 20);
    ImageMiscOps.fillUniform(input_F64, rand, 0, 20);
    System.arraycopy(input_S16.data, 0, input_U16.data, 0, input_S16.data.length);
    kernelF32 = FactoryKernelGaussian.gaussian(Kernel1D_F32.class, -1, radius);
    kernelI32 = FactoryKernelGaussian.gaussian(Kernel1D_S32.class, -1, radius);
    kernel2D_F32 = FactoryKernelGaussian.gaussian(Kernel2D_F32.class, -1, radius);
    kernel2D_I32 = FactoryKernelGaussian.gaussian(Kernel2D_S32.class, -1, radius);
}
Also used : Kernel1D_S32(boofcv.struct.convolve.Kernel1D_S32) Kernel2D_F32(boofcv.struct.convolve.Kernel2D_F32) Random(java.util.Random) Kernel2D_S32(boofcv.struct.convolve.Kernel2D_S32) Kernel1D_F32(boofcv.struct.convolve.Kernel1D_F32)

Example 19 with Kernel1D_F32

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

the class TestConvolveNormalizedStandardSparse method checkMethod.

private void checkMethod(Method method, int width, int height, int kernelRadius, 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);
    GrayS16 shortImage = new GrayS16(width, height);
    ConvertImage.convert(seedImage, shortImage);
    kernelI32 = FactoryKernelGaussian.gaussian(Kernel1D_S32.class, -1, kernelRadius);
    kernelF32 = FactoryKernelGaussian.gaussian(Kernel1D_F32.class, -1, kernelRadius);
    boolean isFloatingKernel = method.getParameterTypes()[0] == Kernel1D_F32.class;
    Class<?> imageType = method.getParameterTypes()[2];
    ImageGray<?> inputImage;
    if (imageType == GrayF32.class) {
        inputImage = floatImage;
        expectedOutput = computeExpected(floatImage);
    } else if (imageType == GrayU8.class) {
        inputImage = seedImage;
        expectedOutput = computeExpected(seedImage);
    } else {
        inputImage = shortImage;
        expectedOutput = computeExpected(shortImage);
    }
    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) GrayS16(boofcv.struct.image.GrayS16) Kernel1D_F32(boofcv.struct.convolve.Kernel1D_F32) GrayU8(boofcv.struct.image.GrayU8)

Example 20 with Kernel1D_F32

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

the class BoofLogo method paintComponent.

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    int order = 1;
    double sigma = FactoryKernelGaussian.sigmaForRadius(radius, order);
    Kernel1D_F32 kerX = FactoryKernelGaussian.derivativeK(Kernel1D_F32.class, order, sigma, 2 * radius);
    Kernel1D_F32 kerY = FactoryKernelGaussian.derivativeK(Kernel1D_F32.class, order, sigma, radius);
    GrayF32 kernel = new GrayF32(kerX.width, kerY.width);
    for (int i = 0, index = 0; i < kernel.height; i++) {
        for (int j = 0; j < kernel.width; j++) {
            kernel.data[index++] = kerY.data[i] * kerX.data[j];
        }
    }
    float max = ImageStatistics.maxAbs(kernel);
    BufferedImage image = new BufferedImage(kernel.width, kernel.height, BufferedImage.TYPE_INT_RGB);
    for (int y = 0; y < kernel.height; y++) {
        for (int x = 0; x < kernel.width; x++) {
            float v = kernel.get(x, y);
            int rgb;
            if (v > 0) {
                int inv255 = (int) (200 * (1 - v / max)) + 55;
                rgb = 255 << 16 | inv255 << 8 | inv255;
            } else {
                int inv255 = (int) (200 * (1 + v / max)) + 55;
                rgb = inv255 << 16 | inv255 << 8 | inv255;
            }
            image.setRGB(x, y, rgb);
        }
    }
    double w = Math.min(getWidth(), getHeight());
    double s = w / (double) kernel.height;
    // if tx not aligned to integer there is a rendering bug in linux
    double tx = (int) ((getWidth() - s * kernel.width) / 2);
    AffineTransform adjustment = new AffineTransform(s, 0, 0, s, tx, 0);
    g2.drawImage(image, adjustment, null);
    Font font = new Font("Serif", Font.BOLD, (int) (w * 0.4));
    FontMetrics metrics = g2.getFontMetrics(font);
    Rectangle2D r = metrics.getStringBounds(NAME, null);
    tx = getWidth() / 2 - r.getCenterX();
    double ty = (int) w / 2 - r.getCenterY();
    g2.setFont(font);
    g2.setColor(Color.BLACK);
    g2.drawString(NAME, (float) tx, (float) ty);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Kernel1D_F32(boofcv.struct.convolve.Kernel1D_F32) Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage)

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