Software module for digitizing damaged documents

 3r3197. 3r3-31. 3r3181. Optical Character Recognition (OCR) is the process of obtaining printed texts in a digitized format. If you read a classic novel on a digital device or asked a doctor to pick up old medical records through the hospital's computer system, you probably took advantage of OCR. 3r3186. 3r3179.  3r3197. 3r3181. OCR makes previously static content editable, searchable and exchangeable. But many documents seeking to digitize contain coffee stains, faded sunspots, pages with curled corners, and many wrinkles retain some printed documents in non-digitized form. 3r3186. 3r3179.  3r3197. 3r3181. Everyone has long known that there are millions of old books that are stored in the vaults. The use of these books is prohibited because of their dilapidation and decrepitude, and therefore the digitization of these books is so important. 3r3186. 3r3179.  3r3197. 3r3181. The paper deals with the task of clearing text from noise, recognizing text in an image and converting it into text format. 3r3186. 3r3179.  3r3197. 3r3181. Software module for digitizing damaged documents 3r3186. 3r3179.  3r3197. 3r3181. For training used 144 pictures. The size may be different, but preferably should be within reason. Pictures must be in PNG format. After reading the image, binarization is used - the process of converting a color image to black and white, that is, each pixel is normalized to the range from 0 to 25? where 0 is black, 255 is white. 3r3186. 3r3179.  3r3197. 3r3181. To train a convolutional network, you need more images than there are. It was decided to divide the images into parts. Since the training sample consists of images of different sizes, each image was compressed to 448x448 pixels. The result was 144 images in the resolution of 448x448 pixels. After that, they were all cut into non-overlapping windows measuring 112x112 pixels. 3r3186.
3r3185. 3r3179.  3r3197. 3r3181. 3r3334. 3r3186. 3r3179.  3r3197. 3r3181. Thus, of the 144 original images, about ?304 images were obtained in the training set. But this was not enough. For good learning of the convolution network, more examples are needed. In consequence of this, the best option was to rotate the pictures by 90 degrees, then by 180 and 270 degrees. As a result, an array with the size of[16,112,112,1]is fed to the input of the network. . Where 16 is the number of images, 112 is the width and height of each image, 1 is the color channels. It turned out 9216 examples for learning. This is enough to train a convolutional network. 3r3186. 3r3179.  3r3197. 3r3181. 3r3186. 3r3179.  3r3197. 3r3181. Each image has a size of 112x112 pixels. If the size is too large, the computational complexity will increase, respectively, the limitations on the speed of response will be violated, the size determination in this problem is solved by the selection method. If you choose a size that is too small, the network will not be able to identify key features. Each image has a black and white format, so it is divided into 1 channel. Color images are divided into 3 channels: red, blue, green. Since we have black and white images, the size of each image is 112x122x1 pixels. 3r3186. 3r3179.  3r3197. 3r3181. First of all, it is necessary to train a convolutional neural network on the harvested, processed images. For this task, the U-Net architecture was chosen. 3r3186. 3r3179.  3r3197. 3r3181. A reduced version of the architecture was selected, consisting of only two blocks (the original version of four). An important consideration was the fact that a large class of well-known binarization algorithms is explicitly expressed in such an architecture or a similar architecture (as an example, we can take a modification of the Niblack algorithm with the replacement of the standard deviation by the mean deviation module, in this case the network is especially simple) 3r3186. 3r3179.  3r3197. 3r3181. 3r360. 3r3186. 3r3179.  3r3197. 3r3181. The advantage of this architecture is that you can create a sufficient amount of training data from a small number of source images for network training. At the same time, the network has a relatively small number of weights due to its convolutional architecture. But there are some nuances. In particular, the artificial neural network used, strictly speaking, does not solve the problem of binarization: each pixel of the original image is associated with a certain number from 0 to ? which characterizes the degree to which a given pixel belongs to one of the classes (meaningful filling or background). still convert to final binary answer.[1]3r3186. 3r3179.  3r3197. 3r3181. U-Net consists of a contraction and decompressive path and “forwarding” between them. The compression path, in this architecture, consists of two blocks (in the original version of four). In each block, there are two convolutions with a 3x3 filter (using the Tanh activation function after convolution) and a pooling with a filter size of 2x2 in increments of 2. The number of channels at each step down is doubled. 3r3186. 3r3179.  3r3197. 3r3181. Splitter path also consists of two blocks. Each of them consists of a “sweep” with a 2x2 filter size, halving the number of channels, concatenation with a corresponding truncated feature map from a compression path (“forwarding”), and two bundles with a 3x3 filter (using the Tanh activation function after folding). Next, on the last layer, a 1x1 convolution (using the Sigmoid activation function) to produce an output, flat image. Note that clipping the feature map during concatenation is significant due to the loss of boundary pixels at each convolution. Adam was chosen as the method of stochastic optimization. 3r3186. 3r3179.  3r3197. 3r3181. In general, the architecture is a sequence of layers of convolution + pooling, which reduce the spatial resolution of the image, then increase it by combining with the image data in advance and passing it through other layers of the convolution. Thus, the network serves as a kind of filter.[2]3r3186. 3r3179.  3r3197. 3r3181. The test sample consisted of similar images, the differences were only in the texture of noise and in the text. Network testing took place on this image. 3r3186. 3r3179.  3r3197. 3r3181. 3r3186. 3r3179.  3r3197. 3r3181. At the output of a convolutional neural network, an array of numbers with the size[16,112,112,1]is obtained. . Each number is a separate pixel processed by the network. The images have a format of 112x112 pixels, as before, it was cut into pieces. She needs to betray the original look. We merge the resulting images into one part, as a result, the picture has a format of 448x448. Then we multiply each number in the array by 255 to get a range from 0 to 25? where 0 is black, 255 is white. We return the image to its original size, as before, it was compressed. The result is a picture below in the picture. 3r3186. 3r3179.  3r3197. 3r3181. 3r3394. 3r3186. 3r3179.  3r3197. 3r3181. In this example, it is clear that the convolutional network has coped with the majority of noisiness and has proven itself operational. But it is clearly seen that the picture has become duller and the missed noises are visible. In the future, this may affect the accuracy of text recognition. 3r3186. 3r3179.  3r3197. 3r3181. Based on this fact, it was decided to use another neural network - a multilayer perceptron. In the expected result, the network should make the text in the image clearer and remove the noisiness missed by the convolutional neural network. 3r3186. 3r3179.  3r3197. 3r3181. An image that has already been processed by a convolutional network is sent to the input of the multilayer perceptron. In this case, the training sample for this network will differ from the sample for the convolutional network, since the networks process the image differently. A convolutional network is considered to be the main network and removes most of the noise in the image, while the multi-layer perceptron processes what the convolutional failed. 3r3179.  3r3197. Here are some examples from a training sample for a multilayer perceptron. 3r3186. 3r3179.  3r3197. 3r3181. 3r3113. 3r3186. 3r3179.  3r3197. 3r3181. Image data was obtained by processing a training sample for a convolutional network with a multilayer perceptron. At the same time, the perceptron was trained on the same sample, but on a small number of examples and a small number of epochs. 3r3186. 3r3179.  3r3197. 3r3181. For perceptron training, 36 images were processed. The network is trained pixel-by-pixel, that is, one pixel from the image is sent to the input of the network. At the output of the network we also get one output neuron - one pixel, that is, the response of the network. To increase the processing accuracy, 29 input neurons were made. And on the image obtained after processing by the convolutional network, 28 filters are superimposed. The result is 29 images with different filters. We send one pixel from each 29 images to the network input and only one pixel is received at the network output, that is, the network response. 3r3186. 3r3179.  3r3197. 3r3181. 3r3186. 3r3179.  3r3197. 3r3181. This was done for better learning and networking. After that, the network began to increase the accuracy and contrast of the image. It also clears minor errors that could not clear the convolutional network. 3r3186. 3r3179.  3r3197. 3r3181. As a result, the neural network has 29 input neurons, one pixel from each image. After the experiments, it was found that only one hidden layer is needed, in which there are 500 neurons. Outlet at the network one. Since learning occurred pixel by pixel, the network was accessed n * m times, where n is the width of the image, and m is the height, respectively. 3r3186. 3r3179.  3r3197. 3r3181. 3r3186. 3r3179.  3r3197. 3r3181. After image processing by successively two neural networks, the main thing that remains is to recognize the text. For this, a ready-made solution was taken, namely the Pytesseract Python library. Pytesseract does not provide true Python bindings. Rather, it is a simple wrapper for the tesseract binary file. In this case, tesseract is installed separately on the computer. Pytesseract saves the image to a temporary file on disk, then calls the tesseract binary file and writes the result to a file. 3r3186. 3r3179.  3r3197. 3r3181. This wrapper is developed by Google and is free and free to use. It can be used both in their own and for commercial purposes. The library works without an internet connection, supports many languages ​​for recognition and impresses with its speed. Its application can be found in various popular applications. 3r3186. 3r3179.  3r3197. 3r3181. The last item left is to write the recognized text to a file in a format suitable for its processing. We use for this the usual notebook, which opens, after the completion of the program. Also, the text is displayed on the test interface. An illustrative example of the interface. 3r3186. 3r3179.  3r3197. 3r3181. 3r3186. 3r3179.  3r3197. 3r3181. 3r3183. References: 3r3184. 3r3186. 3r3179.  3r3197. 3r3r1616.  3r3197. 3r3173. The history of victory in the international competition for the recognition of documents by the SmartEngines[Электронный ресурс]company team. . Access mode: 3r3169. https://habr.com/company/smartengines/blog/344550/ 3r3176.  3r3197. 3r3173. Image segmentation using neural network: U-Net[Электроный ресурс]. Access mode: 3r3174. http://robocraft.ru/blog/machinelearning/3671.html
3r3176.  3r3197. 3r3178. 3r3179.  3r3197. 3r3181. 3r3182. > The repository on github
3r3185. 3r3186. 3r3193. 3r3197. 3r3197. 3r3190. ! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e.parentNode.insertBefore (r, e)}; "[object Opera]" == e .opera? a.addEventListener? a.addEventListener ("DOMContentLoaded", d ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r3191. 3r3197. 3r3193. 3r3197. 3r3197. 3r3197. 3r3197.
+ 0 -

Add comment