use of boofcv.struct.image.GrayS8 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");
}
use of boofcv.struct.image.GrayS8 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);
}
use of boofcv.struct.image.GrayS8 in project BoofCV by lessthanoptimal.
the class CommonHysteresisEdgeTrace method direction.
public GrayS8 direction(int which) {
GrayS8 a = new GrayS8();
setShape(which, a);
if (which == 0) {
a.data = dir0;
} else if (which == 1) {
a.data = dir1;
} else if (which == 2) {
a.data = dir2;
} else if (which == 3) {
a.data = dir3;
} else if (which == 4) {
a.data = dir4;
}
return a.clone();
}
use of boofcv.struct.image.GrayS8 in project BoofCV by lessthanoptimal.
the class TestGradientToEdgeFeatures method nonMaxSuppression8.
@Test
public void nonMaxSuppression8() {
GrayF32 intensity = new GrayF32(width, height);
GrayS8 direction = new GrayS8(width, height);
GrayF32 expected = new GrayF32(width, height);
GrayF32 found = new GrayF32(width, height);
BoofTesting.checkSubImage(this, "nonMaxSuppression4", true, intensity, direction, expected, found);
}
use of boofcv.struct.image.GrayS8 in project BoofCV by lessthanoptimal.
the class TestGradientToEdgeFeatures method discretizeDirection8.
@Test
public void discretizeDirection8() {
GrayF32 angle = new GrayF32(5, 5);
for (int i = 0; i < 8; i++) {
angle.data[i] = (float) UtilAngle.bound(i * Math.PI / 4.0);
}
GrayS8 d = new GrayS8(5, 5);
GradientToEdgeFeatures.discretizeDirection8(angle, d);
for (int i = 0; i < 8; i++) {
int expected = i > 4 ? i - 8 : i;
assertEquals(expected, d.data[i]);
}
}
Aggregations