Search in sources :

Example 56 with GrayS16

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

the class ExampleCannyEdge method main.

public static void main(String[] args) {
    BufferedImage image = UtilImageIO.loadImage(UtilIO.pathExample("simple_objects.jpg"));
    GrayU8 gray = ConvertBufferedImage.convertFrom(image, (GrayU8) null);
    GrayU8 edgeImage = gray.createSameShape();
    // Create a canny edge detector which will dynamically compute the threshold based on maximum edge intensity
    // It has also been configured to save the trace as a graph.  This is the graph created while performing
    // hysteresis thresholding.
    CannyEdge<GrayU8, GrayS16> canny = FactoryEdgeDetectors.canny(2, true, true, GrayU8.class, GrayS16.class);
    // The edge image is actually an optional parameter.  If you don't need it just pass in null
    canny.process(gray, 0.1f, 0.3f, edgeImage);
    // First get the contour created by canny
    List<EdgeContour> edgeContours = canny.getContours();
    // The 'edgeContours' is a tree graph that can be difficult to process.  An alternative is to extract
    // the contours from the binary image, which will produce a single loop for each connected cluster of pixels.
    // Note that you are only interested in external contours.
    List<Contour> contours = BinaryImageOps.contour(edgeImage, ConnectRule.EIGHT, null);
    // display the results
    BufferedImage visualBinary = VisualizeBinaryData.renderBinary(edgeImage, false, null);
    BufferedImage visualCannyContour = VisualizeBinaryData.renderContours(edgeContours, null, gray.width, gray.height, null);
    BufferedImage visualEdgeContour = new BufferedImage(gray.width, gray.height, BufferedImage.TYPE_INT_RGB);
    VisualizeBinaryData.render(contours, (int[]) null, visualEdgeContour);
    ListDisplayPanel panel = new ListDisplayPanel();
    panel.addImage(visualBinary, "Binary Edges from Canny");
    panel.addImage(visualCannyContour, "Canny Trace Graph");
    panel.addImage(visualEdgeContour, "Contour from Canny Binary");
    ShowImages.showWindow(panel, "Canny Edge", true);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) Contour(boofcv.alg.filter.binary.Contour) EdgeContour(boofcv.alg.feature.detect.edge.EdgeContour) GrayS16(boofcv.struct.image.GrayS16) GrayU8(boofcv.struct.image.GrayU8) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) EdgeContour(boofcv.alg.feature.detect.edge.EdgeContour)

Example 57 with GrayS16

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

the class TestCannyEdge method basicTestMarks.

@Test
public void basicTestMarks() {
    GrayU8 input = new GrayU8(width, height);
    GrayU8 binary = new GrayU8(width, height);
    ImageMiscOps.fillRectangle(input, 50, 20, 30, 40, 50);
    CannyEdge<GrayU8, GrayS16> alg = createCanny(false);
    alg.process(input, 10, 50, binary);
    GrayU8 expected = new GrayU8(width, height);
    // set pixels to 1 if there are where the edge could lie
    ImageMiscOps.fillRectangle(expected, 1, 19, 29, 42, 52);
    ImageMiscOps.fillRectangle(expected, 0, 21, 31, 38, 48);
    int totalHits = 0;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            if (expected.get(x, y) == 0) {
                assertEquals(0, binary.get(x, y));
            } else if (binary.get(x, y) == 1) {
                totalHits++;
            }
        }
    }
    assertTrue(totalHits >= 2 * 50 + 2 * 38);
}
Also used : GrayS16(boofcv.struct.image.GrayS16) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 58 with GrayS16

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

the class TestCannyEdge method canHandleNoTexture_and_zeroThresh.

/**
 * Image has no texture and the sadistic user and specified a threshold of zero.  Everything should
 * be an edge.
 */
@Test
public void canHandleNoTexture_and_zeroThresh() {
    GrayU8 input = new GrayU8(width, height);
    GrayU8 output = new GrayU8(width, height);
    CannyEdge<GrayU8, GrayS16> alg = createCanny(true);
    alg.process(input, 0, 0, output);
    List<EdgeContour> contour = alg.getContours();
    assertTrue(contour.size() > 0);
    int numEdgePixels = 0;
    for (EdgeContour e : contour) {
        for (EdgeSegment s : e.segments) {
            numEdgePixels += s.points.size();
        }
    }
    assertEquals(numEdgePixels, input.width * input.height);
    for (int i = 0; i < output.data.length; i++) assertEquals(1, output.data[i]);
}
Also used : GrayS16(boofcv.struct.image.GrayS16) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 59 with GrayS16

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

the class TestCannyEdge method checkEquivalentOutput.

/**
 * Makes sure the two output modes are equivalent
 */
@Test
public void checkEquivalentOutput() {
    GrayU8 input = new GrayU8(width, height);
    GrayU8 output0 = new GrayU8(width, height);
    GrayU8 output1 = new GrayU8(width, height);
    for (int i = 0; i < 10; i++) {
        ImageMiscOps.fillUniform(input, rand, 0, 200);
        CannyEdge<GrayU8, GrayS16> algTrace = createCanny(true);
        CannyEdge<GrayU8, GrayS16> algMark = createCanny(false);
        algTrace.process(input, 20, 100, output0);
        algMark.process(input, 20, 100, output1);
        BoofTesting.assertEquals(output0, output1, 0);
    }
}
Also used : GrayS16(boofcv.struct.image.GrayS16) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 60 with GrayS16

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

the class TestImplShiTomasiCorner_F32 method compareToNaive.

/**
 * Sees if the integer version and this version produce the same results.
 * <p/>
 * Creates a random image and looks for corners in it.  Sees if the naive
 * and fast algorithm produce exactly the same results.
 */
@Test
public void compareToNaive() {
    GrayU8 img = new GrayU8(width, height);
    ImageMiscOps.fillUniform(img, new Random(0xfeed), 0, 100);
    GrayS16 derivX_I = new GrayS16(img.getWidth(), img.getHeight());
    GrayS16 derivY_I = new GrayS16(img.getWidth(), img.getHeight());
    GradientSobel.process(img, derivX_I, derivY_I, new ImageBorder1D_S32(BorderIndex1D_Extend.class));
    GrayF32 derivX_F = ConvertImage.convert(derivX_I, (GrayF32) null);
    GrayF32 derivY_F = ConvertImage.convert(derivY_I, (GrayF32) null);
    BoofTesting.checkSubImage(this, "compareToNaive", true, derivX_F, derivY_F);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Random(java.util.Random) GrayS16(boofcv.struct.image.GrayS16) GrayU8(boofcv.struct.image.GrayU8) ImageBorder1D_S32(boofcv.core.image.border.ImageBorder1D_S32) BorderIndex1D_Extend(boofcv.core.image.border.BorderIndex1D_Extend) Test(org.junit.Test)

Aggregations

GrayS16 (boofcv.struct.image.GrayS16)63 GrayU8 (boofcv.struct.image.GrayU8)45 Test (org.junit.Test)39 ImageBorder_S32 (boofcv.core.image.border.ImageBorder_S32)15 GrayF32 (boofcv.struct.image.GrayF32)13 Random (java.util.Random)8 CompareDerivativeToConvolution (boofcv.alg.filter.derivative.CompareDerivativeToConvolution)7 BorderIndex1D_Extend (boofcv.core.image.border.BorderIndex1D_Extend)4 ImageBorder1D_S32 (boofcv.core.image.border.ImageBorder1D_S32)4 ImageGray (boofcv.struct.image.ImageGray)4 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)3 BufferedImage (java.awt.image.BufferedImage)3 WrapDisparitySadRect (boofcv.abst.feature.disparity.WrapDisparitySadRect)2 DisparitySelect (boofcv.alg.feature.disparity.DisparitySelect)2 ImageBorder_F32 (boofcv.core.image.border.ImageBorder_F32)2 ListDisplayPanel (boofcv.gui.ListDisplayPanel)2 Kernel1D_S32 (boofcv.struct.convolve.Kernel1D_S32)2 FDistort (boofcv.abst.distort.FDistort)1 DetectLineSegmentsGridRansac (boofcv.abst.feature.detect.line.DetectLineSegmentsGridRansac)1 EdgeContour (boofcv.alg.feature.detect.edge.EdgeContour)1