编程知识 cdmana.com

[engineering application 3] three different background bleaching / purification / removal algorithms for text images.

      Text image also takes up a large proportion in the application of image processing , Especially with the increasing emphasis on Basic Education , Some supplementary education for students 、 The demand for intelligent homework marking is growing rapidly . At present, there are many professional software in this aspect . Among the algorithms in this area , An important process is to purify the background of text image , It's also called bleaching or background removal , Because the background is complicated , For subsequent binarization 、 Identification and so on will bring adverse effects .

   In this paper, combined with engineering practice , Three different background bleaching algorithms are proposed , Share with you .

    One 、PhotoCopy Algorithm

   This is a Photoshop An embedded algorithm in the software , The Chinese name is photocopy ,PS Its professional explanation in the help document of is :

  “ photocopy ” Filters simulate the effect of photocopying images . The darkening of larger areas results in copying only around their edges , And the halftone will deviate from pure black or white . You can set the level of detail and darkness .

   After watching , I don't know .

   After testing , stay PS The result of shadow printing algorithm is related to the setting of background color and foreground color , In the application of text image , The foreground color is set to black ( The color of the font ), The background color is white ( Color of paper ), At this point, you can get a basic bleaching effect , As shown below :

  

                    Original picture                                                                                         Photocopying effect ( Detail parameters 10, The darkness parameter 10)

   You can see , There is a lot of noise in the background of the bleached image , This can perform some simple denoising operations before photocopying , such as DCT To do , Or some other edge preserving denoising algorithms ( The text is generally more marginal than the background ).

   The following is the image after partial Laplacian drying, which has been photocopied with the same parameters .

   

               After denoising                                      Copy again

   obvious , After this treatment, the black noise is much less , The whole looks more perfect .

   On the realization of photocopying algorithm , Gauss is the basis of fuzziness , By comparing the difference between the Gaussian blur and the original image , Zoom in a certain number of times , And then use the result as a weight , Fusion between the background and the foreground . It's an easy algorithm to implement and optimize .

   In the text area , The difference between the fuzzy value and the original image is obvious , After zooming in , The weight is bigger , This time it's the foreground color , In other areas , The difference is small , Small weight , The result is close to the background color .

   Two 、 A background removal algorithm shared on the Internet

   The details can be found in https://www.cnblogs.com/jsxyhelu Find in this great Xia's blog . This algorithm is also based on Gaussian blur , A simple code is as follows :

for (int Y = 0; Y < Height * Width; Y++)
{
   if (Blur[Y] != 0)    
  {
    Dest[Y] = IM_ClampToByte(Src[Y] * 255 / Blur[Y]);
  } }

   there Blur It's usually the result of Gaussian blur .

   This is a very simple code , It can also be implemented very efficiently , It usually needs a big blur , such as 100 about .

    

  

                 Original picture                                    The effect of the treatment

   The key to the success of this algorithm in such images is : The black part of the text in the original picture , The overall occupancy is relatively small , When the large radius is blurred , The blur value is close to the color of paper and so on , It's closer to white , So the results basically didn't change , And the color of the paper in those places , Because the fuzzy values are almost the same as their original values , therefore Src/Blur Basically close to 1, Times 255, So it turns white .

   It can be seen that , This algorithm is actually the same as PhotoCopy It's similar , It's the difference between the blur and the original , It's just a subtraction , One uses Division .

   But this algorithm has one advantage , He can keep some color information of the original text image very well , There will be no unnatural phenomena . However, if the direct result of this algorithm is still a little low contrast , In the later stage, it will be very good to increase the contrast at an appropriate point .

   For example, below , That is, the contrast increases after processing 30 The effect of , And the red text and the blue LOGO Well preserved .

      

   3、 ... and 、 An improved algorithm based on local variance and mean

   We know , In the local binary algorithm ,Sauvola Binarization has always been a benchmark algorithm , He compared opencv The self-adaptive binarization has a more stable and reliable effect , And he also has fast O(1) Algorithm . The basic principle and calculation formula are as follows :

   A point (x,y) The expression of mean and variance at is :

            

   Then the threshold of binarization of the point is :

          

   among k Is the correction factor , Effective range [0,1], R It can be fixed 128.

   If you write this directly , became 2 It's worth it , But now there are many libraries that don't need binary results , What he needs is a relatively pure picture , In fact, it contains a lot of edge information .

   We used a method , First of all, the threshold determination processing method is to take those pixels whose values are greater than the average value and the variance of the average value plus the average value , That is to say T, And then provide an adjustable parameter D, When the pixel value is greater than T-D, The result is white , If it is less than T-D, It can't be set to black directly , We calculate a certain... Based on the content of the image BaseValue, When the pixel value is less than T-D-BaseValue, It's black , If it's between them , Then we do a linear quantization , Quantify by size to 0 and 255 Between , So that the color has a linear change , It won't have a particularly abrupt effect .

   If each pixel is processed in the above way , The processing speed will be very slow , Because this process doesn't want to be ordinary Sauvola You can get rid of dependencies , therefore , One way to speed up is to use something like CLAHE Algorithm is the same , Block the image directly , Calculate the parameters of a block separately after blocking , Then bilinear interpolation can be used to calculate the relevant parameters of other positions in the block . Of course, another way is to use these block points to use more complex interpolation or fit a surface , Then get the parameters , The calculation time for doing so will be slightly more complicated , But for some edges, your transition should be a little better .

   Usually , The effect of block size on the results is not obvious , But there are differences , It is recommended that the block size be taken as 16 and 32 Between .

   We tested some pictures , I feel that the effect of this algorithm is very good ,

     

  

   Testing a picture with serious photocopies can also get good results by adjusting the parameters :

 

   These three algorithms have their own merits ,PhotoCopy It's very fault tolerant , But there seems to be a lot of noise ( however PhotoCopy There are many other special functions ),jsxyhelu It's also very good , Fast , The effect is not bad , It's also a perfect guarantee that the color doesn't lose . Variance based has a more significant effect on the overall contrast , And it also has a good filtering effect on local shadows .

   In my SSE Demo The above three algorithms are also integrated in , They are located in Styleize --> PhotoCopy、Detection->Auxliary->RemoveBackGround as well as Detection->Auxliary->PureGround Under menu . PureGround There are other options , As shown in the figure below :   

                 

   Download here Demo: https://files.cnblogs.com/files/Imageshop/SSE_Optimization_Demo.rar

   Some people in China have developed some professional software for this demand , If there is such a need, I recommend this person's blog :https://www.cnblogs.com/Charltsing/p/PictureCleaner.html, It can be used directly for free , And support batch processing and other more practical functions , As shown in the figure below :  

        

        If you want to keep an eye on my latest articles , You can also pay attention to the official account. (Imageshop):

                             

版权声明
本文为[Imageshop]所创,转载请带上原文链接,感谢
https://cdmana.com/2021/04/20210408114459364r.html

Scroll to Top