Search in sources :

Example 91 with GrayF32

use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.

the class ExampleWebcamGradient method main.

public static void main(String[] args) {
    // Open a webcam at a resolution close to 640x480
    Webcam webcam = UtilWebcamCapture.openDefault(640, 480);
    // Create the panel used to display the image and
    ImagePanel gui = new ImagePanel();
    Dimension viewSize = webcam.getViewSize();
    gui.setPreferredSize(viewSize);
    // Predeclare storage for the gradient
    GrayF32 derivX = new GrayF32((int) viewSize.getWidth(), (int) viewSize.getHeight());
    GrayF32 derivY = new GrayF32((int) viewSize.getWidth(), (int) viewSize.getHeight());
    ShowImages.showWindow(gui, "Gradient", true);
    for (; ; ) {
        BufferedImage image = webcam.getImage();
        GrayF32 gray = ConvertBufferedImage.convertFrom(image, (GrayF32) null);
        // compute the gradient
        GImageDerivativeOps.gradient(DerivativeType.SOBEL, gray, derivX, derivY, BorderType.EXTENDED);
        // visualize and display
        BufferedImage visualized = VisualizeImageData.colorizeGradient(derivX, derivY, -1);
        gui.setImageUI(visualized);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Webcam(com.github.sarxos.webcam.Webcam) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ImagePanel(boofcv.gui.image.ImagePanel)

Example 92 with GrayF32

use of boofcv.struct.image.GrayF32 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 93 with GrayF32

use of boofcv.struct.image.GrayF32 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 94 with GrayF32

use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.

the class ExamplePointDeformKeyPoints method main.

public static void main(String[] args) {
    BufferedImage orig = UtilImageIO.loadImage(UtilIO.pathExample("standard/man_mls.jpg"));
    BufferedImage bufferedOut = new BufferedImage(orig.getWidth(), orig.getHeight(), BufferedImage.TYPE_INT_RGB);
    Planar<GrayF32> input = ConvertBufferedImage.convertFrom(orig, true, ImageType.pl(3, GrayF32.class));
    Planar<GrayF32> output = input.createSameShape();
    List<Point2D_F32> src = new ArrayList<>();
    List<Point2D_F32> dst = new ArrayList<>();
    src.add(new Point2D_F32(64, 241));
    src.add(new Point2D_F32(266, 119));
    src.add(new Point2D_F32(265, 240));
    src.add(new Point2D_F32(208, 410));
    src.add(new Point2D_F32(181, 536));
    src.add(new Point2D_F32(335, 409));
    src.add(new Point2D_F32(375, 531));
    src.add(new Point2D_F32(473, 238));
    for (Point2D_F32 p : src) {
        dst.add(p.copy());
    }
    ConfigDeformPointMLS config = new ConfigDeformPointMLS();
    PointDeformKeyPoints deform = FactoryDistort.deformMls(config);
    deform.setImageShape(input.width, input.height);
    ImageDistort<Planar<GrayF32>, Planar<GrayF32>> distorter = FactoryDistort.distort(true, InterpolationType.BILINEAR, BorderType.ZERO, input.getImageType(), input.getImageType());
    deform.setImageShape(input.width, input.height);
    deform.setSource(src);
    deform.setDestination(dst);
    ConvertBufferedImage.convertTo(output, bufferedOut, true);
    ImagePanel panel = ShowImages.showWindow(bufferedOut, "Point Based Distortion Animation", true);
    int count = 0;
    while (true) {
        // specify new locations of key points
        double theta = count++ * Math.PI / 30;
        // right arm
        dst.get(7).y = (float) (238 + Math.sin(theta) * 30);
        // left arm
        dst.get(0).y = (float) (241 - Math.sin(theta * 2.0) * 20);
        // head
        dst.get(1).x = (float) (266 + Math.sin(theta * 0.25) * 10);
        // tell the deformation algorithm that destination points have changed
        deform.setDestination(dst);
        // Tell the distorter that the model has changed. If cached is set to false you can ignore this step
        distorter.setModel(new PointToPixelTransform_F32(deform));
        // distort the image
        distorter.apply(input, output);
        // Show the results
        ConvertBufferedImage.convertTo(output, bufferedOut, true);
        panel.repaint();
        BoofMiscOps.sleep(30);
    }
}
Also used : ArrayList(java.util.ArrayList) PointDeformKeyPoints(boofcv.abst.distort.PointDeformKeyPoints) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ConfigDeformPointMLS(boofcv.abst.distort.ConfigDeformPointMLS) GrayF32(boofcv.struct.image.GrayF32) PointToPixelTransform_F32(boofcv.alg.distort.PointToPixelTransform_F32) Planar(boofcv.struct.image.Planar) Point2D_F32(georegression.struct.point.Point2D_F32) ImagePanel(boofcv.gui.image.ImagePanel)

Example 95 with GrayF32

use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.

the class ExamplePyramidFloat method main.

public static void main(String[] args) {
    BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample("standard/barbara.jpg"));
    ExamplePyramidFloat<GrayF32> app = new ExamplePyramidFloat<>(GrayF32.class);
    // ExamplePyramidFloat<GrayU8> app = new ExamplePyramidFloat<>(GrayU8.class);
    app.standard();
    app.process(image);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Aggregations

GrayF32 (boofcv.struct.image.GrayF32)530 Test (org.junit.Test)291 BufferedImage (java.awt.image.BufferedImage)81 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)76 GrayU8 (boofcv.struct.image.GrayU8)49 Planar (boofcv.struct.image.Planar)34 ArrayList (java.util.ArrayList)28 ImageBorder_F32 (boofcv.core.image.border.ImageBorder_F32)20 ImageGray (boofcv.struct.image.ImageGray)20 File (java.io.File)20 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)19 Se3_F64 (georegression.struct.se.Se3_F64)18 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)17 GrayS8 (boofcv.struct.image.GrayS8)16 ListDisplayPanel (boofcv.gui.ListDisplayPanel)14 PathLabel (boofcv.io.PathLabel)14 Kernel2D_F32 (boofcv.struct.convolve.Kernel2D_F32)13 GrayS16 (boofcv.struct.image.GrayS16)13 GrayS32 (boofcv.struct.image.GrayS32)13 Point2D_F64 (georegression.struct.point.Point2D_F64)13