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 MooreNeighborStrategyTest {
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 MooreNeighborStrategy();
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
77 @Test
78 public void testOpenLoop() throws Exception {
79 final float[][] pixels = new float[][] {
80 new float[] { 0, 0, 0, 0, 0, 0, 0, 0 },
81 new float[] { 0, 0, 0, 0, 0, 0, 0, 0 },
82 new float[] { 0, 0, 0, 0, 0, 1, 1, 0 },
83 new float[] { 0, 0, 0, 1, 0, 0, 1, 0 },
84 new float[] { 0, 0, 0, 1, 0, 1, 1, 0 },
85 new float[] { 0, 0, 0, 0, 1, 1, 0, 0 },
86 new float[] { 0, 0, 0, 0, 0, 0, 0, 0 }
87 };
88
89 final FImage img = new FImage(pixels);
90
91 final MooreNeighborStrategy strat = new MooreNeighborStrategy();
92 final Pixel start = new Pixel(3, 4);
93 final Pixel from = new Pixel(3, 5);
94 strat.contour(img, start, from);
95 }
96
97 }