1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package org.openimaj.image.contour;
31
32 import static org.junit.Assert.assertTrue;
33
34 import java.util.List;
35
36 import org.junit.Test;
37 import org.openimaj.image.FImage;
38 import org.openimaj.image.pixel.Pixel;
39
40
41
42
43
44
45
46 public class SuzukiNeighborStrategyTest {
47
48
49
50
51 @Test
52 public void testSimple() throws Exception {
53 final float[][] pixels = new float[][] {
54 new float[] { 0, 0, 0, 0, 0, 0 },
55 new float[] { 0, 0, 1, 1, 1, 0 },
56 new float[] { 0, 1, 0, 0, 1, 0 },
57 new float[] { 0, 0, 1, 1, 1, 0 },
58 new float[] { 0, 0, 0, 0, 0, 0 }
59 };
60
61 final FImage img = new FImage(pixels);
62
63 final ContourFollowingStrategy strat = new SuzukiNeighborStrategy();
64 final Pixel start = new Pixel(1, 2);
65 Pixel from = new Pixel(1, 3);
66 List<Pixel> contour = strat.contour(img, start, from);
67 assertTrue(contour.size() == img.sum());
68 from = new Pixel(2, 2);
69 contour = strat.contour(img, start, from);
70 assertTrue(contour.size() == img.sum() - 2);
71 }
72
73
74
75
76 @Test
77 public void testOpenLoop() throws Exception {
78 final float[][] pixels = new float[][] {
79 new float[] { 0, 0, 0, 0, 0, 0, 0, 0 },
80 new float[] { 0, 0, 0, 0, 0, 0, 0, 0 },
81 new float[] { 0, 0, 0, 0, 0, 1, 1, 0 },
82 new float[] { 0, 0, 0, 1, 0, 0, 1, 0 },
83 new float[] { 0, 0, 0, 1, 0, 1, 1, 0 },
84 new float[] { 0, 0, 0, 0, 1, 1, 0, 0 },
85 new float[] { 0, 0, 0, 0, 0, 0, 0, 0 }
86 };
87
88 final FImage img = new FImage(pixels);
89
90 final SuzukiNeighborStrategy strat = new SuzukiNeighborStrategy();
91 final Pixel start = new Pixel(3, 4);
92 final Pixel from = new Pixel(3, 5);
93 strat.contour(img, start, from);
94 }
95 }