Search in sources :

Example 1 with Histogram_F64

use of boofcv.alg.feature.color.Histogram_F64 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 2 with Histogram_F64

use of boofcv.alg.feature.color.Histogram_F64 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

Histogram_F64 (boofcv.alg.feature.color.Histogram_F64)2 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)2 GrayF32 (boofcv.struct.image.GrayF32)2 Planar (boofcv.struct.image.Planar)2 BufferedImage (java.awt.image.BufferedImage)2 File (java.io.File)2