Search in sources :

Example 1 with GrayF64

use of boofcv.struct.image.GrayF64 in project BoofCV by lessthanoptimal.

the class ImageLocalNormalization method computeOutput.

private void computeOutput(GrayF64 input, double delta, GrayF64 output, GrayF64 adjusted) {
    GrayF64 localMean = (GrayF64) this.localMean;
    GrayF64 localPow2 = (GrayF64) this.localPow2;
    for (int y = 0; y < input.height; y++) {
        int indexIn = y * input.width;
        int indexEnd = indexIn + input.width;
        int indexOut = output.startIndex + y * output.stride;
        while (indexIn < indexEnd) {
            double ave = localMean.data[indexIn];
            double std = Math.sqrt(localPow2.data[indexIn] - ave * ave + delta);
            output.data[indexOut++] = (adjusted.data[indexIn] - ave) / std;
            indexIn++;
        }
    }
}
Also used : GrayF64(boofcv.struct.image.GrayF64)

Example 2 with GrayF64

use of boofcv.struct.image.GrayF64 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);
}
Also used : GrayF64(boofcv.struct.image.GrayF64) InterleavedF64(boofcv.struct.image.InterleavedF64)

Example 3 with GrayF64

use of boofcv.struct.image.GrayF64 in project BoofCV by lessthanoptimal.

the class TestCirculantTracker method dense_gauss_kernel.

public void dense_gauss_kernel(int offX, int offY) {
    GrayF64 region = new GrayF64(32, 32);
    GrayF64 target = new GrayF64(32, 32);
    GrayF64 k = new GrayF64(32, 32);
    CirculantTracker<GrayF32> alg = new CirculantTracker<>(1f / 16, 0.2, 1e-2, 0.075, 1.0, 32, 255, interp);
    alg.initialize(new GrayF32(32, 32), 0, 0, 32, 32);
    // create a shape inside the image
    GImageMiscOps.fillRectangle(region, 200, 10, 15, 5, 7);
    // copy a shifted portion of the region
    shiftCopy(offX, offY, region, target);
    // process and see if the peak is where it should be
    alg.dense_gauss_kernel(0.2f, region, target, k);
    int maxX = -1, maxY = -1;
    double maxValue = -1;
    for (int y = 0; y < k.height; y++) {
        for (int x = 0; x < k.width; x++) {
            if (k.get(x, y) > maxValue) {
                maxValue = k.get(x, y);
                maxX = x;
                maxY = y;
            }
        }
    }
    int expectedX = k.width / 2 - offX;
    int expectedY = k.height / 2 - offY;
    assertEquals(expectedX, maxX);
    assertEquals(expectedY, maxY);
}
Also used : GrayF64(boofcv.struct.image.GrayF64) GrayF32(boofcv.struct.image.GrayF32)

Example 4 with GrayF64

use of boofcv.struct.image.GrayF64 in project BoofCV by lessthanoptimal.

the class CirculantVisualizationPanel method update.

public synchronized void update(final CirculantTracker tracker) {
    if (hasSelected) {
        RectangleLength2D_F32 r = tracker.getTargetLocation();
        selected.x0 = (int) r.x0;
        selected.y0 = (int) r.y0;
        selected.x1 = selected.x0 + (int) r.width;
        selected.y1 = selected.y0 + (int) r.height;
        GrayF64 template = tracker.getTargetTemplate();
        GrayF64 response = tracker.getResponse();
        if (this.template == null) {
            this.template = new BufferedImage(template.width, template.height, BufferedImage.TYPE_INT_RGB);
            this.response = new BufferedImage(template.width, template.height, BufferedImage.TYPE_INT_RGB);
            tmp.reshape(template.width, template.height);
        }
        ConvertImage.convert(template, tmp);
        PixelMath.plus(tmp, 0.5f, tmp);
        PixelMath.multiply(tmp, 255, 0, 255, tmp);
        ConvertBufferedImage.convertTo(tmp, this.template, true);
        ConvertImage.convert(response, tmp);
        VisualizeImageData.colorizeSign(tmp, this.response, -1);
    }
    repaint();
}
Also used : GrayF64(boofcv.struct.image.GrayF64) RectangleLength2D_F32(georegression.struct.shapes.RectangleLength2D_F32) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 5 with GrayF64

use of boofcv.struct.image.GrayF64 in project BoofCV by lessthanoptimal.

the class FourierTransformNaive_F64 method inverse.

public static void inverse(GrayF64 inputR, GrayF64 inputI, GrayF64 outputR) {
    GrayF64 tempR = new GrayF64(inputR.width, inputR.height);
    GrayF64 tempI = new GrayF64(inputI.width, inputI.height);
    for (int y = 0; y < inputR.height; y++) {
        int index = inputR.startIndex + inputR.stride * y;
        transform(false, inputR.data, inputI.data, tempR.data, tempI.data, index, inputR.width);
    }
    double[] columnR0 = new double[inputR.height];
    double[] columnI0 = new double[inputR.height];
    double[] columnR1 = new double[inputR.height];
    for (int x = 0; x < inputR.width; x++) {
        // copy the column
        for (int y = 0; y < inputR.height; y++) {
            columnR0[y] = tempR.unsafe_get(x, y);
            columnI0[y] = tempI.unsafe_get(x, y);
        }
        inverse(columnR0, columnI0, columnR1, 0, inputR.height);
        // copy the results back
        for (int y = 0; y < inputR.height; y++) {
            outputR.unsafe_set(x, y, columnR1[y]);
        }
    }
}
Also used : GrayF64(boofcv.struct.image.GrayF64)

Aggregations

GrayF64 (boofcv.struct.image.GrayF64)11 Test (org.junit.Test)4 GrayF32 (boofcv.struct.image.GrayF32)2 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 InterleavedF64 (boofcv.struct.image.InterleavedF64)1 RectangleLength2D_F32 (georegression.struct.shapes.RectangleLength2D_F32)1 BufferedImage (java.awt.image.BufferedImage)1