Search in sources :

Example 71 with GrayU8

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;
}
Also used : TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) GrayU8(boofcv.struct.image.GrayU8) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 72 with GrayU8

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!");
}
Also used : ConfigBackgroundBasic(boofcv.factory.background.ConfigBackgroundBasic) SimpleImageSequence(boofcv.io.image.SimpleImageSequence) BufferedImage(java.awt.image.BufferedImage) ImageType(boofcv.struct.image.ImageType) BackgroundModelStationary(boofcv.alg.background.BackgroundModelStationary) MediaManager(boofcv.io.MediaManager) DefaultMediaManager(boofcv.io.wrapper.DefaultMediaManager) ConfigBackgroundGmm(boofcv.factory.background.ConfigBackgroundGmm) GrayU8(boofcv.struct.image.GrayU8) ImageGridPanel(boofcv.gui.image.ImageGridPanel) ImageBase(boofcv.struct.image.ImageBase)

Example 73 with GrayU8

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);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 74 with GrayU8

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);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) GrayF32(boofcv.struct.image.GrayF32) GrayU8(boofcv.struct.image.GrayU8) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 75 with GrayU8

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");
}
Also used : GrayU8(boofcv.struct.image.GrayU8) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Aggregations

GrayU8 (boofcv.struct.image.GrayU8)417 Test (org.junit.Test)242 BufferedImage (java.awt.image.BufferedImage)53 GrayS32 (boofcv.struct.image.GrayS32)52 GrayF32 (boofcv.struct.image.GrayF32)49 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)48 GrayS16 (boofcv.struct.image.GrayS16)45 Planar (boofcv.struct.image.Planar)28 ArrayList (java.util.ArrayList)22 File (java.io.File)17 ListDisplayPanel (boofcv.gui.ListDisplayPanel)16 RectangleLength2D_I32 (georegression.struct.shapes.RectangleLength2D_I32)16 ImageGray (boofcv.struct.image.ImageGray)15 EllipseRotated_F64 (georegression.struct.curve.EllipseRotated_F64)15 Random (java.util.Random)14 Point2D_F64 (georegression.struct.point.Point2D_F64)11 ImageRectangle (boofcv.struct.ImageRectangle)10 GrayU16 (boofcv.struct.image.GrayU16)10 Se3_F64 (georegression.struct.se.Se3_F64)10 Point3D_F64 (georegression.struct.point.Point3D_F64)9