use of boofcv.struct.image.InterleavedF64 in project BoofCV by lessthanoptimal.
the class CirculantTracker method dense_gauss_kernel.
/**
* Gaussian Kernel with dense sampling.
* Evaluates a gaussian kernel with bandwidth SIGMA for all displacements
* between input images X and Y, which must both be MxN. They must also
* be periodic (ie., pre-processed with a cosine window). The result is
* an MxN map of responses.
*
* @param sigma Gaussian kernel bandwidth
* @param x Input image
* @param y Input image
* @param k Output containing Gaussian kernel for each element in target region
*/
public void dense_gauss_kernel(double sigma, GrayF64 x, GrayF64 y, GrayF64 k) {
InterleavedF64 xf = tmpFourier0, yf, xyf = tmpFourier2;
GrayF64 xy = tmpReal0;
double yy;
// find x in Fourier domain
fft.forward(x, xf);
double xx = imageDotProduct(x);
if (x != y) {
// general case, x and y are different
yf = tmpFourier1;
fft.forward(y, yf);
yy = imageDotProduct(y);
} else {
// auto-correlation of x, avoid repeating a few operations
yf = xf;
yy = xx;
}
// ---- xy = invF[ F(x)*F(y) ]
// cross-correlation term in Fourier domain
elementMultConjB(xf, yf, xyf);
// convert to spatial domain
fft.inverse(xyf, xy);
circshift(xy, tmpReal1);
// calculate gaussian response for all positions
gaussianKernel(xx, yy, tmpReal1, sigma, k);
}
use of boofcv.struct.image.InterleavedF64 in project BoofCV by lessthanoptimal.
the class TestCirculantTracker method elementMultConjB.
@Test
public void elementMultConjB() {
InterleavedF64 a = new InterleavedF64(width, height, 2);
InterleavedF64 b = new InterleavedF64(width, height, 2);
InterleavedF64 c = new InterleavedF64(width, height, 2);
ImageMiscOps.fillUniform(a, rand, -10, 10);
ImageMiscOps.fillUniform(b, rand, -10, 10);
ImageMiscOps.fillUniform(c, rand, -10, 10);
CirculantTracker.elementMultConjB(a, b, c);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
Complex_F64 aa = new Complex_F64(a.getBand(x, y, 0), a.getBand(x, y, 1));
Complex_F64 bb = new Complex_F64(b.getBand(x, y, 0), b.getBand(x, y, 1));
Complex_F64 cc = new Complex_F64();
ComplexMath_F64.conj(bb, bb);
ComplexMath_F64.multiply(aa, bb, cc);
double foundReal = c.getBand(x, y, 0);
double foundImg = c.getBand(x, y, 1);
assertEquals(cc.real, foundReal, 1e-4);
assertEquals(cc.imaginary, foundImg, 1e-4);
}
}
}
use of boofcv.struct.image.InterleavedF64 in project BoofCV by lessthanoptimal.
the class GeneralFft_to_DiscreteFourierTransform_F64 method inverse.
@Override
public void inverse(InterleavedF64 transform, GrayF64 image) {
DiscreteFourierTransformOps.checkImageArguments(image, transform);
if (image.isSubimage())
throw new IllegalArgumentException("Subimages are not supported");
checkDeclareAlg(image);
// If he user lets us, modify the transform
InterleavedF64 workImage;
if (modifyInputs) {
workImage = transform;
} else {
tmp.reshape(transform.width, transform.height);
tmp.setTo(transform);
workImage = tmp;
}
alg.complexInverse(workImage.data, true);
// copy the real portion. imaginary should be zeros
int N = image.width * image.height;
for (int i = 0; i < N; i++) {
image.data[i] = workImage.data[i * 2];
}
}
use of boofcv.struct.image.InterleavedF64 in project BoofCV by lessthanoptimal.
the class TestCirculantTracker method computeAlphas.
@Test
public void computeAlphas() {
InterleavedF64 yf = new InterleavedF64(width, height, 2);
InterleavedF64 kf = new InterleavedF64(width, height, 2);
InterleavedF64 alphaf = new InterleavedF64(width, height, 2);
ImageMiscOps.fillUniform(yf, rand, -10, 10);
ImageMiscOps.fillUniform(kf, rand, -10, 10);
ImageMiscOps.fillUniform(alphaf, rand, -10, 10);
float lambda = 0.01f;
CirculantTracker.computeAlphas(yf, kf, lambda, alphaf);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
Complex_F64 a = new Complex_F64(yf.getBand(x, y, 0), yf.getBand(x, y, 1));
Complex_F64 b = new Complex_F64(kf.getBand(x, y, 0) + lambda, kf.getBand(x, y, 1));
Complex_F64 c = new Complex_F64();
ComplexMath_F64.divide(a, b, c);
double foundReal = alphaf.getBand(x, y, 0);
double foundImg = alphaf.getBand(x, y, 1);
assertEquals(c.real, foundReal, 1e-4);
assertEquals(c.imaginary, foundImg, 1e-4);
}
}
}
Aggregations