public void checkBorder(ImageFloat32 image, int c_x, int c_y, int w, int h) { ImplDescribePointPixelRegionNCC_F32 alg = new ImplDescribePointPixelRegionNCC_F32(w, h); NccFeature desc = new NccFeature(alg.getDescriptorLength()); alg.setImage(image); assertFalse(alg.isInBounds(c_x, c_y)); }
public void checkInner(ImageFloat32 image, int c_x, int c_y, int w, int h) { ImplDescribePointPixelRegionNCC_F32 alg = new ImplDescribePointPixelRegionNCC_F32(w, h); NccFeature desc = new NccFeature(alg.getDescriptorLength()); alg.setImage(image); assertTrue(alg.isInBounds(c_x, c_y)); alg.process(c_x, c_y, desc); int y0 = c_y - h / 2; int x0 = c_x - w / 2; double mean = 0; for (int y = y0; y < y0 + h; y++) { for (int x = x0; x < x0 + w; x++) { mean += image.get(x, y); } } mean /= w * h; double variance = 0; for (int y = y0; y < y0 + h; y++) { for (int x = x0; x < x0 + w; x++) { double a = image.get(x, y) - mean; variance += a * a; } } variance /= w * h; assertEquals(desc.mean, mean, 1e-8); assertEquals(desc.sigma, Math.sqrt(variance), 1e-8); int index = 0; for (int y = y0; y < y0 + h; y++) { for (int x = x0; x < x0 + w; x++, index++) { assertEquals(image.get(x, y) - mean, desc.value[index], 1e-4); } } }