use of boofcv.struct.sparse.SparseGradientSafe in project BoofCV by lessthanoptimal.
the class ImplSurfDescribeOps method naiveGradient.
/**
* Simple algorithm for computing the gradient of a region. Can handle image borders
*/
public static <T extends ImageGray<T>> void naiveGradient(T ii, double tl_x, double tl_y, double samplePeriod, int regionSize, double kernelSize, boolean useHaar, double[] derivX, double[] derivY) {
SparseScaleGradient<T, ?> gg = SurfDescribeOps.createGradient(useHaar, (Class<T>) ii.getClass());
gg.setWidth(kernelSize);
gg.setImage(ii);
SparseGradientSafe g = new SparseGradientSafe(gg);
// add 0.5 to c_x and c_y to have it round when converted to an integer pixel
// this is faster than the straight forward method
tl_x += 0.5;
tl_y += 0.5;
int i = 0;
for (int y = 0; y < regionSize; y++) {
for (int x = 0; x < regionSize; x++, i++) {
int xx = (int) (tl_x + x * samplePeriod);
int yy = (int) (tl_y + y * samplePeriod);
GradientValue deriv = g.compute(xx, yy);
derivX[i] = deriv.getX();
derivY[i] = deriv.getY();
// System.out.printf("%2d %2d %2d %2d dx = %6.2f dy = %6.2f\n",x,y,xx,yy,derivX[i],derivY[i]);
}
}
}
use of boofcv.struct.sparse.SparseGradientSafe in project BoofCV by lessthanoptimal.
the class TestSparseGradientSafe method checkMakeBorderSafe.
/**
* Read in a border and see if it returns zeros
*/
@Test
public void checkMakeBorderSafe() {
Dummy d = new Dummy();
SparseImageGradient<GrayF32, GradientValue_F32> safe = new SparseGradientSafe<>(d);
// read the border case
GradientValue_F32 v = safe.compute(0, 0);
assertTrue(v.x == 0);
assertTrue(v.y == 0);
// read inside and see if it has the expected results
assertTrue(safe.compute(width / 2, height / 2) == null);
}
Aggregations