Search in sources :

Example 6 with Planar

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

the class VisualizeAverageDownSample method main.

public static void main(String[] args) {
    BufferedImage original = UtilImageIO.loadImage(UtilIO.pathExample("simple_objects.jpg"));
    Planar<GrayF32> input = new Planar<>(GrayF32.class, original.getWidth(), original.getHeight(), 3);
    ConvertBufferedImage.convertFromPlanar(original, input, true, GrayF32.class);
    Planar<GrayF32> output = new Planar<>(GrayF32.class, original.getWidth() / 3, original.getHeight() / 3, 3);
    Planar<GrayF32> output2 = new Planar<>(GrayF32.class, original.getWidth() / 3, original.getHeight() / 3, 3);
    AverageDownSampleOps.down(input, output);
    new FDistort(input, output2).scaleExt().apply();
    BufferedImage outputFull = ConvertBufferedImage.convertTo_F32(output, null, true);
    BufferedImage outputFull2 = ConvertBufferedImage.convertTo_F32(output2, null, true);
    ShowImages.showWindow(original, "Original");
    ShowImages.showWindow(outputFull, "3x small average");
    ShowImages.showWindow(outputFull2, "3x small bilinear");
}
Also used : GrayF32(boofcv.struct.image.GrayF32) FDistort(boofcv.abst.distort.FDistort) Planar(boofcv.struct.image.Planar) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 7 with Planar

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

the class TestPixelMath method TestAverageBand.

private void TestAverageBand(Method m) throws InvocationTargetException, IllegalAccessException {
    Class[] paramTypes = m.getParameterTypes();
    Planar input = new Planar(paramTypes[1], width, height, 3);
    ImageGray output = GeneralizedImageOps.createSingleBand(paramTypes[1], width, height);
    if (output.getDataType().isSigned()) {
        GImageMiscOps.fillUniform(input, rand, -20, 20);
    } else {
        GImageMiscOps.fillUniform(input, rand, 0, 20);
    }
    m.invoke(null, input, output);
    GImageGray a = FactoryGImageGray.wrap(input.getBand(0));
    GImageGray b = FactoryGImageGray.wrap(input.getBand(1));
    GImageGray c = FactoryGImageGray.wrap(input.getBand(2));
    GImageGray d = FactoryGImageGray.wrap(output);
    boolean isInteger = output.getDataType().isInteger();
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            double expected = 0;
            expected += a.get(j, i).doubleValue();
            expected += b.get(j, i).doubleValue();
            expected += c.get(j, i).doubleValue();
            expected /= 3;
            double found = d.get(j, i).doubleValue();
            if (isInteger)
                expected = (int) expected;
            assertEquals(expected, found, 1e-4);
        }
    }
}
Also used : Planar(boofcv.struct.image.Planar) ImageGray(boofcv.struct.image.ImageGray)

Example 8 with Planar

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

the class TestGPixelMath method all_planar_images.

/**
 * Tests all functions with inputs from planar images
 */
@Test
public void all_planar_images() {
    int total = 0;
    Method[] methods = GPixelMath.class.getMethods();
    for (Method m : methods) {
        if (!Modifier.isStatic(m.getModifiers()))
            continue;
        Class[] param = m.getParameterTypes();
        if (param.length < 1)
            continue;
        // create input arguments
        Object[] inputs = new Object[param.length];
        for (int i = 0; i < inputs.length; i++) {
            if (param[i] == ImageBase.class) {
                inputs[i] = new Planar(GrayF32.class, width, height, 2);
                GImageMiscOps.fillUniform((ImageBase) inputs[i], rand, -100, 100);
            }
        }
        // specialized inputs for individual functions
        String name = m.getName();
        if (name.equals("divide") && param.length == 3) {
            if (!ImageBase.class.isAssignableFrom(param[1])) {
                inputs[1] = 3;
            }
        } else if (name.equals("divide") && param.length == 5) {
            inputs[1] = 3;
            inputs[2] = -1;
            inputs[3] = 5;
        } else if (name.equals("multiply") && param.length == 3) {
            if (!ImageBase.class.isAssignableFrom(param[1])) {
                inputs[1] = 3;
            }
        } else if (name.equals("multiply") && param.length == 5) {
            inputs[1] = 3;
            inputs[2] = -20;
            inputs[3] = 12;
        } else if (name.equals("plus") && param.length == 3) {
            inputs[1] = 3;
        } else if (name.equals("plus") && param.length == 5) {
            inputs[1] = 3;
            inputs[2] = -10;
            inputs[3] = 12;
        } else if (name.equals("minus") && param.length == 3) {
            boolean first = ImageBase.class.isAssignableFrom(param[0]);
            inputs[first ? 1 : 0] = 3;
        } else if (name.equals("minus") && param.length == 5) {
            boolean first = ImageBase.class.isAssignableFrom(param[0]);
            inputs[first ? 1 : 0] = 3;
            inputs[2] = -10;
            inputs[3] = 12;
        } else if (name.equals("boundImage")) {
            inputs[1] = 2;
            inputs[2] = 8;
        } else if (name.equals("averageBand")) {
            continue;
        }
        try {
            // create the expected results
            Object[] inputsByBand = copy(inputs);
            invokeByBand(m, inputsByBand);
            // invoke this function
            m.invoke(null, inputs);
            // compare against each other
            for (int i = 0; i < inputs.length; i++) {
                if (Planar.class == inputs[i].getClass()) {
                    BoofTesting.assertEquals((ImageBase) inputs[i], (ImageBase) inputsByBand[i], 1e-4);
                }
            }
            total++;
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
    assertEquals(21, total);
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) ImageBase(boofcv.struct.image.ImageBase) Test(org.junit.Test)

Example 9 with Planar

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

the class ExampleColorHistogramLookup method coupledHueSat.

/**
 * HSV stores color information in Hue and Saturation while intensity is in Value.  This computes a 2D histogram
 * from hue and saturation only, which makes it lighting independent.
 */
public static List<double[]> coupledHueSat(List<File> images) {
    List<double[]> points = new ArrayList<>();
    Planar<GrayF32> rgb = new Planar<>(GrayF32.class, 1, 1, 3);
    Planar<GrayF32> hsv = new Planar<>(GrayF32.class, 1, 1, 3);
    for (File f : images) {
        BufferedImage buffered = UtilImageIO.loadImage(f.getPath());
        if (buffered == null)
            throw new RuntimeException("Can't load image!");
        rgb.reshape(buffered.getWidth(), buffered.getHeight());
        hsv.reshape(buffered.getWidth(), buffered.getHeight());
        ConvertBufferedImage.convertFrom(buffered, rgb, true);
        ColorHsv.rgbToHsv_F32(rgb, hsv);
        Planar<GrayF32> hs = hsv.partialSpectrum(0, 1);
        // The number of bins is an important parameter.  Try adjusting it
        Histogram_F64 histogram = new Histogram_F64(12, 12);
        // range of hue is from 0 to 2PI
        histogram.setRange(0, 0, 2.0 * Math.PI);
        // range of saturation is from 0 to 1
        histogram.setRange(1, 0, 1.0);
        // Compute the histogram
        GHistogramFeatureOps.histogram(hs, histogram);
        // normalize so that image size doesn't matter
        UtilFeature.normalizeL2(histogram);
        points.add(histogram.value);
    }
    return points;
}
Also used : Histogram_F64(boofcv.alg.feature.color.Histogram_F64) GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 10 with Planar

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

the class ExampleColorHistogramLookup method coupledRGB.

/**
 * Constructs a 3D histogram using RGB.  RGB is a popular color space, but the resulting histogram will
 * depend on lighting conditions and might not produce the accurate results.
 */
public static List<double[]> coupledRGB(List<File> images) {
    List<double[]> points = new ArrayList<>();
    Planar<GrayF32> rgb = new Planar<>(GrayF32.class, 1, 1, 3);
    for (File f : images) {
        BufferedImage buffered = UtilImageIO.loadImage(f.getPath());
        if (buffered == null)
            throw new RuntimeException("Can't load image!");
        rgb.reshape(buffered.getWidth(), buffered.getHeight());
        ConvertBufferedImage.convertFrom(buffered, rgb, true);
        // The number of bins is an important parameter.  Try adjusting it
        Histogram_F64 histogram = new Histogram_F64(10, 10, 10);
        histogram.setRange(0, 0, 255);
        histogram.setRange(1, 0, 255);
        histogram.setRange(2, 0, 255);
        GHistogramFeatureOps.histogram(rgb, histogram);
        // normalize so that image size doesn't matter
        UtilFeature.normalizeL2(histogram);
        points.add(histogram.value);
    }
    return points;
}
Also used : Histogram_F64(boofcv.alg.feature.color.Histogram_F64) GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Aggregations

Planar (boofcv.struct.image.Planar)73 Test (org.junit.Test)39 GrayF32 (boofcv.struct.image.GrayF32)34 GrayU8 (boofcv.struct.image.GrayU8)28 BufferedImage (java.awt.image.BufferedImage)21 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)20 RectangleLength2D_I32 (georegression.struct.shapes.RectangleLength2D_I32)12 File (java.io.File)9 Bitmap (android.graphics.Bitmap)4 ListDisplayPanel (boofcv.gui.ListDisplayPanel)4 ImageGray (boofcv.struct.image.ImageGray)4 ConfigGeneralDetector (boofcv.abst.feature.detect.interest.ConfigGeneralDetector)3 LensDistortionUniversalOmni (boofcv.alg.distort.universal.LensDistortionUniversalOmni)3 MediaManager (boofcv.io.MediaManager)3 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)3 CameraPinhole (boofcv.struct.calib.CameraPinhole)3 GrayU16 (boofcv.struct.image.GrayU16)3 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)3 Se3_F64 (georegression.struct.se.Se3_F64)3 DescribeRegionPoint (boofcv.abst.feature.describe.DescribeRegionPoint)2