Search in sources :

Example 46 with GrayF32

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

the class VisualizeLineRansac method process.

public void process(BufferedImage image) {
    int regionSize = 40;
    I input = GeneralizedImageOps.createSingleBand(imageType, image.getWidth(), image.getHeight());
    D derivX = GeneralizedImageOps.createSingleBand(derivType, image.getWidth(), image.getHeight());
    D derivY = GeneralizedImageOps.createSingleBand(derivType, image.getWidth(), image.getHeight());
    GrayF32 edgeIntensity = new GrayF32(input.width, input.height);
    GrayF32 suppressed = new GrayF32(input.width, input.height);
    GrayF32 orientation = new GrayF32(input.width, input.height);
    GrayS8 direction = new GrayS8(input.width, input.height);
    GrayU8 detected = new GrayU8(input.width, input.height);
    ModelManager<LinePolar2D_F32> manager = new ModelManagerLinePolar2D_F32();
    GridLineModelDistance distance = new GridLineModelDistance((float) (Math.PI * 0.75));
    GridLineModelFitter fitter = new GridLineModelFitter((float) (Math.PI * 0.75));
    ModelMatcher<LinePolar2D_F32, Edgel> matcher = new Ransac<>(123123, manager, fitter, distance, 25, 1);
    ImageGradient<I, D> gradient = FactoryDerivative.sobel(imageType, derivType);
    System.out.println("Image width " + input.width + " height " + input.height);
    ConvertBufferedImage.convertFromSingle(image, input, imageType);
    gradient.process(input, derivX, derivY);
    GGradientToEdgeFeatures.intensityAbs(derivX, derivY, edgeIntensity);
    // non-max suppression on the lines
    // GGradientToEdgeFeatures.direction(derivX,derivY,orientation);
    // GradientToEdgeFeatures.discretizeDirection4(orientation,direction);
    // GradientToEdgeFeatures.nonMaxSuppression4(edgeIntensity,direction,suppressed);
    GThresholdImageOps.threshold(edgeIntensity, detected, 30, false);
    GridRansacLineDetector<GrayF32> alg = new ImplGridRansacLineDetector_F32(40, 10, matcher);
    alg.process((GrayF32) derivX, (GrayF32) derivY, detected);
    MatrixOfList<LineSegment2D_F32> gridLine = alg.getFoundLines();
    ConnectLinesGrid connect = new ConnectLinesGrid(Math.PI * 0.01, 1, 8);
    // connect.process(gridLine);
    // LineImageOps.pruneClutteredGrids(gridLine,3);
    List<LineSegment2D_F32> found = gridLine.createSingleList();
    System.out.println("size = " + found.size());
    LineImageOps.mergeSimilar(found, (float) (Math.PI * 0.03), 5f);
    // LineImageOps.pruneSmall(found,40);
    System.out.println("after size = " + found.size());
    ImageLinePanel gui = new ImageLinePanel();
    gui.setBackground(image);
    gui.setLineSegments(found);
    gui.setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
    BufferedImage renderedBinary = VisualizeBinaryData.renderBinary(detected, false, null);
    ShowImages.showWindow(renderedBinary, "Detected Edges");
    ShowImages.showWindow(gui, "Detected Lines");
}
Also used : LinePolar2D_F32(georegression.struct.line.LinePolar2D_F32) ModelManagerLinePolar2D_F32(georegression.fitting.line.ModelManagerLinePolar2D_F32) LineSegment2D_F32(georegression.struct.line.LineSegment2D_F32) ModelManagerLinePolar2D_F32(georegression.fitting.line.ModelManagerLinePolar2D_F32) ImageLinePanel(boofcv.gui.feature.ImageLinePanel) GridLineModelDistance(boofcv.alg.feature.detect.line.gridline.GridLineModelDistance) Ransac(org.ddogleg.fitting.modelset.ransac.Ransac) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) GrayF32(boofcv.struct.image.GrayF32) GrayS8(boofcv.struct.image.GrayS8) Edgel(boofcv.alg.feature.detect.line.gridline.Edgel) ImplGridRansacLineDetector_F32(boofcv.alg.feature.detect.line.gridline.ImplGridRansacLineDetector_F32) ConnectLinesGrid(boofcv.alg.feature.detect.line.ConnectLinesGrid) GrayU8(boofcv.struct.image.GrayU8) GridLineModelFitter(boofcv.alg.feature.detect.line.gridline.GridLineModelFitter)

Example 47 with GrayF32

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

the class DetectFiducialSquareBinaryApp method createDetector.

protected void createDetector(boolean initializing) {
    if (!initializing)
        BoofSwingUtil.checkGuiThread();
    synchronized (lockProcessing) {
        ConfigThreshold configThresh = controls.polygonPanel.getThresholdPanel().createConfig();
        ConfigFiducialBinary configFid = controls.getConfig();
        final InputToBinary<GrayF32> binary = FactoryThresholdBinary.threshold(configThresh, GrayF32.class);
        final DetectPolygonBinaryGrayRefine<GrayF32> squareDetector = FactoryShapeDetector.polygon(configFid.squareDetector, GrayF32.class);
        detector = new Detector(configFid, binary, squareDetector);
    }
}
Also used : ConfigThreshold(boofcv.factory.filter.binary.ConfigThreshold) ConfigFiducialBinary(boofcv.factory.fiducial.ConfigFiducialBinary) GrayF32(boofcv.struct.image.GrayF32) FactoryShapeDetector(boofcv.factory.shape.FactoryShapeDetector)

Example 48 with GrayF32

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

the class VisualizeCannySteps method main.

// static String fileName = UtilIO.pathExample("indoors01.jpg");
// static String fileName = UtilIO.pathExample("shapes01.png)";
public static void main(String[] args) {
    BufferedImage input = UtilImageIO.loadImage(fileName);
    GrayF32 inputF32 = ConvertBufferedImage.convertFrom(input, (GrayF32) null);
    GrayF32 blurred = new GrayF32(inputF32.width, inputF32.height);
    GrayF32 derivX = new GrayF32(inputF32.width, inputF32.height);
    GrayF32 derivY = new GrayF32(inputF32.width, inputF32.height);
    GrayF32 intensity = new GrayF32(inputF32.width, inputF32.height);
    GrayF32 orientation = new GrayF32(inputF32.width, inputF32.height);
    GrayF32 suppressed = new GrayF32(inputF32.width, inputF32.height);
    GrayS8 direction = new GrayS8(inputF32.width, inputF32.height);
    GrayU8 output = new GrayU8(inputF32.width, inputF32.height);
    BlurStorageFilter<GrayF32> blur = FactoryBlurFilter.gaussian(GrayF32.class, -1, 2);
    ImageGradient<GrayF32, GrayF32> gradient = FactoryDerivative.sobel(GrayF32.class, null);
    blur.process(inputF32, blurred);
    gradient.process(blurred, derivX, derivY);
    float threshLow = 5;
    float threshHigh = 40;
    GradientToEdgeFeatures.intensityE(derivX, derivY, intensity);
    GradientToEdgeFeatures.direction(derivX, derivY, orientation);
    GradientToEdgeFeatures.discretizeDirection4(orientation, direction);
    GradientToEdgeFeatures.nonMaxSuppression4(intensity, direction, suppressed);
    BufferedImage renderedOrientation = VisualizeEdgeFeatures.renderOrientation4(direction, suppressed, threshLow, null);
    HysteresisEdgeTraceMark hysteresis = new HysteresisEdgeTraceMark();
    hysteresis.process(suppressed, direction, threshLow, threshHigh, output);
    BufferedImage renderedLabel = VisualizeBinaryData.renderBinary(output, false, null);
    ListDisplayPanel gui = new ListDisplayPanel();
    gui.addImage(suppressed, "Suppressed Intensity");
    gui.addImage(intensity, "Raw Intensity");
    gui.addImage(renderedOrientation, "Orientation");
    gui.addImage(renderedLabel, "Labeled Contours");
    ShowImages.showWindow(gui, "Visualized Canny Steps", true);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ListDisplayPanel(boofcv.gui.ListDisplayPanel) GrayS8(boofcv.struct.image.GrayS8) HysteresisEdgeTraceMark(boofcv.alg.feature.detect.edge.HysteresisEdgeTraceMark) GrayU8(boofcv.struct.image.GrayU8) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 49 with GrayF32

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

the class CompareFeatureExtractorApp method doProcess.

private synchronized void doProcess() {
    // System.out.println("radius "+radius+" min separation "+minSeparation+" thresholdFraction "+thresholdFraction+" numFeatures "+numFeatures);
    deriv.setInput(grayImage);
    D derivX = deriv.getDerivative(true);
    D derivY = deriv.getDerivative(false);
    D derivXX = deriv.getDerivative(true, true);
    D derivYY = deriv.getDerivative(false, false);
    D derivXY = deriv.getDerivative(true, false);
    // todo modifying buffered images which might be actively being displayed, could mess up swing
    intensityAlg.process(grayImage, derivX, derivY, derivXX, derivYY, derivXY);
    GrayF32 intensity = intensityAlg.getIntensity();
    intensityImage = VisualizeImageData.colorizeSign(intensityAlg.getIntensity(), null, ImageStatistics.maxAbs(intensity));
    float max = ImageStatistics.maxAbs(intensity);
    float threshold = max * thresholdFraction;
    NonMaxSuppression extractor = FactoryFeatureExtractor.nonmax(new ConfigExtract(minSeparation, threshold, radius, true));
    GeneralFeatureDetector<T, D> detector = new GeneralFeatureDetector<>(intensityAlg, extractor);
    detector.setMaxFeatures(numFeatures);
    detector.process(grayImage, derivX, derivY, derivXX, derivYY, derivXY);
    QueueCorner foundCorners = detector.getMaximums();
    render.reset();
    for (int i = 0; i < foundCorners.size(); i++) {
        Point2D_I16 p = foundCorners.get(i);
        render.addPoint(p.x, p.y, 3, Color.RED);
    }
    Graphics2D g2 = workImage.createGraphics();
    g2.drawImage(input, 0, 0, grayImage.width, grayImage.height, null);
    render.draw(g2);
    drawImage();
}
Also used : ConfigExtract(boofcv.abst.feature.detect.extract.ConfigExtract) NonMaxSuppression(boofcv.abst.feature.detect.extract.NonMaxSuppression) GrayF32(boofcv.struct.image.GrayF32) Point2D_I16(georegression.struct.point.Point2D_I16) QueueCorner(boofcv.struct.QueueCorner) GeneralFeatureDetector(boofcv.alg.feature.detect.interest.GeneralFeatureDetector) FactoryIntensityPoint(boofcv.factory.feature.detect.intensity.FactoryIntensityPoint)

Example 50 with GrayF32

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

the class IntensityFastHessianApp method main.

// static String fileName = "data/particles01.jpg";
// static String fileName = "data/scale/beach02.jpg";
// static String fileName = "data/scale/mountain_7p1mm.jpg";
// static String fileName = "data/indoors01.jpg";
// static String fileName = "data/shapes01.png";
public static void main(String[] args) {
    BufferedImage input = UtilImageIO.loadImage(fileName);
    GrayF32 inputF32 = ConvertBufferedImage.convertFrom(input, (GrayF32) null);
    GrayF32 integral = IntegralImageOps.transform(inputF32, null);
    GrayF32 intensity = new GrayF32(integral.width, integral.height);
    ListDisplayPanel guiIntensity = new ListDisplayPanel();
    guiIntensity.addImage(input, "Original");
    guiIntensity.addImage(VisualizeImageData.grayMagnitude(inputF32, null, 255), "Gray");
    int skip = 0;
    for (int octave = 0; octave < 4; octave++) {
        if (skip == 0)
            skip = 1;
        else
            skip = skip + skip;
        for (int sizeIndex = 0; sizeIndex < 4; sizeIndex++) {
            int block = 1 + skip * 2 * (sizeIndex + 1);
            int size = 3 * block;
            IntegralImageFeatureIntensity.hessian(integral, 1, size, intensity);
            float maxAbs = ImageStatistics.maxAbs(intensity);
            BufferedImage b = VisualizeImageData.colorizeSign(intensity, null, maxAbs);
            guiIntensity.addImage(b, String.format("Oct = %2d size %3d", octave + 1, size));
        }
    }
    ShowImages.showWindow(guiIntensity, "Feature Intensity", true);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ListDisplayPanel(boofcv.gui.ListDisplayPanel) 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