Connectivity implements PlugIn { public double getSumEuler(final ImagePlus imp) { setDimensions(imp); final ImageStack stack = imp.getImageStack(); final int[] sumEulerInt = new int[depth + 1]; final AtomicInteger ai = new AtomicInteger(0); final Thread[] threads = Multithreader.newThreads(); for (int thread = 0; thread < threads.length; thread++) { threads[thread] = new Thread(new Runnable() { @Override public void run() { for (int z = ai.getAndIncrement(); z <= depth; z = ai.getAndIncrement()) { for (int y = 0; y <= height; y++) { for (int x = 0; x <= width; x++) { final byte[] octant = getOctant(stack, x, y, z); if (octant[0] == 0) continue; sumEulerInt[z] += getDeltaEuler(octant); } } } } }); } Multithreader.startAndJoin(threads); double sumEuler = Arrays.stream(sumEulerInt).sum(); sumEuler /= 8; return sumEuler; }  @Override void run(final String arg); double getConnDensity(final ImagePlus imp, final double connectivity); double getConnectivity(final double deltaChi); double getDeltaChi(final ImagePlus imp, final double sumEuler); double getSumEuler(final ImagePlus imp);  }
@Test public void testGetSumEulerCrossedCircle() { for (int size = 16; size < 1024; size *= 2) { final ImagePlus imp = crossedCircle(size); final double sumEuler = conn.getSumEuler(imp); assertEquals(-3, sumEuler, 1e-12); } }
@Test public void testGetSumEulerBoxFrame() { for (int size = 16; size < 256; size *= 2) { final ImagePlus imp = boxFrame(size, size, size); final double sumEuler = conn.getSumEuler(imp); assertEquals(-4, sumEuler, 1e-12); } }