SuzukiNeighborStrategy extends ContourFollowingStrategy { @Override public void contour(FImage image, Pixel start, Pixel from, final Operation<Pixel> operation) { directedContour(image, start, from, new Operation<IndependentPair<Pixel, boolean[]>>() { @Override public void perform(IndependentPair<Pixel, boolean[]> object) { operation.perform(object.firstObject()); } }); }  @Override void contour(FImage image, Pixel start, Pixel from, final Operation<Pixel> operation); void directedContour(FImage image, Pixel ij, Pixel i2j2, Operation<IndependentPair<Pixel, boolean[]>> operation);  }
@Test public void testSimple() throws Exception { final float[][] pixels = new float[][] { new float[] { 0, 0, 0, 0, 0, 0 }, new float[] { 0, 0, 1, 1, 1, 0 }, new float[] { 0, 1, 0, 0, 1, 0 }, new float[] { 0, 0, 1, 1, 1, 0 }, new float[] { 0, 0, 0, 0, 0, 0 } }; final FImage img = new FImage(pixels); final ContourFollowingStrategy strat = new SuzukiNeighborStrategy(); final Pixel start = new Pixel(1, 2); Pixel from = new Pixel(1, 3); List<Pixel> contour = strat.contour(img, start, from); assertTrue(contour.size() == img.sum()); from = new Pixel(2, 2); contour = strat.contour(img, start, from); assertTrue(contour.size() == img.sum() - 2); }
@Test public void testOpenLoop() throws Exception { final float[][] pixels = new float[][] { new float[] { 0, 0, 0, 0, 0, 0, 0, 0 }, new float[] { 0, 0, 0, 0, 0, 0, 0, 0 }, new float[] { 0, 0, 0, 0, 0, 1, 1, 0 }, new float[] { 0, 0, 0, 1, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 1, 0, 1, 1, 0 }, new float[] { 0, 0, 0, 0, 1, 1, 0, 0 }, new float[] { 0, 0, 0, 0, 0, 0, 0, 0 } }; final FImage img = new FImage(pixels); final SuzukiNeighborStrategy strat = new SuzukiNeighborStrategy(); final Pixel start = new Pixel(3, 4); final Pixel from = new Pixel(3, 5); strat.contour(img, start, from); }