use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.
the class ExampleColorHistogramLookup method histogramGray.
/**
* Computes a histogram from the gray scale intensity image alone. Probably the least effective at looking up
* similar images.
*/
public static List<double[]> histogramGray(List<File> images) {
List<double[]> points = new ArrayList<>();
GrayU8 gray = new GrayU8(1, 1);
for (File f : images) {
BufferedImage buffered = UtilImageIO.loadImage(f.getPath());
if (buffered == null)
throw new RuntimeException("Can't load image!");
gray.reshape(buffered.getWidth(), buffered.getHeight());
ConvertBufferedImage.convertFrom(buffered, gray, true);
TupleDesc_F64 imageHist = new TupleDesc_F64(150);
HistogramFeatureOps.histogram(gray, 255, imageHist);
// normalize so that image size doesn't matter
UtilFeature.normalizeL2(imageHist);
points.add(imageHist.value);
}
return points;
}
use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.
the class ExampleBackgroundRemovalStationary method main.
public static void main(String[] args) {
String fileName = UtilIO.pathExample("background/street_intersection.mp4");
// String fileName = UtilIO.pathExample("background/rubixfire.mp4"); // dynamic background
// String fileName = UtilIO.pathExample("background/horse_jitter.mp4"); // degraded performance because of jitter
// String fileName = UtilIO.pathExample("tracking/chipmunk.mjpeg"); // Camera moves. Stationary will fail here
// Comment/Uncomment to switch input image type
ImageType imageType = ImageType.single(GrayF32.class);
// ImageType imageType = ImageType.il(3, InterleavedF32.class);
// ImageType imageType = ImageType.il(3, InterleavedU8.class);
ConfigBackgroundGmm configGmm = new ConfigBackgroundGmm();
// Comment/Uncomment to switch algorithms
BackgroundModelStationary background = FactoryBackgroundModel.stationaryBasic(new ConfigBackgroundBasic(35, 0.005f), imageType);
// FactoryBackgroundModel.stationaryGmm(configGmm, imageType);
MediaManager media = DefaultMediaManager.INSTANCE;
SimpleImageSequence video = media.openVideo(fileName, background.getImageType());
// media.openCamera(null,640,480,background.getImageType());
// Declare storage for segmented image. 1 = moving foreground and 0 = background
GrayU8 segmented = new GrayU8(video.getNextWidth(), video.getNextHeight());
BufferedImage visualized = new BufferedImage(segmented.width, segmented.height, BufferedImage.TYPE_INT_RGB);
ImageGridPanel gui = new ImageGridPanel(1, 2);
gui.setImages(visualized, visualized);
ShowImages.showWindow(gui, "Static Scene: Background Segmentation", true);
double fps = 0;
// smoothing factor for FPS
double alpha = 0.01;
while (video.hasNext()) {
ImageBase input = video.next();
long before = System.nanoTime();
background.updateBackground(input, segmented);
long after = System.nanoTime();
fps = (1.0 - alpha) * fps + alpha * (1.0 / ((after - before) / 1e9));
VisualizeBinaryData.renderBinary(segmented, false, visualized);
gui.setImage(0, 0, (BufferedImage) video.getGuiImage());
gui.setImage(0, 1, visualized);
gui.repaint();
System.out.println("FPS = " + fps);
try {
Thread.sleep(5);
} catch (InterruptedException e) {
}
}
System.out.println("done!");
}
use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.
the class ExampleImageBlur method main.
public static void main(String[] args) {
ListDisplayPanel panel = new ListDisplayPanel();
BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample("sunflowers.jpg"));
panel.addImage(buffered, "Original");
Planar<GrayU8> input = ConvertBufferedImage.convertFrom(buffered, true, ImageType.pl(3, GrayU8.class));
Planar<GrayU8> blurred = input.createSameShape();
// size of the blur kernel. square region with a width of radius*2 + 1
int radius = 8;
// Apply gaussian blur using a procedural interface
GBlurImageOps.gaussian(input, blurred, -1, radius, null);
panel.addImage(ConvertBufferedImage.convertTo(blurred, null, true), "Gaussian");
// Apply a mean filter using an object oriented interface. This has the advantage of automatically
// recycling memory used in intermediate steps
BlurFilter<Planar<GrayU8>> filterMean = FactoryBlurFilter.mean(input.getImageType(), radius);
filterMean.process(input, blurred);
panel.addImage(ConvertBufferedImage.convertTo(blurred, null, true), "Mean");
// Apply a median filter using image type specific procedural interface. Won't work if the type
// isn't known at compile time
BlurImageOps.median(input, blurred, radius);
panel.addImage(ConvertBufferedImage.convertTo(blurred, null, true), "Median");
ShowImages.showWindow(panel, "Image Blur Examples", true);
}
use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.
the class ExampleMorphologicalThinning method main.
public static void main(String[] args) {
String[] images = new String[] { "drawings/drawing_text.png", "standard/fingerprint.jpg", "drawings/drawing_face.png" };
ListDisplayPanel uberPanel = new ListDisplayPanel();
for (String path : images) {
// load and convert the image into a usable format
BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample(path));
// convert into a usable format
GrayF32 input = ConvertBufferedImage.convertFromSingle(image, null, GrayF32.class);
GrayU8 binary = new GrayU8(input.width, input.height);
// Fixed threshold is best for B&W images, but the adaptive would improve results for the finger print
GThresholdImageOps.threshold(input, binary, 120, true);
// GThresholdImageOps.adaptiveSquare(input, binary, 20,0,true,null,null);
// Tell it to thin the image until there are no more changes
GrayU8 thinned = BinaryImageOps.thin(binary, -1, null);
// display the results
BufferedImage visualBinary = VisualizeBinaryData.renderBinary(binary, false, null);
BufferedImage visualThinned = VisualizeBinaryData.renderBinary(thinned, false, null);
ListDisplayPanel panel = new ListDisplayPanel();
panel.addImage(visualThinned, "Thinned");
panel.addImage(visualBinary, "Binary");
panel.addImage(image, "Original");
uberPanel.addItem(panel, new File(path).getName());
}
ShowImages.showWindow(uberPanel, "Thinned/Skeletonalized Images", true);
}
use of boofcv.struct.image.GrayU8 in project BoofCV by lessthanoptimal.
the class ExamplePlanarImages method convertToGray.
/**
* There is no real perfect way that everyone agrees on for converting color images into gray scale
* images. Two examples of how to convert a Planar image into a gray scale image are shown
* in this example.
*/
public static void convertToGray(BufferedImage input) {
// convert the BufferedImage into a Planar
Planar<GrayU8> image = ConvertBufferedImage.convertFromPlanar(input, null, true, GrayU8.class);
GrayU8 gray = new GrayU8(image.width, image.height);
// creates a gray scale image by averaging intensity value across pixels
GPixelMath.averageBand(image, gray);
BufferedImage outputAve = ConvertBufferedImage.convertTo(gray, null);
// convert to gray scale but weigh each color band based on how human vision works
ColorRgb.rgbToGray_Weighted(image, gray);
BufferedImage outputWeighted = ConvertBufferedImage.convertTo(gray, null);
// create an output image just from the first band
BufferedImage outputBand0 = ConvertBufferedImage.convertTo(image.getBand(0), null);
gui.addImage(outputAve, "Gray Averaged");
gui.addImage(outputWeighted, "Gray Weighted");
gui.addImage(outputBand0, "Band 0");
}
Aggregations