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