use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class TestGradientReduceToSingle method maxf_plfu8_u8.
@Test
public void maxf_plfu8_u8() {
Planar<GrayU8> inX = new Planar<>(GrayU8.class, width, height, numbands);
Planar<GrayU8> inY = new Planar<>(GrayU8.class, width, height, numbands);
GrayU8 outX = new GrayU8(width, height);
GrayU8 outY = new GrayU8(width, height);
GImageMiscOps.fillUniform(inX, rand, 0, 100);
GImageMiscOps.fillUniform(inY, rand, 0, 100);
GradientReduceToSingle.maxf(inX, inY, outX, outY);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int maxNorm = 0;
int maxValueX = -Integer.MAX_VALUE;
int maxValueY = -Integer.MAX_VALUE;
for (int i = 0; i < numbands; i++) {
int dx = inX.getBand(i).get(x, y);
int dy = inY.getBand(i).get(x, y);
int r = dx * dx + dy * dy;
if (r > maxNorm) {
maxNorm = r;
maxValueX = dx;
maxValueY = dy;
}
}
assertEquals(maxValueX, outX.get(x, y), 1e-4f);
assertEquals(maxValueY, outY.get(x, y), 1e-4f);
}
}
}
use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class TestLikelihoodHistCoupled_PL_U8 method singleColor.
@Test
public void singleColor() {
LikelihoodHistCoupled_PL_U8 alg = new LikelihoodHistCoupled_PL_U8(255, 11);
Planar<GrayU8> image = new Planar<>(GrayU8.class, 30, 40, 3);
RectangleLength2D_I32 r = new RectangleLength2D_I32(3, 4, 12, 8);
setColor(image, r, 100, 105, 12);
alg.setImage(image);
alg.createModel(r);
assertEquals(1.0f, alg.compute(3, 4), 1e-4);
assertEquals(1.0f, alg.compute(14, 11), 1e-4);
assertEquals(0, alg.compute(10, 30), 1e-4);
}
use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class TestLikelihoodHistCoupled_PL_U8 method multipleColors.
@Test
public void multipleColors() {
LikelihoodHistCoupled_PL_U8 alg = new LikelihoodHistCoupled_PL_U8(255, 11);
Planar<GrayU8> image = new Planar<>(GrayU8.class, 30, 40, 3);
RectangleLength2D_I32 r0 = new RectangleLength2D_I32(3, 4, 8, 8);
RectangleLength2D_I32 r1 = new RectangleLength2D_I32(11, 4, 4, 8);
setColor(image, r0, 100, 105, 12);
setColor(image, r1, 50, 200, 50);
RectangleLength2D_I32 region = new RectangleLength2D_I32(3, 4, 12, 8);
alg.setImage(image);
alg.createModel(region);
float v0 = alg.compute(3, 4);
float v1 = alg.compute(11, 4);
assertEquals(1.0f, v0 + v1, 1e-4);
assertTrue(v0 > v1);
}
use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class TestLikelihoodHueSatHistCoupled_PL_U8 method convertToHueSat.
@Test
public void convertToHueSat() {
LikelihoodHueSatHistCoupled_PL_U8 alg = new LikelihoodHueSatHistCoupled_PL_U8(255, 30);
Planar<GrayU8> image = new Planar<>(GrayU8.class, 30, 40, 3);
setColor(image, 5, 6, 120, 50, 255);
alg.setImage(image);
alg.createModel(new RectangleLength2D_I32(5, 6, 1, 1));
float[] hsv = new float[3];
ColorHsv.rgbToHsv(120, 50, 255, hsv);
int indexH = (int) (hsv[0] / alg.sizeH);
int indexS = (int) (hsv[1] / alg.sizeS);
int index = indexH * 30 + indexS;
assertEquals(1.0, alg.bins[index], 1e-4);
}
use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.
the class TestLikelihoodHueSatHistCoupled_PL_U8 method numBins.
@Test
public void numBins() {
LikelihoodHueSatHistCoupled_PL_U8 alg = new LikelihoodHueSatHistCoupled_PL_U8(255, 30);
Planar<GrayU8> image = new Planar<>(GrayU8.class, 30, 40, 3);
// make sure the upper limit is handled correctly
setColor(image, 5, 6, 255, 255, 255);
alg.setImage(image);
alg.createModel(new RectangleLength2D_I32(5, 6, 1, 1));
assertEquals(30, alg.numHistogramBins);
assertEquals(30 * 30, alg.bins.length);
// it comes out to a slightly larger size on purpose
assertEquals(2 * Math.PI, alg.sizeH * 30, 0.01);
assertEquals(1.0, alg.sizeS * 30, 0.01);
}
Aggregations