Page 1 of 1

Remove Vertical Lines for Pre OCR (Tesseract)

Posted: 2013-07-10T13:54:08-07:00
by dabgdk
I wish to remove vertical lines from an image of a form so that Tesseract will be able to read the piece of data in those lines.

More specifically, this form has a small box containing "NUMBER: XXXXX" which Tesseract does not even attempt to read because of the box surrounding it. I verified that removing the vertical lines making up the right and left sides of this box allows Tesseract to read the contents.

Does Imagemagick have the ability to do this? From what I've read, I need to do a "Hough Transform", and that Imagemagick does not support this. Yet, from http://www.imagemagick.org/Usage/morphology/:

This particular kernel is also good at defining long horizontal and vertical lines, allowing you to search for such objects within images.
This is essentially what I want to do: find (and remove) a long line, more than 1 pixel wide. How might this be done?

Re: Remove Vertical Lines for Pre OCR (Tesseract)

Posted: 2013-07-10T14:04:20-07:00
by fmw42
Please post a link to an example image so we can see what your problem is and try some experiments.

Re: Remove Vertical Lines for Pre OCR (Tesseract)

Posted: 2013-07-11T04:57:52-07:00
by dabgdk

Re: Remove Vertical Lines for Pre OCR (Tesseract)

Posted: 2013-07-11T10:31:25-07:00
by fmw42
Are all the images this simple? Or is this just a small part of a larger image? If the latter, is the box always the same size and shape?

If this is the whole image then, the vertical lines can be removed by averaging the image down to one row. Then scan the data from each end and find the darkest pixels closest to the left and right edge. You may want to blur the image first or apply a morphology operation to close the white area between the double box.

Once you know how the x location and how wide it is, you can composite a white vertical strip over the original image to mask out those vertical lines.


convert example_box_ocr.png -morphology open diamond:1 -scale 545x1! txt:

Code: Select all

# ImageMagick pixel enumeration: 545,1,255,srgb
0,0: (255,255,255)  #FFFFFF  white
1,0: (255,255,255)  #FFFFFF  white
2,0: (255,255,255)  #FFFFFF  white
3,0: (255,255,255)  #FFFFFF  white
4,0: (255,255,255)  #FFFFFF  white
5,0: (255,255,255)  #FFFFFF  white
6,0: (255,255,255)  #FFFFFF  white
7,0: (255,255,255)  #FFFFFF  white
8,0: (255,255,255)  #FFFFFF  white
9,0: (255,255,255)  #FFFFFF  white
10,0: (255,255,255)  #FFFFFF  white
11,0: (255,255,255)  #FFFFFF  white
12,0: (255,255,255)  #FFFFFF  white
13,0: (255,255,255)  #FFFFFF  white
14,0: (255,255,255)  #FFFFFF  white
15,0: (255,255,255)  #FFFFFF  white
16,0: (255,255,255)  #FFFFFF  white
17,0: (255,255,255)  #FFFFFF  white
18,0: (255,255,255)  #FFFFFF  white
19,0: (255,255,255)  #FFFFFF  white
20,0: (255,255,255)  #FFFFFF  white
21,0: (255,255,255)  #FFFFFF  white
22,0: (255,255,255)  #FFFFFF  white
23,0: ( 71, 71, 71)  #474747  srgb(71,71,71)
24,0: ( 67, 67, 67)  #434343  srgb(67,67,67)
25,0: ( 67, 67, 67)  #434343  srgb(67,67,67)
26,0: ( 67, 67, 67)  #434343  srgb(67,67,67)
27,0: ( 67, 67, 67)  #434343  srgb(67,67,67)
28,0: ( 67, 67, 67)  #434343  srgb(67,67,67)
29,0: ( 67, 67, 67)  #434343  srgb(67,67,67)
30,0: ( 67, 67, 67)  #434343  srgb(67,67,67)
31,0: (222,222,222)  #DEDEDE  srgb(222,222,222)
32,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
33,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
34,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
35,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
36,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
37,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
38,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
39,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
40,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
41,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
42,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
43,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
44,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
45,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
46,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
47,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
48,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
49,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
50,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
51,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
52,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
53,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
54,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
55,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
56,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
57,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
58,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
59,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
60,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
61,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
62,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
63,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
64,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
65,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
66,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
67,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
68,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
69,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
70,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
71,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
72,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
73,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
74,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
75,0: (214,214,214)  #D6D6D6  srgb(214,214,214)
76,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
77,0: (211,211,211)  #D3D3D3  srgb(211,211,211)
78,0: (209,209,209)  #D1D1D1  srgb(209,209,209)
79,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
80,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
81,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
82,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
83,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
84,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
85,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
86,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
87,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
88,0: (186,186,186)  #BABABA  srgb(186,186,186)
89,0: (183,183,183)  #B7B7B7  srgb(183,183,183)
90,0: (181,181,181)  #B5B5B5  srgb(181,181,181)
91,0: (181,181,181)  #B5B5B5  srgb(181,181,181)
92,0: (216,216,216)  #D8D8D8  srgb(216,216,216)
93,0: (217,217,217)  #D9D9D9  srgb(217,217,217)
94,0: (217,217,217)  #D9D9D9  srgb(217,217,217)
95,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
96,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
97,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
98,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
99,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
100,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
101,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
102,0: (217,217,217)  #D9D9D9  srgb(217,217,217)
103,0: (217,217,217)  #D9D9D9  srgb(217,217,217)
104,0: (217,217,217)  #D9D9D9  srgb(217,217,217)
105,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
106,0: (181,181,181)  #B5B5B5  srgb(181,181,181)
107,0: (183,183,183)  #B7B7B7  srgb(183,183,183)
108,0: (184,184,184)  #B8B8B8  srgb(184,184,184)
109,0: (189,189,189)  #BDBDBD  srgb(189,189,189)
110,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
111,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
112,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
113,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
114,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
115,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
116,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
117,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
118,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
119,0: (199,199,199)  #C7C7C7  srgb(199,199,199)
120,0: (204,204,204)  #CCCCCC  grey80
121,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
122,0: (206,206,206)  #CECECE  srgb(206,206,206)
123,0: (206,206,206)  #CECECE  srgb(206,206,206)
124,0: (206,206,206)  #CECECE  srgb(206,206,206)
125,0: (206,206,206)  #CECECE  srgb(206,206,206)
126,0: (211,211,211)  #D3D3D3  srgb(211,211,211)
127,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
128,0: (211,211,211)  #D3D3D3  srgb(211,211,211)
129,0: (209,209,209)  #D1D1D1  srgb(209,209,209)
130,0: (206,206,206)  #CECECE  srgb(206,206,206)
131,0: (206,206,206)  #CECECE  srgb(206,206,206)
132,0: (206,206,206)  #CECECE  srgb(206,206,206)
133,0: (206,206,206)  #CECECE  srgb(206,206,206)
134,0: (206,206,206)  #CECECE  srgb(206,206,206)
135,0: (202,202,202)  #CACACA  srgb(202,202,202)
136,0: (201,201,201)  #C9C9C9  srgb(201,201,201)
137,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
138,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
139,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
140,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
141,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
142,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
143,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
144,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
145,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
146,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
147,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
148,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
149,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
150,0: (201,201,201)  #C9C9C9  srgb(201,201,201)
151,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
152,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
153,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
154,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
155,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
156,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
157,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
158,0: (206,206,206)  #CECECE  srgb(206,206,206)
159,0: (202,202,202)  #CACACA  srgb(202,202,202)
160,0: (199,199,199)  #C7C7C7  srgb(199,199,199)
161,0: (189,189,189)  #BDBDBD  srgb(189,189,189)
162,0: (183,183,183)  #B7B7B7  srgb(183,183,183)
163,0: (186,186,186)  #BABABA  srgb(186,186,186)
164,0: (192,192,192)  #C0C0C0  srgb(192,192,192)
165,0: (206,206,206)  #CECECE  srgb(206,206,206)
166,0: (217,217,217)  #D9D9D9  srgb(217,217,217)
167,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
168,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
169,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
170,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
171,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
172,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
173,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
174,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
175,0: (201,201,201)  #C9C9C9  srgb(201,201,201)
176,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
177,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
178,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
179,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
180,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
181,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
182,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
183,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
184,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
185,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
186,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
187,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
188,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
189,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
190,0: (214,214,214)  #D6D6D6  srgb(214,214,214)
191,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
192,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
193,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
194,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
195,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
196,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
197,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
198,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
199,0: (179,179,179)  #B3B3B3  srgb(179,179,179)
200,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
201,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
202,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
203,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
204,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
205,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
206,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
207,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
208,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
209,0: (212,212,212)  #D4D4D4  srgb(212,212,212)
210,0: (211,211,211)  #D3D3D3  srgb(211,211,211)
211,0: (209,209,209)  #D1D1D1  srgb(209,209,209)
212,0: (206,206,206)  #CECECE  srgb(206,206,206)
213,0: (183,183,183)  #B7B7B7  srgb(183,183,183)
214,0: (181,181,181)  #B5B5B5  srgb(181,181,181)
215,0: (184,184,184)  #B8B8B8  srgb(184,184,184)
216,0: (189,189,189)  #BDBDBD  srgb(189,189,189)
217,0: (209,209,209)  #D1D1D1  srgb(209,209,209)
218,0: (222,222,222)  #DEDEDE  srgb(222,222,222)
219,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
220,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
221,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
222,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
223,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
224,0: (211,211,211)  #D3D3D3  srgb(211,211,211)
225,0: (211,211,211)  #D3D3D3  srgb(211,211,211)
226,0: (211,211,211)  #D3D3D3  srgb(211,211,211)
227,0: (211,211,211)  #D3D3D3  srgb(211,211,211)
228,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
229,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
230,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
231,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
232,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
233,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
234,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
235,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
236,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
237,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
238,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
239,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
240,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
241,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
242,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
243,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
244,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
245,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
246,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
247,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
248,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
249,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
250,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
251,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
252,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
253,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
254,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
255,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
256,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
257,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
258,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
259,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
260,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
261,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
262,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
263,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
264,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
265,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
266,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
267,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
268,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
269,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
270,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
271,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
272,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
273,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
274,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
275,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
276,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
277,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
278,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
279,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
280,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
281,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
282,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
283,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
284,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
285,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
286,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
287,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
288,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
289,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
290,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
291,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
292,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
293,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
294,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
295,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
296,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
297,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
298,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
299,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
300,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
301,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
302,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
303,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
304,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
305,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
306,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
307,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
308,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
309,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
310,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
311,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
312,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
313,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
314,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
315,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
316,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
317,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
318,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
319,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
320,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
321,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
322,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
323,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
324,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
325,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
326,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
327,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
328,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
329,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
330,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
331,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
332,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
333,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
334,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
335,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
336,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
337,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
338,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
339,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
340,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
341,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
342,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
343,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
344,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
345,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
346,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
347,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
348,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
349,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
350,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
351,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
352,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
353,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
354,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
355,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
356,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
357,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
358,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
359,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
360,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
361,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
362,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
363,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
364,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
365,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
366,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
367,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
368,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
369,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
370,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
371,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
372,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
373,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
374,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
375,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
376,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
377,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
378,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
379,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
380,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
381,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
382,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
383,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
384,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
385,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
386,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
387,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
388,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
389,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
390,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
391,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
392,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
393,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
394,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
395,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
396,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
397,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
398,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
399,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
400,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
401,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
402,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
403,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
404,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
405,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
406,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
407,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
408,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
409,0: (211,211,211)  #D3D3D3  srgb(211,211,211)
410,0: (197,197,197)  #C5C5C5  srgb(197,197,197)
411,0: (191,191,191)  #BFBFBF  srgb(191,191,191)
412,0: (188,188,188)  #BCBCBC  srgb(188,188,188)
413,0: (184,184,184)  #B8B8B8  srgb(184,184,184)
414,0: (197,197,197)  #C5C5C5  srgb(197,197,197)
415,0: (202,202,202)  #CACACA  srgb(202,202,202)
416,0: (204,204,204)  #CCCCCC  grey80
417,0: (206,206,206)  #CECECE  srgb(206,206,206)
418,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
419,0: (206,206,206)  #CECECE  srgb(206,206,206)
420,0: (206,206,206)  #CECECE  srgb(206,206,206)
421,0: (201,201,201)  #C9C9C9  srgb(201,201,201)
422,0: (199,199,199)  #C7C7C7  srgb(199,199,199)
423,0: (189,189,189)  #BDBDBD  srgb(189,189,189)
424,0: (192,192,192)  #C0C0C0  srgb(192,192,192)
425,0: (197,197,197)  #C5C5C5  srgb(197,197,197)
426,0: (204,204,204)  #CCCCCC  grey80
427,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
428,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
429,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
430,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
431,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
432,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
433,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
434,0: (214,214,214)  #D6D6D6  srgb(214,214,214)
435,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
436,0: (204,204,204)  #CCCCCC  grey80
437,0: (199,199,199)  #C7C7C7  srgb(199,199,199)
438,0: (199,199,199)  #C7C7C7  srgb(199,199,199)
439,0: (202,202,202)  #CACACA  srgb(202,202,202)
440,0: (206,206,206)  #CECECE  srgb(206,206,206)
441,0: (206,206,206)  #CECECE  srgb(206,206,206)
442,0: (206,206,206)  #CECECE  srgb(206,206,206)
443,0: (206,206,206)  #CECECE  srgb(206,206,206)
444,0: (209,209,209)  #D1D1D1  srgb(209,209,209)
445,0: (211,211,211)  #D3D3D3  srgb(211,211,211)
446,0: (214,214,214)  #D6D6D6  srgb(214,214,214)
447,0: (216,216,216)  #D8D8D8  srgb(216,216,216)
448,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
449,0: (222,222,222)  #DEDEDE  srgb(222,222,222)
450,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
451,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
452,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
453,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
454,0: (214,214,214)  #D6D6D6  srgb(214,214,214)
455,0: (207,207,207)  #CFCFCF  srgb(207,207,207)
456,0: (204,204,204)  #CCCCCC  grey80
457,0: (199,199,199)  #C7C7C7  srgb(199,199,199)
458,0: (199,199,199)  #C7C7C7  srgb(199,199,199)
459,0: (202,202,202)  #CACACA  srgb(202,202,202)
460,0: (206,206,206)  #CECECE  srgb(206,206,206)
461,0: (206,206,206)  #CECECE  srgb(206,206,206)
462,0: (206,206,206)  #CECECE  srgb(206,206,206)
463,0: (206,206,206)  #CECECE  srgb(206,206,206)
464,0: (209,209,209)  #D1D1D1  srgb(209,209,209)
465,0: (211,211,211)  #D3D3D3  srgb(211,211,211)
466,0: (214,214,214)  #D6D6D6  srgb(214,214,214)
467,0: (216,216,216)  #D8D8D8  srgb(216,216,216)
468,0: (219,219,219)  #DBDBDB  srgb(219,219,219)
469,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
470,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
471,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
472,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
473,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
474,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
475,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
476,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
477,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
478,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
479,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
480,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
481,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
482,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
483,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
484,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
485,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
486,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
487,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
488,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
489,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
490,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
491,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
492,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
493,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
494,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
495,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
496,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
497,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
498,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
499,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
500,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
501,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
502,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
503,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
504,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
505,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
506,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
507,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
508,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
509,0: (225,225,225)  #E1E1E1  srgb(225,225,225)
510,0: (222,222,222)  #DEDEDE  srgb(222,222,222)
511,0: ( 67, 67, 67)  #434343  srgb(67,67,67)
512,0: ( 67, 67, 67)  #434343  srgb(67,67,67)
513,0: ( 67, 67, 67)  #434343  srgb(67,67,67)
514,0: ( 67, 67, 67)  #434343  srgb(67,67,67)
515,0: ( 67, 67, 67)  #434343  srgb(67,67,67)
516,0: ( 67, 67, 67)  #434343  srgb(67,67,67)
517,0: ( 67, 67, 67)  #434343  srgb(67,67,67)
518,0: ( 71, 71, 71)  #474747  srgb(71,71,71)
519,0: (255,255,255)  #FFFFFF  white
520,0: (255,255,255)  #FFFFFF  white
521,0: (255,255,255)  #FFFFFF  white
522,0: (255,255,255)  #FFFFFF  white
523,0: (255,255,255)  #FFFFFF  white
524,0: (255,255,255)  #FFFFFF  white
525,0: (255,255,255)  #FFFFFF  white
526,0: (255,255,255)  #FFFFFF  white
527,0: (255,255,255)  #FFFFFF  white
528,0: (255,255,255)  #FFFFFF  white
529,0: (255,255,255)  #FFFFFF  white
530,0: (255,255,255)  #FFFFFF  white
531,0: (255,255,255)  #FFFFFF  white
532,0: (255,255,255)  #FFFFFF  white
533,0: (255,255,255)  #FFFFFF  white
534,0: (255,255,255)  #FFFFFF  white
535,0: (255,255,255)  #FFFFFF  white
536,0: (255,255,255)  #FFFFFF  white
537,0: (255,255,255)  #FFFFFF  white
538,0: (255,255,255)  #FFFFFF  white
539,0: (255,255,255)  #FFFFFF  white
540,0: (255,255,255)  #FFFFFF  white
541,0: (255,255,255)  #FFFFFF  white
542,0: (255,255,255)  #FFFFFF  white
543,0: (255,255,255)  #FFFFFF  white
544,0: (255,255,255)  #FFFFFF  white
You can get a visual representation by using Anthony's im_profile script (http://www.imagemagick.org/Usage/scripts/) or my profile script.

convert example_box_ocr.png -morphology open diamond:1 -scale 545x1! miff:- | im_profile - profile1.gif
Image

or

convert example_box_ocr.png -morphology open diamond:1 -scale 545x1! miff:- | profile - profile2.gif
Image


From the above txt listing you can see the location and width of the left and right dark vertical lines are

left: between x=23 and 30
right: between x=511 and 518

convert example_box_ocr.png -size 8x155 xc:white -geometry +23+0 -compose over -composite \
-size 8x155 xc:white -geometry +511+0 -compose over -composite processedbox.png

Image

You can do the same now to remove the horizontal lines if you want by repeating but averaging to one column

Re: Remove Vertical Lines for Pre OCR (Tesseract)

Posted: 2013-07-11T12:07:21-07:00
by dabgdk
fmw42,

Unfortunately, no, this image is a part of a larger image, which I will link to here: http://postimg.org/image/hjx9wujnj/

I cannot provide the original owing to privacy concerns, but I think you can see that averaging all rows to a single row, and then removing the darkest pixels will not work for this situation because this would cause columns with many letters in them to be whited out.

I appreciate the cleverness of your method, though. Might there be another way?

The box does always show up in the top right portion of the page, but it's location is not concrete because other images (of the same form) might come from scanners which would have slightly different dimensions.

Re: Remove Vertical Lines for Pre OCR (Tesseract)

Posted: 2013-07-11T16:06:20-07:00
by snibgo
This removes the vertical double-lines. There is probably a far more elegant method. Windows script:

Code: Select all

convert example_box_ocr.png ^
  -verbose ^
  -define morphology:compose=lighten ^
  -morphology Thicken ^
10x1+1+0:1,0,0,0,1,0,0,0,0,1;^
10x1+2+0:1,0,0,0,1,0,0,0,0,1;^
10x1+3+0:1,0,0,0,1,0,0,0,0,1;^
10x1+5+0:1,0,0,0,1,0,0,0,0,1;^
10x1+6+0:1,0,0,0,1,0,0,0,0,1;^
10x1+7+0:1,0,0,0,1,0,0,0,0,1;^
10x1+8+0:1,0,0,0,1,0,0,0,0,1 ^
  -morphology Thicken ^
10x1+1+0:1,0,0,0,0,1,0,0,0,1;^
10x1+2+0:1,0,0,0,0,1,0,0,0,1;^
10x1+3+0:1,0,0,0,0,1,0,0,0,1;^
10x1+4+0:1,0,0,0,0,1,0,0,0,1;^
10x1+6+0:1,0,0,0,0,1,0,0,0,1;^
10x1+7+0:1,0,0,0,0,1,0,0,0,1;^
10x1+8+0:1,0,0,0,0,1,0,0,0,1 ^
  e.png

Re: Remove Vertical Lines for Pre OCR (Tesseract)

Posted: 2013-07-11T21:05:21-07:00
by snibgo
Or define the problem as "remove all horizontal or vertical black lines that are at least 30 pixels long":

Code: Select all

convert example_box_ocr.png ^
  -define morphology:compose=lighten ^
  -morphology Thicken ^
1x30+0+0^<:0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ^
  e.png
EDIT: We can do without all those zeros, but with some extra processing:

Code: Select all

convert example_box_ocr.png ^
  -negate ^
  -define morphology:compose=darken ^
  -morphology Thinning Rectangle:1x30+0+0^< ^
  -negate ^
  e2.png
EDIT2: These work for the sample image, but more thought verified by experiment shows they don't do quite what I said. Lines >= 60 pixels are removed. Lines < 30 pixels are untouched. Lines >= 30 but < 60 pixels are reduced in length but not eliminated.

Re: Remove Vertical Lines for Pre OCR (Tesseract)

Posted: 2013-07-12T05:27:58-07:00
by dabgdk
Thanks, this works fairly well.

The text lined up with areas that are whited out does get a little rumpled, but Tesseract is able to read that anyway.