use of boofcv.struct.convolve.Kernel2D_S32 in project BoofCV by lessthanoptimal.
the class ExampleConvolution method convolve2D.
/**
* Convolves a 2D kernel
*/
private static void convolve2D(GrayU8 gray) {
// By default 2D kernels will be centered around width/2
Kernel2D_S32 kernel = new Kernel2D_S32(3);
kernel.set(1, 0, 2);
kernel.set(2, 1, 2);
kernel.set(0, 1, -2);
kernel.set(1, 2, -2);
// Output needs to handle the increased domain after convolution. Can't be 8bit
GrayS16 output = new GrayS16(gray.width, gray.height);
ImageBorder<GrayU8> border = FactoryImageBorder.wrap(BorderType.EXTENDED, gray);
GConvolveImageOps.convolve(kernel, gray, output, border);
panel.addImage(VisualizeImageData.standard(output, null), "2D Kernel");
}
use of boofcv.struct.convolve.Kernel2D_S32 in project BoofCV by lessthanoptimal.
the class TestFactoryConvolve method convolve2D_I32.
@Test
public void convolve2D_I32() {
Kernel2D_S32 kernel = FactoryKernel.random2D_I32(kernelWidth, radius, 1, 6, rand);
ConvolveInterface conv;
GrayU8 input = new GrayU8(width, height);
GrayS16 found = new GrayS16(width, height);
GrayS16 expected = new GrayS16(width, height);
ImageMiscOps.fillUniform(input, rand, 0, 5);
// CHECK NO BORDER
conv = FactoryConvolve.convolve(kernel, GrayU8.class, GrayI16.class, BorderType.SKIP);
conv.process(input, found);
ConvolveImageNoBorder.convolve(kernel, input, expected);
BoofTesting.assertEquals(expected, found, 0);
// CHECK EXTENDED
conv = FactoryConvolve.convolve(kernel, GrayU8.class, GrayI16.class, BorderType.EXTENDED);
conv.process(input, found);
ConvolveImage.convolve(kernel, input, expected, new ImageBorder1D_S32(BorderIndex1D_Extend.class));
BoofTesting.assertEquals(expected, found, 0);
// CHECK NORMALIZED
GrayU8 found8 = new GrayU8(width, height);
GrayU8 expected8 = new GrayU8(width, height);
conv = FactoryConvolve.convolve(kernel, GrayU8.class, GrayU8.class, BorderType.NORMALIZED);
conv.process(input, found8);
ConvolveImageNormalized.convolve(kernel, input, expected8);
BoofTesting.assertEquals(expected8, found8, 0);
}
use of boofcv.struct.convolve.Kernel2D_S32 in project BoofCV by lessthanoptimal.
the class TestFactoryConvolveDown method convolve2D_I32.
@Test
public void convolve2D_I32() {
Kernel2D_S32 kernel = FactoryKernel.random2D_I32(kernelWidth, radius, 1, 6, rand);
FilterImageInterface conv;
GrayU8 input = new GrayU8(width, height);
GrayS16 found = new GrayS16(width / skip, height / skip);
GrayS16 expected = new GrayS16(width / skip, height / skip);
ImageMiscOps.fillUniform(input, rand, 0, 5);
// CHECK NO BORDER
conv = FactoryConvolveDown.convolveSB(kernel, BorderType.SKIP, skip, GrayU8.class, GrayI16.class);
conv.process(input, found);
ConvolveImageDownNoBorder.convolve(kernel, input, expected, skip);
BoofTesting.assertEquals(expected, found, 0);
// CHECK EXTENDED
// conv = FactoryConvolveDown.convolve( kernel,GrayU8.class,ImageInt16.class,BorderType.EXTENDED);
// conv.process(input,found);
// ConvolveWithBorder.convolve(kernel,input,expected);
// BoofTesting.assertEquals(expected,found,0);
// CHECK NORMALIZED
GrayU8 found8 = new GrayU8(width / skip, height / skip);
GrayU8 expected8 = new GrayU8(width / skip, height / skip);
conv = FactoryConvolveDown.convolveSB(kernel, BorderType.NORMALIZED, skip, GrayU8.class, GrayU8.class);
conv.process(input, found8);
ConvolveImageDownNormalized.convolve(kernel, input, expected8, skip);
BoofTesting.assertEquals(expected8, found8, 0);
}
use of boofcv.struct.convolve.Kernel2D_S32 in project BoofCV by lessthanoptimal.
the class SteerableKernel_I32 method compute.
@Override
public Kernel2D_S32 compute(double angle) {
// set the output to zero
KernelMath.fill(output, 0);
int N = output.width * output.width;
for (int i = 0; i < basis.length; i++) {
double c = coef.compute(angle, i);
Kernel2D_S32 k = (Kernel2D_S32) basis[i];
for (int j = 0; j < N; j++) {
output.data[j] += k.data[j] * c;
}
}
return output;
}
use of boofcv.struct.convolve.Kernel2D_S32 in project BoofCV by lessthanoptimal.
the class SteerableKernel_I32 method setBasis.
@Override
public void setBasis(SteerableCoefficients coef, Kernel2D... basis) {
this.coef = coef;
this.basis = basis;
int width = basis[0].width;
output = new Kernel2D_S32(width);
}
Aggregations