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");
}
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);
}
}
}
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);
}
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;
}
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;
}
Aggregations