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;
}
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);
}
}
}
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);
}
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);
}
}
}
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);
}
Aggregations