Search in sources :

Example 21 with GrayS16

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

the class ExampleConvolution method convolve1D.

/**
 * Convolves a 1D kernel horizontally and vertically
 */
private static void convolve1D(GrayU8 gray) {
    ImageBorder<GrayU8> border = FactoryImageBorder.wrap(BorderType.EXTENDED, gray);
    Kernel1D_S32 kernel = new Kernel1D_S32(2);
    // specify the kernel's origin
    kernel.offset = 1;
    kernel.data[0] = 1;
    kernel.data[1] = -1;
    GrayS16 output = new GrayS16(gray.width, gray.height);
    GConvolveImageOps.horizontal(kernel, gray, output, border);
    panel.addImage(VisualizeImageData.standard(output, null), "1D Horizontal");
    GConvolveImageOps.vertical(kernel, gray, output, border);
    panel.addImage(VisualizeImageData.standard(output, null), "1D Vertical");
}
Also used : Kernel1D_S32(boofcv.struct.convolve.Kernel1D_S32) GrayS16(boofcv.struct.image.GrayS16) GrayU8(boofcv.struct.image.GrayU8)

Example 22 with GrayS16

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

the class ExampleConvolution method convolve2D.

/**
 * Convolves a 2D kernel
 */
private static void convolve2D(GrayU8 gray) {
    // By default 2D kernels will be centered around width/2
    Kernel2D_S32 kernel = new Kernel2D_S32(3);
    kernel.set(1, 0, 2);
    kernel.set(2, 1, 2);
    kernel.set(0, 1, -2);
    kernel.set(1, 2, -2);
    // Output needs to handle the increased domain after convolution.  Can't be 8bit
    GrayS16 output = new GrayS16(gray.width, gray.height);
    ImageBorder<GrayU8> border = FactoryImageBorder.wrap(BorderType.EXTENDED, gray);
    GConvolveImageOps.convolve(kernel, gray, output, border);
    panel.addImage(VisualizeImageData.standard(output, null), "2D Kernel");
}
Also used : Kernel2D_S32(boofcv.struct.convolve.Kernel2D_S32) GrayS16(boofcv.struct.image.GrayS16) GrayU8(boofcv.struct.image.GrayU8)

Example 23 with GrayS16

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

the class TestCannyEdge method constantGradient.

/**
 * Test a pathological case. The input image has a constant gradient
 */
@Test
public void constantGradient() {
    GrayU8 input = new GrayU8(width, height);
    GrayU8 output = new GrayU8(width, height);
    // the whole image has a constant gradient
    for (int i = 0; i < input.width; i++) {
        for (int j = 0; j < input.height; j++) {
            input.unsafe_set(i, j, i * 2);
        }
    }
    CannyEdge<GrayU8, GrayS16> alg = createCanny(true);
    alg.process(input, 1, 2, output);
// just see if it blows up or freezes
}
Also used : GrayS16(boofcv.struct.image.GrayS16) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 24 with GrayS16

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

the class TestCannyEdge method basicTestPoints.

@Test
public void basicTestPoints() {
    GrayU8 input = new GrayU8(width, height);
    ImageMiscOps.fillRectangle(input, 50, 20, 30, 40, 50);
    CannyEdge<GrayU8, GrayS16> alg = createCanny(true);
    alg.process(input, 10, 50, null);
    List<EdgeContour> contour = alg.getContours();
    assertEquals(1, contour.size());
    // the exact edge location is ambiguous
    for (EdgeContour e : contour) {
        for (EdgeSegment s : e.segments) {
            checkNeighbor(s.points);
            checkRectangle(s.points, 20, 30, 20 + 40, 30 + 50, 1);
        }
    }
}
Also used : GrayS16(boofcv.struct.image.GrayS16) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 25 with GrayS16

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

the class TestCannyEdge method checkThresholds.

@Test
public void checkThresholds() {
    GrayU8 input = new GrayU8(15, 20);
    input.set(5, 0, 50);
    input.set(5, 1, 50);
    input.set(5, 2, 50);
    input.set(5, 3, 5);
    input.set(5, 4, 5);
    input.set(5, 5, 5);
    // manually inspecting the image shows that the intensity image has a max value of 34 and a
    // smallest value of 2
    CannyEdge<GrayU8, GrayS16> alg = createCanny(true);
    alg.process(input, 1, 28, null);
    assertEquals(1, alg.getContours().size());
    // the high threshold should be too high
    alg.process(input, 1, 1000, null);
    assertEquals(0, alg.getContours().size());
    // the low threshold is too low now for everything to be connected
    alg.process(input, 30, 31, null);
    assertEquals(2, alg.getContours().size());
}
Also used : GrayS16(boofcv.struct.image.GrayS16) GrayU8(boofcv.struct.image.GrayU8) 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