Search in sources :

Example 56 with ImageGray

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

the class OrientationHistogramSift method computeHistogram.

/**
 * Constructs the histogram around the specified point.
 *
 * @param c_x Center x-axis
 * @param c_y Center y-axis
 * @param sigma Scale of feature, adjusted for local octave
 */
void computeHistogram(int c_x, int c_y, double sigma) {
    int r = (int) Math.ceil(sigma * sigmaEnlarge);
    // specify the area being sampled
    bound.x0 = c_x - r;
    bound.y0 = c_y - r;
    bound.x1 = c_x + r + 1;
    bound.y1 = c_y + r + 1;
    ImageGray rawDX = derivX.getImage();
    ImageGray rawDY = derivY.getImage();
    // make sure it is contained in the image bounds
    BoofMiscOps.boundRectangleInside(rawDX, bound);
    // clear the histogram
    Arrays.fill(histogramMag, 0);
    Arrays.fill(histogramX, 0);
    Arrays.fill(histogramY, 0);
    // construct the histogram
    for (int y = bound.y0; y < bound.y1; y++) {
        // iterate through the raw array for speed
        int indexDX = rawDX.startIndex + y * rawDX.stride + bound.x0;
        int indexDY = rawDY.startIndex + y * rawDY.stride + bound.x0;
        for (int x = bound.x0; x < bound.x1; x++) {
            float dx = derivX.getF(indexDX++);
            float dy = derivY.getF(indexDY++);
            // edge intensity and angle
            double magnitude = Math.sqrt(dx * dx + dy * dy);
            double theta = UtilAngle.domain2PI(Math.atan2(dy, dx));
            // weight from gaussian
            double weight = computeWeight(x - c_x, y - c_y, sigma);
            // histogram index
            int h = (int) (theta / histAngleBin) % histogramMag.length;
            // update the histogram
            histogramMag[h] += magnitude * weight;
            histogramX[h] += dx * weight;
            histogramY[h] += dy * weight;
        }
    }
}
Also used : FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray) GImageGray(boofcv.core.image.GImageGray)

Example 57 with ImageGray

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

the class TestGlobalEntropyBinaryFilter method compare.

@Test
public void compare() {
    Class[] imageTypes = new Class[] { GrayU8.class, GrayF32.class };
    for (Class type : imageTypes) {
        ImageGray input = GeneralizedImageOps.createSingleBand(type, 30, 40);
        GrayU8 found = new GrayU8(30, 40);
        GrayU8 expected = new GrayU8(30, 40);
        GImageMiscOps.fillUniform(input, rand, 0, 200);
        GlobalEntropyBinaryFilter alg = new GlobalEntropyBinaryFilter(0, 255, true, ImageType.single(type));
        alg.process(input, found);
        double threshold = GThresholdImageOps.computeEntropy(input, 0, 255);
        GThresholdImageOps.threshold(input, expected, threshold, true);
        BoofTesting.assertEquals(found, expected, 0);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) GrayU8(boofcv.struct.image.GrayU8) ImageGray(boofcv.struct.image.ImageGray) Test(org.junit.Test)

Example 58 with ImageGray

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

the class TestGlobalFixedBinaryFilter method compare.

@Test
public void compare() {
    Class[] imageTypes = new Class[] { GrayU8.class, GrayF32.class };
    for (Class type : imageTypes) {
        ImageGray input = GeneralizedImageOps.createSingleBand(type, 30, 40);
        GrayU8 found = new GrayU8(30, 40);
        GrayU8 expected = new GrayU8(30, 40);
        GImageMiscOps.fillUniform(input, rand, 0, 200);
        GlobalFixedBinaryFilter alg = new GlobalFixedBinaryFilter(120, true, ImageType.single(type));
        alg.process(input, found);
        GThresholdImageOps.threshold(input, expected, 120, true);
        BoofTesting.assertEquals(found, expected, 0);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) GrayU8(boofcv.struct.image.GrayU8) ImageGray(boofcv.struct.image.ImageGray) Test(org.junit.Test)

Example 59 with ImageGray

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

the class TestLocalGaussianBinaryFilter method compare.

@Test
public void compare() {
    Class[] imageTypes = new Class[] { GrayU8.class, GrayF32.class };
    for (Class type : imageTypes) {
        ImageGray input = GeneralizedImageOps.createSingleBand(type, 30, 40);
        GrayU8 found = new GrayU8(30, 40);
        GrayU8 expected = new GrayU8(30, 40);
        GImageMiscOps.fillUniform(input, rand, 0, 200);
        LocalGaussianBinaryFilter alg = new LocalGaussianBinaryFilter(ConfigLength.fixed(9), 0.95, true, ImageType.single(type));
        alg.process(input, found);
        GThresholdImageOps.localGaussian(input, expected, ConfigLength.fixed(9), 0.95, true, null, null);
        BoofTesting.assertEquals(found, expected, 0);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) GrayU8(boofcv.struct.image.GrayU8) ImageGray(boofcv.struct.image.ImageGray) Test(org.junit.Test)

Example 60 with ImageGray

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

the class TestLocalMeanBinaryFilter method compare.

@Test
public void compare() {
    Class[] imageTypes = new Class[] { GrayU8.class, GrayF32.class };
    for (Class type : imageTypes) {
        ImageGray input = GeneralizedImageOps.createSingleBand(type, 30, 40);
        GrayU8 found = new GrayU8(30, 40);
        GrayU8 expected = new GrayU8(30, 40);
        GImageMiscOps.fillUniform(input, rand, 0, 200);
        LocalMeanBinaryFilter alg = new LocalMeanBinaryFilter(ConfigLength.fixed(9), 0.95, true, ImageType.single(type));
        alg.process(input, found);
        GThresholdImageOps.localMean(input, expected, ConfigLength.fixed(9), 0.95, true, null, null);
        BoofTesting.assertEquals(found, expected, 0);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) GrayU8(boofcv.struct.image.GrayU8) ImageGray(boofcv.struct.image.ImageGray) Test(org.junit.Test)

Aggregations

ImageGray (boofcv.struct.image.ImageGray)110 FactoryGImageGray (boofcv.core.image.FactoryGImageGray)43 GImageGray (boofcv.core.image.GImageGray)43 Test (org.junit.Test)26 GrayF32 (boofcv.struct.image.GrayF32)20 Method (java.lang.reflect.Method)17 GrayU8 (boofcv.struct.image.GrayU8)15 Bitmap (android.graphics.Bitmap)4 ImageBorder_S32 (boofcv.core.image.border.ImageBorder_S32)4 GrayS16 (boofcv.struct.image.GrayS16)4 GrayS32 (boofcv.struct.image.GrayS32)4 Planar (boofcv.struct.image.Planar)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 IntegralKernel (boofcv.alg.transform.ii.IntegralKernel)3 ImageRectangle (boofcv.struct.ImageRectangle)3 FDistort (boofcv.abst.distort.FDistort)2 ImageBorder_F32 (boofcv.core.image.border.ImageBorder_F32)2 FactoryDescribeImageDense (boofcv.factory.feature.dense.FactoryDescribeImageDense)2 Kernel2D_S32 (boofcv.struct.convolve.Kernel2D_S32)2 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)2