Search in sources :

Example 1 with HysteresisEdgeTraceMark

use of boofcv.alg.feature.detect.edge.HysteresisEdgeTraceMark 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)

Aggregations

HysteresisEdgeTraceMark (boofcv.alg.feature.detect.edge.HysteresisEdgeTraceMark)1 ListDisplayPanel (boofcv.gui.ListDisplayPanel)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 GrayF32 (boofcv.struct.image.GrayF32)1 GrayS8 (boofcv.struct.image.GrayS8)1 GrayU8 (boofcv.struct.image.GrayU8)1 BufferedImage (java.awt.image.BufferedImage)1