Search in sources :

Example 26 with ListDisplayPanel

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

the class ExampleNonMaximumSupression method main.

public static void main(String[] args) {
    BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample("standard/boat.jpg"));
    GrayF32 input = ConvertBufferedImage.convertFrom(buffered, (GrayF32) null);
    // Compute the image gradient
    GrayF32 derivX = input.createSameShape();
    GrayF32 derivY = input.createSameShape();
    GImageDerivativeOps.gradient(DerivativeType.SOBEL, input, derivX, derivY, BorderType.EXTENDED);
    // From the gradient compute intensity of shi-tomasi features
    GeneralFeatureIntensity<GrayF32, GrayF32> featureIntensity = FactoryIntensityPoint.shiTomasi(3, false, GrayF32.class);
    featureIntensity.process(input, derivX, derivY, null, null, null);
    GrayF32 intensity = featureIntensity.getIntensity();
    ListDisplayPanel panel = new ListDisplayPanel();
    panel.addImage(buffered, "Input Image");
    // hack to just show intensity - no features can be detected
    panel.addImage(renderNonMax(intensity, 10, Float.MAX_VALUE), "Intensity Image");
    // Detect maximums with different settings and visualize the results
    panel.addImage(renderNonMax(intensity, 3, -Float.MAX_VALUE), "Radius 3");
    panel.addImage(renderNonMax(intensity, 3, 30000), "Radius 3  threshold");
    panel.addImage(renderNonMax(intensity, 20, -Float.MAX_VALUE), "Radius 10");
    panel.addImage(renderNonMax(intensity, 20, 30000), "Radius 10 threshold");
    ShowImages.showWindow(panel, "Non-Maximum Suppression", true);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ListDisplayPanel(boofcv.gui.ListDisplayPanel) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 27 with ListDisplayPanel

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

the class ExampleCannyEdge method main.

public static void main(String[] args) {
    BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample("simple_objects.jpg"));
    GrayU8 gray = ConvertBufferedImage.convertFrom(image, (GrayU8) null);
    GrayU8 edgeImage = gray.createSameShape();
    // Create a canny edge detector which will dynamically compute the threshold based on maximum edge intensity
    // It has also been configured to save the trace as a graph.  This is the graph created while performing
    // hysteresis thresholding.
    CannyEdge<GrayU8, GrayS16> canny = FactoryEdgeDetectors.canny(2, true, true, GrayU8.class, GrayS16.class);
    // The edge image is actually an optional parameter.  If you don't need it just pass in null
    canny.process(gray, 0.1f, 0.3f, edgeImage);
    // First get the contour created by canny
    List<EdgeContour> edgeContours = canny.getContours();
    // The 'edgeContours' is a tree graph that can be difficult to process.  An alternative is to extract
    // the contours from the binary image, which will produce a single loop for each connected cluster of pixels.
    // Note that you are only interested in external contours.
    List<Contour> contours = BinaryImageOps.contour(edgeImage, ConnectRule.EIGHT, null);
    // display the results
    BufferedImage visualBinary = VisualizeBinaryData.renderBinary(edgeImage, false, null);
    BufferedImage visualCannyContour = VisualizeBinaryData.renderContours(edgeContours, null, gray.width, gray.height, null);
    BufferedImage visualEdgeContour = new BufferedImage(gray.width, gray.height, BufferedImage.TYPE_INT_RGB);
    VisualizeBinaryData.render(contours, (int[]) null, visualEdgeContour);
    ListDisplayPanel panel = new ListDisplayPanel();
    panel.addImage(visualBinary, "Binary Edges from Canny");
    panel.addImage(visualCannyContour, "Canny Trace Graph");
    panel.addImage(visualEdgeContour, "Contour from Canny Binary");
    ShowImages.showWindow(panel, "Canny Edge", true);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) Contour(boofcv.alg.filter.binary.Contour) EdgeContour(boofcv.alg.feature.detect.edge.EdgeContour) GrayS16(boofcv.struct.image.GrayS16) GrayU8(boofcv.struct.image.GrayU8) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) EdgeContour(boofcv.alg.feature.detect.edge.EdgeContour)

Example 28 with ListDisplayPanel

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

the class ExampleDetectBlackEllipse method main.

public static void main(String[] args) {
    String[] images = new String[] { "shapes/polygons01.jpg", "shapes/shapes02.png", "fiducial/circle_hexagonal/image00.jpg", "fiducial/circle_hexagonal/image01.jpg" };
    ListDisplayPanel panel = new ListDisplayPanel();
    BinaryEllipseDetector<GrayU8> detector = FactoryShapeDetector.ellipse(null, GrayU8.class);
    for (String fileName : images) {
        BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample(fileName));
        GrayU8 input = ConvertBufferedImage.convertFromSingle(image, null, GrayU8.class);
        GrayU8 binary = new GrayU8(input.width, input.height);
        // Binarization is done outside to allows creative tricks.  For example, when applied to a chessboard
        // pattern where square touch each other, the binary image is eroded first so that they don't touch.
        // The squares are expanded automatically during the subpixel optimization step.
        int threshold = (int) GThresholdImageOps.computeOtsu(input, 0, 255);
        ThresholdImageOps.threshold(input, binary, threshold, true);
        // it takes in a grey scale image and binary image
        // the binary image is used to do a crude polygon fit, then the grey image is used to refine the lines
        // using a sub-pixel algorithm
        detector.process(input, binary);
        // visualize results by drawing red polygons
        FastQueue<BinaryEllipseDetector.EllipseInfo> found = detector.getFound();
        Graphics2D g2 = image.createGraphics();
        g2.setStroke(new BasicStroke(3));
        g2.setColor(Color.RED);
        for (int i = 0; i < found.size; i++) {
            VisualizeShapes.drawEllipse(found.get(i).ellipse, g2);
        }
        panel.addImage(image, new File(fileName).getName());
    }
    ShowImages.showWindow(panel, "Detected Ellipses", true);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) GrayU8(boofcv.struct.image.GrayU8) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 29 with ListDisplayPanel

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

the class ExampleBinaryOps method main.

public static void main(String[] args) {
    // load and convert the image into a usable format
    BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample("particles01.jpg"));
    // convert into a usable format
    GrayF32 input = ConvertBufferedImage.convertFromSingle(image, null, GrayF32.class);
    GrayU8 binary = new GrayU8(input.width, input.height);
    GrayS32 label = new GrayS32(input.width, input.height);
    // Select a global threshold using Otsu's method.
    double threshold = GThresholdImageOps.computeOtsu(input, 0, 255);
    // Apply the threshold to create a binary image
    ThresholdImageOps.threshold(input, binary, (float) threshold, true);
    // remove small blobs through erosion and dilation
    // The null in the input indicates that it should internally declare the work image it needs
    // this is less efficient, but easier to code.
    GrayU8 filtered = BinaryImageOps.erode8(binary, 1, null);
    filtered = BinaryImageOps.dilate8(filtered, 1, null);
    // Detect blobs inside the image using an 8-connect rule
    List<Contour> contours = BinaryImageOps.contour(filtered, ConnectRule.EIGHT, label);
    // colors of contours
    int colorExternal = 0xFFFFFF;
    int colorInternal = 0xFF2020;
    // display the results
    BufferedImage visualBinary = VisualizeBinaryData.renderBinary(binary, false, null);
    BufferedImage visualFiltered = VisualizeBinaryData.renderBinary(filtered, false, null);
    BufferedImage visualLabel = VisualizeBinaryData.renderLabeledBG(label, contours.size(), null);
    BufferedImage visualContour = VisualizeBinaryData.renderContours(contours, colorExternal, colorInternal, input.width, input.height, null);
    ListDisplayPanel panel = new ListDisplayPanel();
    panel.addImage(visualBinary, "Binary Original");
    panel.addImage(visualFiltered, "Binary Filtered");
    panel.addImage(visualLabel, "Labeled Blobs");
    panel.addImage(visualContour, "Contours");
    ShowImages.showWindow(panel, "Binary Operations", true);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ListDisplayPanel(boofcv.gui.ListDisplayPanel) Contour(boofcv.alg.filter.binary.Contour) GrayU8(boofcv.struct.image.GrayU8) GrayS32(boofcv.struct.image.GrayS32) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 30 with ListDisplayPanel

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

the class ExampleEquirectangularToPinhole method main.

public static void main(String[] args) {
    // Specify what the pinhole camera should look like
    CameraPinhole pinholeModel = new CameraPinhole(200, 200, 0, 250, 250, 500, 500);
    // Load equirectangular RGB image
    BufferedImage bufferedEqui = UtilImageIO.loadImage(UtilIO.pathExample("spherical/equirectangular_half_dome_01.jpg"));
    Planar<GrayU8> equiImage = ConvertBufferedImage.convertFrom(bufferedEqui, true, ImageType.pl(3, GrayU8.class));
    // Declare storage for pinhole camera image
    Planar<GrayU8> pinholeImage = equiImage.createNew(pinholeModel.width, pinholeModel.height);
    // Create the image distorter which will render the image
    InterpolatePixel<Planar<GrayU8>> interp = FactoryInterpolation.createPixel(0, 255, InterpolationType.BILINEAR, BorderType.EXTENDED, equiImage.getImageType());
    ImageDistort<Planar<GrayU8>, Planar<GrayU8>> distorter = FactoryDistort.distort(false, interp, equiImage.getImageType());
    // This is where the magic is done.  It defines the transform rfom equirectangular to pinhole
    PinholeToEquirectangular_F32 pinholeToEqui = new PinholeToEquirectangular_F32();
    pinholeToEqui.setEquirectangularShape(equiImage.width, equiImage.height);
    pinholeToEqui.setPinhole(pinholeModel);
    // Pass in the transform to the image distorter
    distorter.setModel(pinholeToEqui);
    // change the orientation of the camera to make the view better
    ConvertRotation3D_F32.eulerToMatrix(EulerType.YXZ, 0, 1.45f, 2.2f, pinholeToEqui.getRotation());
    // Render the image
    distorter.apply(equiImage, pinholeImage);
    BufferedImage bufferedPinhole0 = ConvertBufferedImage.convertTo(pinholeImage, null, true);
    // Let's look at another view
    ConvertRotation3D_F32.eulerToMatrix(EulerType.YXZ, 0, 1.25f, -1.25f, pinholeToEqui.getRotation());
    distorter.apply(equiImage, pinholeImage);
    BufferedImage bufferedPinhole1 = ConvertBufferedImage.convertTo(pinholeImage, null, true);
    // Display the results
    ListDisplayPanel panel = new ListDisplayPanel();
    panel.addImage(bufferedPinhole0, "Pinehole View 0");
    panel.addImage(bufferedPinhole1, "Pinehole View 1");
    panel.addImage(bufferedEqui, "Equirectangular");
    panel.setPreferredSize(new Dimension(equiImage.width, equiImage.height));
    ShowImages.showWindow(panel, "Equirectangular to Pinhole", true);
}
Also used : PinholeToEquirectangular_F32(boofcv.alg.distort.spherical.PinholeToEquirectangular_F32) ListDisplayPanel(boofcv.gui.ListDisplayPanel) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) CameraPinhole(boofcv.struct.calib.CameraPinhole) 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