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);
}
Aggregations