use of boofcv.struct.convolve.Kernel2D in project BoofCV by lessthanoptimal.
the class TestBlurImageOps method gaussian.
@Test
public void gaussian() {
for (ImageType type : imageTypes) {
ImageBase input = type.createImage(width, height);
ImageBase found = type.createImage(width, height);
ImageBase expected = type.createImage(width, height);
GImageMiscOps.fillUniform(input, rand, 0, 20);
for (int radius = 1; radius <= 4; radius++) {
GImageMiscOps.fill(expected, 0);
GImageMiscOps.fill(found, 0);
// convolve with a kernel to compute the expected value
Kernel2D kernel = FactoryKernelGaussian.gaussian2D(type.getDataType(), -1, radius);
GConvolveImageOps.convolveNormalized(kernel, input, expected);
try {
Class storage = type.getFamily() == ImageType.Family.PLANAR ? ImageGray.class : input.getClass();
Method m = BlurImageOps.class.getMethod("gaussian", input.getClass(), found.getClass(), double.class, int.class, storage);
m.invoke(null, input, found, -1, radius, null);
BoofTesting.assertEquals(expected, found, 2);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
}
}
use of boofcv.struct.convolve.Kernel2D in project BoofCV by lessthanoptimal.
the class GImageDerivativeOps method createAnyDerivatives.
/**
* <p>
* Convenience function for creating an instance of {@link boofcv.abst.filter.derivative.AnyImageDerivative}.
* This class is an any way to compute any derivative of any order using the specified kernel. It might
* use more memory or be more expensive the specialized code but is easy to use.
* </p>
*
* @param type Type of gradient to use
* @param inputType Type of input image.
* @param derivType Type of derivative image
* @param <I> Image type.
* @param <D> Image derivative type.
* @return AnyImageDerivative
*/
public static <I extends ImageGray<I>, D extends ImageGray<D>> AnyImageDerivative<I, D> createAnyDerivatives(DerivativeType type, Class<I> inputType, Class<D> derivType) {
boolean isInteger = !GeneralizedImageOps.isFloatingPoint(inputType);
KernelBase kernel = lookupKernelX(type, isInteger);
if (kernel instanceof Kernel1D)
return new AnyImageDerivative<>((Kernel1D) kernel, inputType, derivType);
else
return new AnyImageDerivative<>((Kernel2D) kernel, inputType, derivType);
}
use of boofcv.struct.convolve.Kernel2D in project BoofCV by lessthanoptimal.
the class TestConvolveImageStandard_IL method convolve.
/**
* Unit test for 2D convolution.
*/
public void convolve(ImageInterleaved img, ImageInterleaved dest) {
Kernel2D ker = FactoryKernel.createKernelForImage(kernelWidth, kernelRadius, 2, img.getDataType());
// standard symmetric odd kernel shape
ker = FactoryKernel.random(ker.getClass(), kernelWidth, kernelRadius, 0, maxKernelValue, rand);
convolve(ker, img, dest);
// odd non-symmetric kernel shape
ker = FactoryKernel.random(ker.getClass(), kernelWidth, 0, 0, maxKernelValue, rand);
convolve(ker, img, dest);
// even non-symmetric kernel shape
ker = FactoryKernel.random(ker.getClass(), 2, 1, 0, maxKernelValue, rand);
convolve(ker, img, dest);
}
use of boofcv.struct.convolve.Kernel2D in project BoofCV by lessthanoptimal.
the class TestConvolveImageStandard_IL method convolveDiv.
/**
* Unit test for 2D convolution with division.
*/
public void convolveDiv(ImageInterleaved img, ImageInterleaved dest) {
Kernel2D ker = FactoryKernel.createKernelForImage(kernelWidth, kernelRadius, 2, img.getDataType());
// standard symmetric odd kernel shape
ker = FactoryKernel.random(ker.getClass(), kernelWidth, kernelRadius, 0, maxKernelValue, rand);
convolveDiv(ker, img, dest);
// odd non-symmetric kernel shape
ker = FactoryKernel.random(ker.getClass(), kernelWidth, 0, 0, maxKernelValue, rand);
convolveDiv(ker, img, dest);
// even non-symmetric kernel shape
ker = FactoryKernel.random(ker.getClass(), 2, 1, 0, maxKernelValue, rand);
convolveDiv(ker, img, dest);
}
use of boofcv.struct.convolve.Kernel2D in project BoofCV by lessthanoptimal.
the class TestSteerableKernel_F32 method checkCombining.
/**
* Checks to see if the basis kernels are correctly combined together.
*/
@Test
public void checkCombining() {
double[] c = new double[] { 0.1, 0.2, 0.8 };
DummySteerableCoefficients coef = new DummySteerableCoefficients(c);
Kernel2D[] basis = new Kernel2D[3];
basis[0] = FactoryKernel.random2D_F32(width, width / 2, 0, 10, rand);
basis[1] = FactoryKernel.random2D_F32(width, width / 2, 0, 10, rand);
basis[2] = FactoryKernel.random2D_F32(width, width / 2, 0, 10, rand);
Kernel2D_F32 expected = new Kernel2D_F32(width);
for (int y = 0; y < width; y++) {
for (int x = 0; x < width; x++) {
float total = 0;
for (int i = 0; i < c.length; i++) {
total += c[i] * ((Kernel2D_F32) basis[i]).get(x, y);
}
expected.set(x, y, total);
}
}
SteerableKernel_F32 alg = new SteerableKernel_F32();
alg.setBasis(coef, basis);
Kernel2D_F32 found = alg.compute(60.0);
assertTrue(KernelMath.isEquals(expected.data, found.data, width * width, 1e-4f));
}
Aggregations