use of boofcv.struct.border.ImageBorder_F32 in project BoofCV by lessthanoptimal.
the class TestDerivativeIntegralImage method kernelDerivXX.
@Test
void kernelDerivXX() {
GrayF32 orig = new GrayF32(width, height);
GrayF32 integral = new GrayF32(width, height);
ImageMiscOps.fillUniform(orig, rand, 0, 20);
GrayF32 expected = new GrayF32(width, height);
GrayF32 found = new GrayF32(width, height);
IntegralImageOps.transform(orig, integral);
ImageBorder_F32 border = (ImageBorder_F32) FactoryImageBorderAlgs.value(orig, 0);
for (int i = 1; i <= 5; i += 2) {
int size = i * 3;
IntegralKernel kernelI = DerivativeIntegralImage.kernelDerivXX(size, null);
Kernel2D_F32 kernel = createDerivXX(size);
ConvolveImage.convolve(kernel, orig, expected, border);
IntegralImageOps.convolve(integral, kernelI, found);
BoofTesting.assertEquals(expected, found, 1e-2);
}
}
use of boofcv.struct.border.ImageBorder_F32 in project BoofCV by lessthanoptimal.
the class ImplEdgeNonMaxSuppression method border8.
/**
* Just processes the image border.
*/
public static void border8(GrayF32 _intensity, GrayS8 direction, GrayF32 output) {
int w = _intensity.width;
int h = _intensity.height - 1;
ImageBorder_F32 intensity = FactoryImageBorderAlgs.value(_intensity, 0);
// CONCURRENT_BELOW BoofConcurrency.loopFor(0,w,x->{
for (int x = 0; x < w; x++) {
int dir = direction.get(x, 0);
int dx, dy;
if (dir == 0 || dir == 4) {
dx = 1;
dy = 0;
} else if (dir == 1 || dir == -3) {
dx = 1;
dy = 1;
} else if (dir == 2 || dir == -2) {
dx = 0;
dy = 1;
} else {
dx = 1;
dy = -1;
}
float left = intensity.get(x - dx, -dy);
float middle = intensity.get(x, 0);
float right = intensity.get(x + dx, dy);
if (left > middle || right > middle) {
output.set(x, 0, 0);
} else {
output.set(x, 0, middle);
}
}
// CONCURRENT_BELOW BoofConcurrency.loopFor(0,w,x->{
for (int x = 0; x < w; x++) {
int dir = direction.get(x, h);
int dx, dy;
if (dir == 0 || dir == 4) {
dx = 1;
dy = 0;
} else if (dir == 1 || dir == -3) {
dx = 1;
dy = 1;
} else if (dir == 2 || dir == -2) {
dx = 0;
dy = 1;
} else {
dx = 1;
dy = -1;
}
float left = intensity.get(x - dx, h - dy);
float middle = intensity.get(x, h);
float right = intensity.get(x + dx, h + dy);
if (left > middle || right > middle) {
output.set(x, h, 0);
} else {
output.set(x, h, middle);
}
}
// CONCURRENT_BELOW BoofConcurrency.loopFor(1,h,y->{
for (int y = 1; y < h; y++) {
int dir = direction.get(0, y);
int dx, dy;
if (dir == 0 || dir == 4) {
dx = 1;
dy = 0;
} else if (dir == 1 || dir == -3) {
dx = 1;
dy = 1;
} else if (dir == 2 || dir == -2) {
dx = 0;
dy = 1;
} else {
dx = 1;
dy = -1;
}
float left = intensity.get(-dx, y - dy);
float middle = intensity.get(0, y);
float right = intensity.get(dx, y + dy);
if (left > middle || right > middle) {
output.set(0, y, 0);
} else {
output.set(0, y, middle);
}
}
// CONCURRENT_ABOVE });
// right border
int _w = w - 1;
// CONCURRENT_BELOW BoofConcurrency.loopFor(1,h,y->{
for (int y = 1; y < h; y++) {
int dir = direction.get(_w, y);
int dx, dy;
if (dir == 0 || dir == 4) {
dx = 1;
dy = 0;
} else if (dir == 1 || dir == -3) {
dx = 1;
dy = 1;
} else if (dir == 2 || dir == -2) {
dx = 0;
dy = 1;
} else {
dx = 1;
dy = -1;
}
float left = intensity.get(_w - dx, y - dy);
float middle = intensity.get(_w, y);
float right = intensity.get(_w + dx, y + dy);
if (left > middle || right > middle) {
output.set(_w, y, 0);
} else {
output.set(_w, y, middle);
}
}
// CONCURRENT_ABOVE });
}
use of boofcv.struct.border.ImageBorder_F32 in project BoofCV by lessthanoptimal.
the class ImplEdgeNonMaxSuppression method naive8.
/**
* Slow algorithm which processes the whole image.
*/
public static void naive8(GrayF32 _intensity, GrayS8 direction, GrayF32 output) {
final int w = _intensity.width;
final int h = _intensity.height;
ImageBorder_F32 intensity = FactoryImageBorderAlgs.value(_intensity, 0);
// CONCURRENT_BELOW BoofConcurrency.loopFor(0,h,y->{
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int dir = direction.get(x, y);
int dx, dy;
if (dir == 0 || dir == 4) {
dx = 1;
dy = 0;
} else if (dir == 1 || dir == -3) {
dx = 1;
dy = 1;
} else if (dir == 2 || dir == -2) {
dx = 0;
dy = 1;
} else {
dx = 1;
dy = -1;
}
float left = intensity.get(x - dx, y - dy);
float middle = intensity.get(x, y);
float right = intensity.get(x + dx, y + dy);
// suppress the value if either of its neighboring values are more than or equal to it
if (left > middle || right > middle) {
output.set(x, y, 0);
} else {
output.set(x, y, middle);
}
}
}
// CONCURRENT_ABOVE });
}
use of boofcv.struct.border.ImageBorder_F32 in project BoofCV by lessthanoptimal.
the class ImplBilinearPixel_F32 method get_border.
public float get_border(float x, float y) {
float xf = (float) Math.floor(x);
float yf = (float) Math.floor(y);
int xt = (int) xf;
int yt = (int) yf;
float ax = x - xf;
float ay = y - yf;
ImageBorder_F32 border = (ImageBorder_F32) this.border;
// (x,y)
float val = (1.0f - ax) * (1.0f - ay) * border.get(xt, yt);
// (x+1,y)
val += ax * (1.0f - ay) * border.get(xt + 1, yt);
// (x+1,y)
;
// (x+1,y+1)
val += ax * ay * border.get(xt + 1, yt + 1);
// (x+1,y+1)
;
// (x,y+1)
val += (1.0f - ax) * ay * border.get(xt, yt + 1);
// (x,y+1)
;
return val;
}
use of boofcv.struct.border.ImageBorder_F32 in project BoofCV by lessthanoptimal.
the class TestDerivativeIntegralImage method kernelDerivX.
@Test
public void kernelDerivX() {
GrayF32 orig = new GrayF32(width, height);
GrayF32 integral = new GrayF32(width, height);
ImageMiscOps.fillUniform(orig, rand, 0, 20);
GrayF32 expected = new GrayF32(width, height);
GrayF32 found = new GrayF32(width, height);
IntegralImageOps.transform(orig, integral);
ImageBorder_F32 border = (ImageBorder_F32) FactoryImageBorderAlgs.value(orig, 0);
for (int r = 1; r < 5; r++) {
IntegralKernel kernelI = DerivativeIntegralImage.kernelDerivX(r, null);
Kernel2D_F32 kernel = createDerivX(r);
ConvolveImage.convolve(kernel, orig, expected, border);
IntegralImageOps.convolve(integral, kernelI, found);
BoofTesting.assertEquals(expected, found, 1e-2);
}
}
Aggregations