use of boofcv.struct.image.GrayF32 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.GrayF32 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;
}
use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.
the class ExampleImageClassification method main.
public static void main(String[] args) throws IOException {
// Test set 89.9% for 10 categories
ClassifierAndSource cs = FactoryImageClassifier.vgg_cifar10();
// ClassifierAndSource cs = FactoryImageClassifier.nin_imagenet(); // Test set 62.6% for 1000 categories
File path = DeepBoofDataBaseOps.downloadModel(cs.getSource(), new File("download_data"));
ImageClassifier<Planar<GrayF32>> classifier = cs.getClassifier();
classifier.loadModel(path);
List<String> categories = classifier.getCategories();
String imagePath = UtilIO.pathExample("recognition/pixabay");
List<File> images = Arrays.asList(UtilIO.findMatches(new File(imagePath), "\\w*.jpg"));
Collections.sort(images);
ImageClassificationPanel gui = new ImageClassificationPanel();
ShowImages.showWindow(gui, "Image Classification", true);
for (File f : images) {
BufferedImage buffered = UtilImageIO.loadImage(f.getPath());
if (buffered == null)
throw new RuntimeException("Couldn't find input image");
Planar<GrayF32> image = new Planar<>(GrayF32.class, buffered.getWidth(), buffered.getHeight(), 3);
ConvertBufferedImage.convertFromPlanar(buffered, image, true, GrayF32.class);
classifier.classify(image);
// add image and results to the GUI for display
gui.addImage(buffered, f.getName(), classifier.getAllResults(), categories);
}
}
use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.
the class ExampleMultiviewSceneReconstruction method detectFeatures.
/**
* Detects image features. Saves their location, description, and pixel color
*/
private void detectFeatures(BufferedImage colorImage, FastQueue<BrightFeature> features, FastQueue<Point2D_F64> pixels, GrowQueue_I32 colors) {
GrayF32 image = ConvertBufferedImage.convertFrom(colorImage, (GrayF32) null);
features.reset();
pixels.reset();
colors.reset();
detDesc.detect(image);
for (int i = 0; i < detDesc.getNumberOfFeatures(); i++) {
Point2D_F64 p = detDesc.getLocation(i);
features.grow().set(detDesc.getDescription(i));
// store pixels are normalized image coordinates
pixelToNorm.compute(p.x, p.y, pixels.grow());
colors.add(colorImage.getRGB((int) p.x, (int) p.y));
}
}
use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.
the class ExampleTrackingKlt method main.
public static void main(String[] args) {
// tune the tracker for the image size and visual appearance
ConfigGeneralDetector configDetector = new ConfigGeneralDetector(-1, 8, 1);
PkltConfig configKlt = new PkltConfig(3, new int[] { 1, 2, 4, 8 });
PointTracker<GrayF32> tracker = FactoryPointTracker.klt(configKlt, configDetector, GrayF32.class, null);
// Open a webcam at a resolution close to 640x480
Webcam webcam = UtilWebcamCapture.openDefault(640, 480);
// Create the panel used to display the image and feature tracks
ImagePanel gui = new ImagePanel();
gui.setPreferredSize(webcam.getViewSize());
ShowImages.showWindow(gui, "KLT Tracker", true);
int minimumTracks = 100;
while (true) {
BufferedImage image = webcam.getImage();
GrayF32 gray = ConvertBufferedImage.convertFrom(image, (GrayF32) null);
tracker.process(gray);
List<PointTrack> tracks = tracker.getActiveTracks(null);
// Spawn tracks if there are too few
if (tracks.size() < minimumTracks) {
tracker.spawnTracks();
tracks = tracker.getActiveTracks(null);
minimumTracks = tracks.size() / 2;
}
// Draw the tracks
Graphics2D g2 = image.createGraphics();
for (PointTrack t : tracks) {
VisualizeFeatures.drawPoint(g2, (int) t.x, (int) t.y, Color.RED);
}
gui.setImageUI(image);
}
}
Aggregations