Search in sources :

Example 61 with ImageGray

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

the class FactorySteerable method gaussian.

/**
 * Steerable filter for 2D Gaussian derivatives.  The basis is composed of a set of rotated kernels.
 *
 * @param kernelType Specifies which type of 2D kernel should be generated.
 * @param orderX Order of the derivative in the x-axis.
 * @param orderY Order of the derivative in the y-axis.
 *
 * @param sigma
 *@param radius Radius of the kernel.  @return Steerable kernel generator for the specified gaussian derivative.
 */
public static <K extends Kernel2D> SteerableKernel<K> gaussian(Class<K> kernelType, int orderX, int orderY, double sigma, int radius) {
    if (orderX < 0 || orderX > 4)
        throw new IllegalArgumentException("derivX must be from 0 to 4 inclusive.");
    if (orderY < 0 || orderY > 4)
        throw new IllegalArgumentException("derivT must be from 0 to 4 inclusive.");
    int order = orderX + orderY;
    if (order > 4) {
        throw new IllegalArgumentException("The total order of x and y can't be greater than 4");
    }
    int maxOrder = Math.max(orderX, orderY);
    if (sigma <= 0)
        sigma = (float) FactoryKernelGaussian.sigmaForRadius(radius, maxOrder);
    else if (radius <= 0)
        radius = FactoryKernelGaussian.radiusForSigma(sigma, maxOrder);
    Class kernel1DType = FactoryKernel.get1DType(kernelType);
    Kernel1D kerX = FactoryKernelGaussian.derivativeK(kernel1DType, orderX, sigma, radius);
    Kernel1D kerY = FactoryKernelGaussian.derivativeK(kernel1DType, orderY, sigma, radius);
    Kernel2D kernel = GKernelMath.convolve(kerY, kerX);
    Kernel2D[] basis = new Kernel2D[order + 1];
    // convert it into an image which can be rotated
    ImageGray image = GKernelMath.convertToImage(kernel);
    ImageGray imageRotated = (ImageGray) image.createNew(image.width, image.height);
    basis[0] = kernel;
    // form the basis by created rotated versions of the kernel
    double angleStep = Math.PI / basis.length;
    for (int index = 1; index <= order; index++) {
        float angle = (float) (angleStep * index);
        GImageMiscOps.fill(imageRotated, 0);
        new FDistort(image, imageRotated).rotate(angle).apply();
        basis[index] = GKernelMath.convertToKernel(imageRotated);
    }
    SteerableKernel<K> ret;
    if (kernelType == Kernel2D_F32.class)
        ret = (SteerableKernel<K>) new SteerableKernel_F32();
    else
        ret = (SteerableKernel<K>) new SteerableKernel_I32();
    ret.setBasis(FactorySteerCoefficients.polynomial(order), basis);
    return ret;
}
Also used : Kernel1D(boofcv.struct.convolve.Kernel1D) SteerableKernel_F32(boofcv.alg.filter.kernel.impl.SteerableKernel_F32) ImageGray(boofcv.struct.image.ImageGray) FDistort(boofcv.abst.distort.FDistort) SteerableKernel(boofcv.alg.filter.kernel.SteerableKernel) SteerableKernel_I32(boofcv.alg.filter.kernel.impl.SteerableKernel_I32) Kernel2D(boofcv.struct.convolve.Kernel2D)

Example 62 with ImageGray

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

the class TestWaveletTransformOps method testMultipleLevels.

private void testMultipleLevels(Class typeInput) {
    this.typeInput = typeInput;
    WaveletDescription<?> desc = createDesc(typeInput);
    // try different sized images
    for (int adjust = 0; adjust < 5; adjust++) {
        int w = width + adjust;
        int h = height + adjust;
        ImageGray input = GeneralizedImageOps.createSingleBand(typeInput, w, h);
        ImageGray found = GeneralizedImageOps.createSingleBand(typeInput, w, h);
        GImageMiscOps.fillUniform(input, rand, 0, 50);
        for (int level = 1; level <= 5; level++) {
            ImageDimension dim = UtilWavelet.transformDimension(w, h, level);
            ImageGray output = GeneralizedImageOps.createSingleBand(typeInput, dim.width, dim.height);
            // System.out.println("adjust "+adjust+" level "+level+" scale "+ div);
            invokeTransformN(desc, (ImageGray) input.clone(), output, found, level, 0, 255);
            BoofTesting.assertEquals(input, found, 1e-4f);
        }
    }
}
Also used : ImageDimension(boofcv.struct.image.ImageDimension) ImageGray(boofcv.struct.image.ImageGray)

Example 63 with ImageGray

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

the class TestImageMiscOps method testFillUniform_Single.

private void testFillUniform_Single(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramTypes = m.getParameterTypes();
    ImageGray orig = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
    if (orig.getDataType().isInteger()) {
        if (orig.getDataType().isSigned())
            m.invoke(null, orig, rand, -10, 10);
        else {
            m.invoke(null, orig, rand, 1, 10);
        }
    } else {
        m.invoke(null, orig, rand, -10, 10);
    }
    int numZero = 0;
    GImageGray a = FactoryGImageGray.wrap(orig);
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            double value = a.get(j, i).doubleValue();
            assertTrue("value = " + value, value >= -10 && value < 10);
            if (value == 0)
                numZero++;
        }
    }
    assertTrue(numZero < width * height);
}
Also used : FactoryGImageGray(boofcv.core.image.FactoryGImageGray) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray) GImageGray(boofcv.core.image.GImageGray)

Example 64 with ImageGray

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

the class TestImageMiscOps method testFillBorder.

private void testFillBorder(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramTypes = m.getParameterTypes();
    ImageGray orig = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
    GImageMiscOps.fill(orig, 4);
    int r = 2;
    if (orig.getDataType().isInteger()) {
        m.invoke(null, orig, 5, r);
    } else {
        m.invoke(null, orig, 5, r);
    }
    GImageGray a = FactoryGImageGray.wrap(orig);
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            if (j < r || i < r || j >= width - r || i >= height - r)
                assertEquals(i + " " + j, 5, a.get(j, i).doubleValue(), 1e-4);
            else
                assertEquals(4, a.get(j, i).doubleValue(), 1e-4);
        }
    }
}
Also used : FactoryGImageGray(boofcv.core.image.FactoryGImageGray) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray) GImageGray(boofcv.core.image.GImageGray)

Example 65 with ImageGray

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

the class TestImageMiscOps method testAddGaussian_Single.

private void testAddGaussian_Single(Method m) throws InvocationTargetException, IllegalAccessException {
    double mean = 10;
    Class[] paramTypes = m.getParameterTypes();
    ImageGray orig = GeneralizedImageOps.createSingleBand(paramTypes[0], width, height);
    GImageMiscOps.fill(orig, mean);
    m.invoke(null, orig, rand, 2.0, 0, 255);
    double stdev2 = 0;
    GImageGray a = FactoryGImageGray.wrap(orig);
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            double value = a.get(j, i).doubleValue();
            stdev2 += (value - mean) * (value - mean);
        }
    }
    GImageMiscOps.fill(orig, mean);
    m.invoke(null, orig, rand, 10.0, 0, 255);
    double stdev10 = 0;
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            double value = a.get(j, i).doubleValue();
            stdev10 += (value - mean) * (value - mean);
        }
    }
    // see if the gaussian with the larger variance creates a noisier image
    assertTrue(stdev2 < stdev10);
}
Also used : FactoryGImageGray(boofcv.core.image.FactoryGImageGray) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray) GImageGray(boofcv.core.image.GImageGray)

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