use of boofcv.struct.border.ImageBorder in project BoofCV by lessthanoptimal.
the class ImageBorderWrapped method wrap.
/**
* Creates an ImageBorder for the two specified images. The offsets are created by dividing the difference
* inside by 2. Border must be bigger the image.
*/
public static <T extends ImageGray<T>> ImageBorder<T> wrap(T border, T image) {
int offsetX = (border.width - image.width) / 2;
int offsetY = (border.height - image.height) / 2;
ImageBorder<T> ret;
if (border instanceof GrayI) {
ret = new S32(offsetX, offsetY, (GrayI) border);
} else if (border instanceof GrayF32) {
ret = (ImageBorder) new F32(offsetX, offsetY, (GrayF32) border);
} else {
throw new RuntimeException("Not supported yet");
}
ret.setImage(image);
return ret;
}
use of boofcv.struct.border.ImageBorder in project BoofCV by lessthanoptimal.
the class TestBlurImageOps method meanBorder.
@Test
void meanBorder() {
for (ImageType type : imageTypes) {
if (type.getFamily() == ImageType.Family.INTERLEAVED)
continue;
ImageBase input = type.createImage(width, height);
ImageBase found = type.createImage(width, height);
ImageBase expected = type.createImage(width, height);
GImageMiscOps.fillUniform(input, rand, 0, 20);
ImageBorder border = FactoryImageBorder.generic(BorderType.REFLECT, input.getImageType());
for (int radius = 1; radius <= 4; radius++) {
GImageMiscOps.fill(expected, 0);
GImageMiscOps.fill(found, 0);
int w = radius * 2 + 1;
// convolve with a kernel to compute the expected value
Kernel2D kernel = FactoryKernel.createKernelForImage(w, w / 2, 2, type.getDataType());
FactoryKernel.setTable(kernel);
GConvolveImageOps.convolveNormalized(kernel, input, expected, border);
Class storage = type.getFamily() == ImageType.Family.PLANAR ? ImageGray.class : input.getClass();
Class work = GeneralizedImageOps.createGrowArray(type).getClass();
Class borderType = ImageBorder.class;
if (type.getFamily() == ImageType.Family.GRAY) {
switch(type.getDataType()) {
case U8:
borderType = ImageBorder_S32.class;
break;
case F32:
borderType = ImageBorder_F32.class;
break;
default:
break;
}
}
try {
// Compare with image border
if (type.getFamily() == ImageType.Family.PLANAR) {
work = GrowArray.class;
Method m = BlurImageOps.class.getMethod("meanB", input.getClass(), found.getClass(), int.class, int.class, borderType, storage, work);
m.invoke(null, input, found, radius, radius, border, null, null);
} else {
Method m = BlurImageOps.class.getMethod("meanB", input.getClass(), found.getClass(), int.class, int.class, borderType, storage, work);
m.invoke(null, input, found, radius, radius, border, null, null);
}
BoofTesting.assertEquals(expected, found, 2);
// Test will null border
// zero the image
GImageMiscOps.fill(found, 0);
if (type.getFamily() == ImageType.Family.PLANAR) {
work = GrowArray.class;
Method m = BlurImageOps.class.getMethod("meanB", input.getClass(), found.getClass(), int.class, int.class, borderType, storage, work);
m.invoke(null, input, found, radius, radius, border, null, null);
} else {
Method m = BlurImageOps.class.getMethod("meanB", input.getClass(), found.getClass(), int.class, int.class, borderType, storage, work);
m.invoke(null, input, found, radius, radius, border, null, null);
}
// Inner should be the same
BoofTesting.assertEqualsInner(expected, found, 2, radius, radius, false);
// outer should be zeros
// When a new image is created it is filled with zeros. That's why this test works
BoofTesting.assertEqualsBorder(expected.createSameShape(), found, 2, radius, radius);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
}
}
use of boofcv.struct.border.ImageBorder in project BoofCV by lessthanoptimal.
the class TestConvolveImageMean method createInputParam.
@Override
protected Object[][] createInputParam(Method candidate, Method validation) {
Class[] c = candidate.getParameterTypes();
ImageGray input = GeneralizedImageOps.createSingleBand(c[0], width, height);
ImageGray output = GeneralizedImageOps.createSingleBand(c[1], width, height);
GImageMiscOps.fillUniform(input, rand, 0, 100);
ImageBorder border = FactoryImageBorder.generic(BorderType.REFLECT, input.getImageType());
Object[][] ret = new Object[2][];
if (c.length == 4) {
ret[0] = new Object[] { input, output, offset1, length1 };
ret[1] = new Object[] { input, output, offset2, length2 };
} else if (c.length == 5) {
ret[0] = new Object[] { input, output, offset1, length1, null };
ret[1] = new Object[] { input, output, offset2, length2, null };
if (ImageBorder.class.isAssignableFrom(c[4])) {
ret[0][4] = border;
ret[1][4] = border;
}
} else {
ret[0] = new Object[] { input, output, offset1, length1, border, null };
ret[1] = new Object[] { input, output, offset2, length2, border, null };
}
return ret;
}
use of boofcv.struct.border.ImageBorder in project BoofCV by lessthanoptimal.
the class TestConvolveJustBorder_General_SB method createInputParam.
@Override
protected Object[][] createInputParam(Method candidate, Method validation) {
Class<?>[] paramTypes = candidate.getParameterTypes();
// Adjust border size for the different convolution types
int kernelLength = 5;
KernelBase kernel = createKernel(paramTypes[0], kernelLength, kernelLength / 2);
ImageBase src = ConvolutionTestHelper.createImage(validation.getParameterTypes()[1], width, height);
GImageMiscOps.fillUniform(src, rand, 0, 5);
ImageBase dst = ConvolutionTestHelper.createImage(validation.getParameterTypes()[2], width, height);
ImageBorder border = FactoryImageBorder.generic(borderType, src.getImageType());
border.setImage(src);
Object[][] ret = new Object[2][paramTypes.length];
// normal symmetric odd kernel
ret[0][0] = kernel;
ret[0][1] = border;
ret[0][2] = dst;
if (paramTypes.length == 4)
ret[0][3] = BoofTesting.primitive(3, paramTypes[3]);
// change the offset
kernel = createKernel(paramTypes[0], kernelLength, kernelLength / 2 - 1);
ret[1][0] = kernel;
ret[1][1] = border;
ret[1][2] = ConvolutionTestHelper.createImage(validation.getParameterTypes()[2], width, height);
if (paramTypes.length == 4)
ret[1][3] = BoofTesting.primitive(3, paramTypes[3]);
return ret;
}
use of boofcv.struct.border.ImageBorder in project BoofCV by lessthanoptimal.
the class GeneralGradientSparse method compareToFullImage_Border.
@Test
void compareToFullImage_Border() {
ImageBorder border = FactoryImageBorder.single(BorderType.EXTENDED, imageType);
ImageGradient gradient = createGradient();
gradient.setBorderType(BorderType.EXTENDED);
gradient.process(image, derivX, derivY);
SparseImageGradient alg = createAlg(border);
alg.setImage(image);
for (int i = 0; i < image.height; i++) {
for (int j = 0; j < image.width; j++) {
assertTrue(image.isInBounds(j, i), j + " " + i);
GradientValue g = alg.compute(j, i);
double expectedX = GeneralizedImageOps.get(derivX, j, i);
double expectedY = GeneralizedImageOps.get(derivY, j, i);
assertEquals(expectedX, g.getX(), 1e-4f);
assertEquals(expectedY, g.getY(), 1e-4f);
}
}
}
Aggregations