Search in sources :

Example 6 with ListDisplayPanel

use of boofcv.gui.ListDisplayPanel in project BoofCV by lessthanoptimal.

the class ExampleColorHistogramLookup method main.

public static void main(String[] args) {
    String imagePath = UtilIO.pathExample("recognition/vacation");
    List<File> images = Arrays.asList(UtilIO.findMatches(new File(imagePath), "\\w*.jpg"));
    Collections.sort(images);
    // Different color spaces you can try
    List<double[]> points = coupledHueSat(images);
    // List<double[]> points = independentHueSat(images);
    // List<double[]> points = coupledRGB(images);
    // List<double[]> points = histogramGray(images);
    // A few suggested image you can try searching for
    int target = 0;
    // int target = 28;
    // int target = 38;
    // int target = 46;
    // int target = 65;
    // int target = 77;
    double[] targetPoint = points.get(target);
    // Use a generic NN search algorithm.  This uses Euclidean distance as a distance metric.
    NearestNeighbor<File> nn = FactoryNearestNeighbor.exhaustive();
    FastQueue<NnData<File>> results = new FastQueue(NnData.class, true);
    nn.init(targetPoint.length);
    nn.setPoints(points, images);
    nn.findNearest(targetPoint, -1, 10, results);
    ListDisplayPanel gui = new ListDisplayPanel();
    // Add the target which the other images are being matched against
    gui.addImage(UtilImageIO.loadImage(images.get(target).getPath()), "Target", ScaleOptions.ALL);
    // The results will be the 10 best matches, but their order can be arbitrary.  For display purposes
    // it's better to do it from best fit to worst fit
    Collections.sort(results.toList(), new Comparator<NnData>() {

        @Override
        public int compare(NnData o1, NnData o2) {
            if (o1.distance < o2.distance)
                return -1;
            else if (o1.distance > o2.distance)
                return 1;
            else
                return 0;
        }
    });
    // Add images to GUI -- first match is always the target image, so skip it
    for (int i = 1; i < results.size; i++) {
        File file = results.get(i).data;
        double error = results.get(i).distance;
        BufferedImage image = UtilImageIO.loadImage(file.getPath());
        gui.addImage(image, String.format("Error %6.3f", error), ScaleOptions.ALL);
    }
    ShowImages.showWindow(gui, "Similar Images", true);
}
Also used : NnData(org.ddogleg.nn.NnData) ListDisplayPanel(boofcv.gui.ListDisplayPanel) FastQueue(org.ddogleg.struct.FastQueue) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) File(java.io.File)

Example 7 with ListDisplayPanel

use of boofcv.gui.ListDisplayPanel in project BoofCV by lessthanoptimal.

the class ExampleSegmentSuperpixels method visualize.

/**
 * Visualizes results three ways.  1) Colorized segmented image where each region is given a random color.
 * 2) Each pixel is assigned the mean color through out the region. 3) Black pixels represent the border
 * between regions.
 */
public static <T extends ImageBase<T>> void visualize(GrayS32 pixelToRegion, T color, int numSegments) {
    // Computes the mean color inside each region
    ImageType<T> type = color.getImageType();
    ComputeRegionMeanColor<T> colorize = FactorySegmentationAlg.regionMeanColor(type);
    FastQueue<float[]> segmentColor = new ColorQueue_F32(type.getNumBands());
    segmentColor.resize(numSegments);
    GrowQueue_I32 regionMemberCount = new GrowQueue_I32();
    regionMemberCount.resize(numSegments);
    ImageSegmentationOps.countRegionPixels(pixelToRegion, numSegments, regionMemberCount.data);
    colorize.process(color, pixelToRegion, regionMemberCount, segmentColor);
    // Draw each region using their average color
    BufferedImage outColor = VisualizeRegions.regionsColor(pixelToRegion, segmentColor, null);
    // Draw each region by assigning it a random color
    BufferedImage outSegments = VisualizeRegions.regions(pixelToRegion, numSegments, null);
    // Make region edges appear red
    BufferedImage outBorder = new BufferedImage(color.width, color.height, BufferedImage.TYPE_INT_RGB);
    ConvertBufferedImage.convertTo(color, outBorder, true);
    VisualizeRegions.regionBorders(pixelToRegion, 0xFF0000, outBorder);
    // Show the visualization results
    ListDisplayPanel gui = new ListDisplayPanel();
    gui.addImage(outColor, "Color of Segments");
    gui.addImage(outBorder, "Region Borders");
    gui.addImage(outSegments, "Regions");
    ShowImages.showWindow(gui, "Superpixels", true);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) ColorQueue_F32(boofcv.struct.feature.ColorQueue_F32) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32)

Example 8 with ListDisplayPanel

use of boofcv.gui.ListDisplayPanel 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 9 with ListDisplayPanel

use of boofcv.gui.ListDisplayPanel in project BoofCV by lessthanoptimal.

the class ExampleInterpolation method main.

public static void main(String[] args) {
    String imagePath;
    imagePath = "eye01.jpg";
    // imagePath = "small_sunflower.jpg";
    BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample(imagePath));
    ListDisplayPanel gui = new ListDisplayPanel();
    gui.addImage(buffered, "Original");
    // For sake of simplicity assume it's a gray scale image.  Interpolation functions exist for planar and
    // interleaved color images too
    GrayF32 input = ConvertBufferedImage.convertFrom(buffered, (GrayF32) null);
    GrayF32 scaled = input.createNew(500, 500 * input.height / input.width);
    for (InterpolationType type : InterpolationType.values()) {
        // Create the single band (gray scale) interpolation function for the input image
        InterpolatePixelS<GrayF32> interp = FactoryInterpolation.createPixelS(0, 255, type, BorderType.EXTENDED, input.getDataType());
        // Tell it which image is being interpolated
        interp.setImage(input);
        // the same thing and is slightly more efficient
        for (int y = 0; y < scaled.height; y++) {
            // iterate using the 1D index for added performance.  Altertively there is the set(x,y) operator
            int indexScaled = scaled.startIndex + y * scaled.stride;
            float origY = y * input.height / (float) scaled.height;
            for (int x = 0; x < scaled.width; x++) {
                float origX = x * input.width / (float) scaled.width;
                scaled.data[indexScaled++] = interp.get(origX, origY);
            }
        }
        // Add the results to the output
        BufferedImage out = ConvertBufferedImage.convertTo(scaled, null, true);
        gui.addImage(out, type.toString());
    }
    ShowImages.showWindow(gui, "Example Interpolation", true);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) GrayF32(boofcv.struct.image.GrayF32) InterpolationType(boofcv.alg.interpolate.InterpolationType) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 10 with ListDisplayPanel

use of boofcv.gui.ListDisplayPanel 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)

Aggregations

ListDisplayPanel (boofcv.gui.ListDisplayPanel)30 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)27 BufferedImage (java.awt.image.BufferedImage)27 GrayU8 (boofcv.struct.image.GrayU8)16 GrayF32 (boofcv.struct.image.GrayF32)14 File (java.io.File)6 CameraPinhole (boofcv.struct.calib.CameraPinhole)4 Planar (boofcv.struct.image.Planar)4 ConfigPolygonDetector (boofcv.factory.shape.ConfigPolygonDetector)3 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)2 FoundFiducial (boofcv.alg.fiducial.square.FoundFiducial)2 Contour (boofcv.alg.filter.binary.Contour)2 FactoryShapeDetector (boofcv.factory.shape.FactoryShapeDetector)2 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)2 StereoParameters (boofcv.struct.calib.StereoParameters)2 GrayS16 (boofcv.struct.image.GrayS16)2 GrayS32 (boofcv.struct.image.GrayS32)2 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)2 FDistort (boofcv.abst.distort.FDistort)1 ImageDistort (boofcv.alg.distort.ImageDistort)1