My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import static org.shapelogic.logic.CommonLogicExpressions.ASPECT_RATIO;
import static org.shapelogic.logic.CommonLogicExpressions.CURVE_ARCH_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.END_POINT_BOTTOM_CENTER_THIRD_POINT_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.END_POINT_BOTTOM_LEFT_THIRD_POINT_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.END_POINT_BOTTOM_POINT_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.END_POINT_BOTTOM_RIGHT_THIRD_POINT_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.END_POINT_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.END_POINT_TOP_LEFT_THIRD_POINT_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.END_POINT_TOP_RIGHT_THIRD_POINT_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.HARD_CORNER_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.HOLE_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.HORIZONTAL_LINE_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.MULTI_LINE_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.POINT_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.SOFT_POINT_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.T_JUNCTION_LEFT_POINT_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.T_JUNCTION_POINT_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.T_JUNCTION_RIGHT_POINT_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.U_JUNCTION_POINT_COUNT;
import static org.shapelogic.logic.CommonLogicExpressions.VERTICAL_LINE_COUNT;
import ij.ImagePlus;
import ij.process.ImageProcessor;

import org.shapelogic.imageprocessing.StreamVectorizerIJ;
import org.shapelogic.imageutil.IJImage;
import org.shapelogic.streamlogic.StreamNames;
import org.shapelogic.streams.StreamFactory;

/** Class running StreamVectorizer and matching polygons to digits.<br />
* <p>
* The main purpose of this is to demonstrate how users of ShapeLogic
* relatively easily can define their own match.
* This class did not need to be in the ShapeLogic jar file.
* </p>
* @author Sami Badawi
*
*/
public class DigitStreamVectorizer_ extends StreamVectorizerIJ {

@Override
protected void defineRules() {
loadDigitStream();
_categorizer = StreamFactory.findNumberedStream(StreamNames.LETTERS, this);
}

public void loadDigitStream() {
loadLetterStreams.loadPolygonStreams.loadStreamsRequiredForLetterMatch();
makeDigitStream();
String[] digits = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
loadLetterStreams.makeXOrStream(StreamNames.LETTERS,digits);
}

public void rule(String letter, String streamName, String predicate, double value) {
loadLetterStreams.rule(letter, streamName, predicate, value);
}

public void makeDigitStream() {

rule("0", HOLE_COUNT, "==", 1.);
rule("0", T_JUNCTION_POINT_COUNT, "==", 0.);
rule("0", END_POINT_COUNT, "==", 0.);
rule("0", MULTI_LINE_COUNT, "==", 1.);
rule("0", CURVE_ARCH_COUNT, ">", 0.);
rule("0", HARD_CORNER_COUNT, "==", 0.);
rule("0", SOFT_POINT_COUNT, ">", 0.);

rule("1", HOLE_COUNT, "==", 0.);
rule("1", T_JUNCTION_LEFT_POINT_COUNT, "==", 0.);
rule("1", T_JUNCTION_RIGHT_POINT_COUNT, "==", 0.);
rule("1", END_POINT_BOTTOM_POINT_COUNT, "==", 1.);
rule("1", HORIZONTAL_LINE_COUNT, "==", 0.);
rule("1", VERTICAL_LINE_COUNT, "==", 1.);
rule("1", END_POINT_COUNT, "==", 2.);
rule("1", MULTI_LINE_COUNT, "==", 0.);
rule("1", SOFT_POINT_COUNT, "==", 0.);
rule("1", ASPECT_RATIO, "<", 0.4);

rule("2", HOLE_COUNT, "==", 0.);
rule("2", END_POINT_TOP_LEFT_THIRD_POINT_COUNT, "==", 1.);
rule("2", END_POINT_BOTTOM_RIGHT_THIRD_POINT_COUNT, "==", 1.);
rule("2", END_POINT_COUNT, ">", 1.);
rule("2", END_POINT_COUNT, "<", 4.);
rule("2", POINT_COUNT,">", 3.);
rule("2", ASPECT_RATIO, ">", 0.5);
rule("2", ASPECT_RATIO, "<", 0.9);

rule("3", HOLE_COUNT, "==", 0.);
rule("3", T_JUNCTION_LEFT_POINT_COUNT, "==", 0.);
rule("3", END_POINT_TOP_LEFT_THIRD_POINT_COUNT, "==", 1.);
rule("3", END_POINT_BOTTOM_LEFT_THIRD_POINT_COUNT, "==", 1.);
rule("3", END_POINT_COUNT, ">", 1.);
rule("3", END_POINT_COUNT, "<", 4.);
rule("3", SOFT_POINT_COUNT, ">", 0.);
rule("3", POINT_COUNT, ">", 5.);
rule("3", ASPECT_RATIO, ">", 0.5);
rule("3", ASPECT_RATIO, "<", 0.9);

rule("4", HOLE_COUNT, "==", 1.);
rule("4", END_POINT_BOTTOM_RIGHT_THIRD_POINT_COUNT, "==", 1.);
rule("4", T_JUNCTION_RIGHT_POINT_COUNT, ">", 0.);
rule("4", T_JUNCTION_RIGHT_POINT_COUNT, "<", 4.);
rule("4", ASPECT_RATIO, ">", 0.5);
rule("4", ASPECT_RATIO, "<", 0.9);
rule("4", SOFT_POINT_COUNT, "==", 0.);
rule("4", HARD_CORNER_COUNT, ">", 1.);

rule("5", HOLE_COUNT, "==", 0.);
rule("5", END_POINT_TOP_RIGHT_THIRD_POINT_COUNT, "==", 1.);
rule("5", END_POINT_BOTTOM_LEFT_THIRD_POINT_COUNT, "==", 1.);
rule("5", END_POINT_COUNT, ">", 1.);
rule("5", END_POINT_COUNT, "<", 4.);
rule("5", POINT_COUNT,">", 3.);
rule("5", ASPECT_RATIO, ">", 0.5);
rule("5", ASPECT_RATIO, "<", 0.9);
rule("5", HARD_CORNER_COUNT, ">", 0.);
rule("5", SOFT_POINT_COUNT, ">", 0.);

rule("6", HOLE_COUNT, "==", 1.);
rule("6", END_POINT_TOP_RIGHT_THIRD_POINT_COUNT, "==", 1.);
rule("6", T_JUNCTION_LEFT_POINT_COUNT, ">", 0.);
rule("6", T_JUNCTION_LEFT_POINT_COUNT, "<", 4.);
rule("6", ASPECT_RATIO, ">", 0.5);
rule("6", ASPECT_RATIO, "<", 0.9);
rule("6", SOFT_POINT_COUNT, ">", 0.);
rule("6", HARD_CORNER_COUNT, "<", 2.);

rule("7", HOLE_COUNT, "==", 0.);
rule("7", END_POINT_TOP_LEFT_THIRD_POINT_COUNT, "==", 1.);
rule("7", END_POINT_BOTTOM_CENTER_THIRD_POINT_COUNT, "==", 1.);
rule("7", HORIZONTAL_LINE_COUNT, "==", 1.);
rule("7", END_POINT_COUNT, ">", 1.);
rule("7", END_POINT_COUNT, "<", 4.);
rule("7", POINT_COUNT,">", 2.);
rule("7", ASPECT_RATIO, ">", 0.5);
rule("7", ASPECT_RATIO, "<", 0.9);
rule("7", HARD_CORNER_COUNT, "==", 1.);

rule("8", HOLE_COUNT, "==", 2.);
rule("8", END_POINT_COUNT, "==", 0.);
rule("8", U_JUNCTION_POINT_COUNT, ">", 0.);
rule("8", ASPECT_RATIO, ">", 0.5);
rule("8", ASPECT_RATIO, "<", 0.9);
rule("8", SOFT_POINT_COUNT, ">", 0.);
rule("8", HARD_CORNER_COUNT, "<", 2.);

rule("9", HOLE_COUNT, "==", 1.);
rule("9", END_POINT_BOTTOM_LEFT_THIRD_POINT_COUNT, "==", 1.);
rule("9", T_JUNCTION_RIGHT_POINT_COUNT, ">", 0.);
rule("9", T_JUNCTION_RIGHT_POINT_COUNT, "<", 4.);
rule("9", ASPECT_RATIO, ">", 0.5);
rule("9", ASPECT_RATIO, "<", 0.9);
rule("9", SOFT_POINT_COUNT, ">", 1.);
rule("9", HARD_CORNER_COUNT, "<", 2.);
}

@Override
public void run(ImageProcessor ip) {
run();
}

@Override
public int setup(String arg, ImagePlus imp) {
_useNeuralNetwork = false;
return setup(arg, new IJImage(imp));
}
}

Change log

r1099 by sami.badawi on May 4, 2009   Diff
Change to DigitStreamVectorizer_ extends
StreamVectorizerIJ.
Go to: 
Project members, sign in to write a code review

Older revisions

r1071 by sami.badawi on Apr 18, 2009   Diff
Added neural network option to
StreamVectorizer.
r825 by sami.badawi on Aug 21, 2008   Diff
It is now directly sub classed from
the StreamVectorizer so it is both an
ImageOperation and a ImageJ plugin.
r714 by sami.badawi on Jun 29, 2008   Diff
Took out unused imports.
All revisions of this file

File info

Size: 6845 bytes, 166 lines

File properties

svn:mime-type
text/plain
Powered by Google Project Hosting