use of boofcv.struct.convolve.Kernel1D 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.convolve.Kernel1D in project BoofCV by lessthanoptimal.
the class DisplayGaussianKernelApp method setActiveAlgorithm.
@Override
public void setActiveAlgorithm(String name, Object cookie) {
DerivType type = (DerivType) cookie;
panel.reset();
for (int radius = 1; radius <= 40; radius += 2) {
int maxOrder = Math.max(type.orderX, type.orderY);
double sigma = FactoryKernelGaussian.sigmaForRadius(radius, maxOrder);
Class typeKer1 = FactoryKernel.getKernelType(imageType, 1);
Kernel1D kerX = FactoryKernelGaussian.derivativeK(typeKer1, type.orderX, sigma, radius);
Kernel1D kerY = FactoryKernelGaussian.derivativeK(typeKer1, type.orderY, sigma, radius);
Kernel2D kernel = GKernelMath.convolve(kerY, kerX);
T smallImg = GKernelMath.convertToImage(kernel);
new FDistort(smallImg, largeImg).interpNN().scaleExt().apply();
double maxValue = GImageStatistics.maxAbs(largeImg);
BufferedImage out = VisualizeImageData.colorizeSign(largeImg, null, maxValue);
panel.addImage(out, String.format("%5d", radius));
}
}
use of boofcv.struct.convolve.Kernel1D in project BoofCV by lessthanoptimal.
the class ExamplePyramidDiscrete method unusual.
/**
* Creates a more unusual pyramid and updater.
*/
public void unusual() {
// Note that the first level does not have to be one
pyramid = FactoryPyramid.discreteGaussian(new int[] { 2, 6 }, -1, 2, true, ImageType.single(imageType));
// Other kernels can also be used besides Gaussian
Kernel1D kernel;
if (GeneralizedImageOps.isFloatingPoint(imageType)) {
kernel = FactoryKernel.table1D_F32(2, true);
} else {
kernel = FactoryKernel.table1D_I32(2);
}
}
use of boofcv.struct.convolve.Kernel1D in project BoofCV by lessthanoptimal.
the class TestConvolveImageStandard_IL method horizontal.
/**
* Unit test for horizontal convolution.
*/
public void horizontal(ImageInterleaved img, ImageInterleaved dest) {
Kernel1D ker = FactoryKernel.createKernelForImage(kernelWidth, kernelRadius, 1, img.getDataType());
// standard symmetric odd kernel shape
ker = FactoryKernel.random(ker.getClass(), kernelWidth, kernelRadius, 0, maxKernelValue, rand);
checkHorizontal(ker, img, dest);
// odd non-symmetric kernel shape
ker = FactoryKernel.random(ker.getClass(), kernelWidth, 0, 0, maxKernelValue, rand);
checkHorizontal(ker, img, dest);
// even non-symmetric kernel shape
ker = FactoryKernel.random(ker.getClass(), 2, 1, 0, maxKernelValue, rand);
checkHorizontal(ker, img, dest);
}
use of boofcv.struct.convolve.Kernel1D in project BoofCV by lessthanoptimal.
the class TestConvolveImageStandard_IL method verticalDiv.
/**
* Unit test for vertical convolution with division.
*/
public void verticalDiv(ImageInterleaved img, ImageInterleaved dest) {
Kernel1D ker = FactoryKernel.createKernelForImage(kernelWidth, kernelRadius, 1, img.getDataType());
// standard symmetric odd kernel shape
ker = FactoryKernel.random(ker.getClass(), kernelWidth, kernelRadius, 0, maxKernelValue, rand);
checkVerticalDiv(ker, img, dest);
// odd non-symmetric kernel shape
ker = FactoryKernel.random(ker.getClass(), kernelWidth, 0, 0, maxKernelValue, rand);
checkVerticalDiv(ker, img, dest);
// even non-symmetric kernel shape
ker = FactoryKernel.random(ker.getClass(), 2, 1, 0, maxKernelValue, rand);
checkVerticalDiv(ker, img, dest);
}
Aggregations