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 package org.openimaj.image.text.extraction;
34
35 import java.util.Map;
36
37 import org.openimaj.citation.annotation.Reference;
38 import org.openimaj.citation.annotation.ReferenceType;
39 import org.openimaj.image.DisplayUtilities;
40 import org.openimaj.image.FImage;
41 import org.openimaj.image.analysis.pyramid.PyramidProcessor;
42 import org.openimaj.image.analysis.pyramid.gaussian.GaussianOctave;
43 import org.openimaj.image.analysis.pyramid.gaussian.GaussianPyramid;
44 import org.openimaj.image.analysis.pyramid.gaussian.GaussianPyramidOptions;
45 import org.openimaj.image.processing.resize.ResizeProcessor;
46 import org.openimaj.math.geometry.shape.Rectangle;
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 @Reference(
67 type = ReferenceType.Inproceedings,
68 author = { "Liu, X.", "Samarabandu, J." },
69 title = "Multiscale Edge-Based Text Extraction from Complex Images",
70 year = "2006",
71 booktitle = "Multimedia and Expo, 2006 IEEE International Conference on",
72 pages = { "1721 ", "1724" },
73 month = "july",
74 number = "",
75 volume = "",
76 customData = { "keywords", "multiscale edge-based text extraction;printed document image;scene text;text detection;document image processing;edge detection;feature extraction;text analysis;", "doi", "10.1109/ICME.2006.262882", "ISSN", "" }
77 )
78 public class LiuSamarabanduTextExtractorMultiscale extends TextExtractor<FImage>
79 {
80 private static final boolean DEBUG = true;
81
82
83 private final LiuSamarabanduTextExtractorBasic basicTextExtractor =
84 new LiuSamarabanduTextExtractorBasic();
85
86
87 private Map<Rectangle, FImage> extractedRegions;
88
89
90 private boolean doubleSizePyramid = true;
91
92
93
94
95
96
97
98
99
100 public class PyramidTextExtractor implements PyramidProcessor<FImage>
101 {
102
103 private FImage featureMap = null;
104
105
106
107
108
109 public FImage getFeatureMap()
110 {
111 return this.featureMap;
112 }
113
114
115
116
117
118 @Override
119 public void process( final GaussianPyramid<FImage> pyramid )
120 {
121 FImage fmap = null;
122
123
124 for( final GaussianOctave<FImage> octave : pyramid )
125 {
126
127 FImage octaveFMap = LiuSamarabanduTextExtractorMultiscale.this.basicTextExtractor.textRegionDetection(
128 octave.getNextOctaveImage() );
129
130 if( fmap == null )
131 fmap = octaveFMap;
132 else
133 {
134
135 octaveFMap = ResizeProcessor.resample( octaveFMap,
136 fmap.getWidth(), fmap.getHeight() ).normalise();
137
138 if( LiuSamarabanduTextExtractorMultiscale.DEBUG )
139 DisplayUtilities.display( octaveFMap, "Resized feature map" );
140
141 fmap.addInplace( octaveFMap );
142 }
143 }
144
145 this.featureMap = fmap;
146 }
147 }
148
149
150
151
152 protected void forceWait()
153 {
154 synchronized(this){ try { this.wait( 200000 ); } catch( final InterruptedException e1 ) {} }
155 }
156
157
158
159
160
161 @Override
162 public void processImage( final FImage image )
163 {
164 final PyramidTextExtractor ped = new PyramidTextExtractor();
165
166
167 final GaussianPyramidOptions<FImage> gpo = new GaussianPyramidOptions<FImage>();
168 gpo.setScales( 1 );
169 gpo.setExtraScaleSteps( 1 );
170 gpo.setPyramidProcessor( ped );
171 gpo.setDoubleInitialImage( this.doubleSizePyramid );
172
173
174 final GaussianPyramid<FImage> gp = new GaussianPyramid<FImage>( gpo );
175 image.analyseWith( gp );
176
177
178
179
180 FImage msFMap = ped.getFeatureMap();
181
182
183 FImage fmap = this.basicTextExtractor.textRegionDetection( image );
184
185
186 if( this.doubleSizePyramid )
187 fmap = ResizeProcessor.doubleSize( fmap );
188
189
190 msFMap = fmap.add( msFMap );
191
192
193 if( LiuSamarabanduTextExtractorMultiscale.DEBUG )
194 DisplayUtilities.display( msFMap.normalise(), "Fused Feature Map" );
195
196
197 this.basicTextExtractor.processFeatureMap( msFMap, image );
198
199
200 this.extractedRegions = this.basicTextExtractor.getTextRegions();
201
202
203 if( this.doubleSizePyramid )
204 for( final Rectangle r : this.extractedRegions.keySet() )
205 r.scale( 0.5f );
206
207
208 image.internalAssign( fmap );
209 }
210
211
212
213
214
215 @Override
216 public Map<Rectangle, FImage> getTextRegions()
217 {
218 return this.extractedRegions;
219 }
220
221
222
223
224
225 public boolean isDoubleSizePyramid()
226 {
227 return this.doubleSizePyramid;
228 }
229
230
231
232
233
234 public void setDoubleSizePyramid( final boolean doubleSizePyramid )
235 {
236 this.doubleSizePyramid = doubleSizePyramid;
237 }
238 }