Showing posts with label Whitewashing algorithm. Show all posts
Showing posts with label Whitewashing algorithm. Show all posts

Thursday, September 19, 2013

Final report : Part 3

The filters I tested out generated some results that help in preparing a document for OCR.
In a tabular format, the results look like :





Median FilterGaussian FiltersGreyscale ConversionBilateral FiltersAdaptive ThresholdingResolution
Changes
WhiteWashing
Algo

Color ImagesGRGGGN,AWorks as intended
NewsPaperRGGGR, SN,AWorks as intended
BooksRGGGR, SN,AWorks as intended
PostersGN, AGGG, SN,AWorks as intended


Legend :
R : Recommended
G : Good Results, Useful to have
N : Neutral
A : Adverse Effects
S : improved results with Whitewashing

Explanations :

All tests were performed on random image samples found via a basic image search on Google.
NOTE : Tests mentioned in Column N should be performed before tests in column N+1. 

Median Filters:
These are useful for Color Images, and seem to improve the output in general for all documents.
In case of samples from newspapers and books, they helped greatly in removing noise.

Gaussian Smoothing:
It helped in smoothing the images before greyscale conversion, but in case of Posters, the smoothing often distorted the text as well.

Greyscale Conversion :
It is always better to do a greyscale conversion as there is no downside to it.
Often, using a filter to "skeletonize" the input resulted in improved output. But this was also affected by the resolution, and it is suggested not to use skeletonize for input with very low resolution.

Bilateral Filters and Adaptive Thresholding :
These tests were started before the mid-term, and are explained in details here and here, respectively.
However, I continued checking the combinations, and they were found to be mostly useful.

I will write one last post about me, myself, life, the universe and everything that happened this summer. So Long.


Tuesday, September 17, 2013

Final Report : Part 2

At the beginning of the project, I spent some time finalising the tools I would be using.
Having done so, I started with the pre-processor, and finally, by the mid-term, a working prototype of the Whitewashing code was completed.

During this period, I also realised how difficult it was to generate good data for training/testing purposes. They were awful in the begining, when I got the results for whole words instead of characters. But gradually the quality improved. During these trials, I tried out various methods for generating the data and eventually the box files, some of them are :

  1.  Ari's trainer  helped a lot in learning about the training procedure
  2.  OCR chopper was easy to use to make box files, but not always accurate. It needed lots of manual editing.
  3. BoxMaker was similar to OCR chopper, but more flexible in terms of size
  4.  I also tried with some data from Parichit 
  5.  Open source icr , a project related to Ari's project mentioned above, was somewhat helpful.
  6. Some amazing work at Silpa inspired and motivated me, but i ended up not using them because I felt they were not very easy to incorporate in the project.
  7. Debayan's Tesseract Indic project has been a great help and provided me with much required guidance to get started.
After having tried all the methods, I took the decision to use Cairo-Pango in combination, and though had some problem initially, finally it worked out.

Further reading made it clear that I should always jumble up and mix the characters in a training set. I took it one step further, and decided to mix up even the sizes of the different images. And for that, I wrote another script. This helps in better training.
For the final leg of this, I was trying to make a  python script, but it was not working. In the end, I switched to using ImageMagick as it does the trick with a single command. There was no point in making things more complicated than necessary.

Along with this, I continued my work on testing various filters on different types of documents. I will publish it in the next post.

Monday, September 16, 2013

Final Report : Part 1

Finally, The Summer has come to an end, and it's time to look back on the journey.
It turned out to be very different from what I had thought at the beginning. To sum up, my work towards GSoC 2013 can be categorised in two parts : the whitewashing algorithm, and the data generation method.

My First plan was to have a pre-processor and a post-processor, which would combine and work around the OCR to improve the quality of the final result. But after learning about the InfoRescue project, the plan for the post-processor changed, and in the final implementation, I have the pre-processor, and a system for generating data easily.
For the result, my initial plan was to chart out the performance of the individual systems, but instead, I ended up doing a table that helps in the pre-processing of the documents.
Here, I will  sum up my Aimed vs Achieved Goals in brief, and then in the following post(s), I will explain in detail the arguments and train of thoughts/events that lead to the changes in the plan.

Set Goals :
  1. Pre-processor : shirorekha chopper
  2. Post-processor : CBR-based
  3. Output matrix : performance based comparison
Achieved Goals :
  1. Pre-processor : Whitewashing code , a modified shirorekha chopper that paints over the shirorekha instead of chopping only at the gaps.
  2. Data generation : It helps in generating data that may be used for testing, as well as used to make the box-files to train the system.
  3. Output table : Several filters and their effect on different type of documents was tested, in hope of providing a  guideline to better pre-process any document that needs to be OCR'ed.
Key extra takeaways :
  • Learnt a lot about OCR software, specifically about Tesseract.
  • Learnt about Pango-Cairo. 
  • Used IPython and Notebooks with EPD. I am definitely going to use them a lot now.
  • Practised modular development as a single developer on this big a project for the first time.
In the next few posts, I will explain my reasoning for the changes I made to the plan along the way.
So Long.

Sunday, September 15, 2013

code clean up

It was bugging me to put up the whole code in a single file, specially after having used a very nice, modular  structure in the notebooks.  So I spent the day scrubbing, and finally I have split them up in manageable parts, and pushed everything to the repository.
Also included with the code is instructions on how to use them, and my personal views and suggestion at some points, in the form of README files.
In the future, I would like to continue and maybe develop a GUI to make it easier to use.  
However, it's time to stop coding, and start documenting whatever is left. 

Tuesday, July 23, 2013

Mid -Term Summary : Part 4 - Results so far

This post is going to be all about the various results I have had so far, which will include both  the good ones (obviously) and the bad ones, that compelled me to update my plans somehow.

1.Tesseract
To start with, I am happy with the decision to use Tesseract 3.02. It's effective,not difficult to setup or use on any platform, and the training procedure, though long and tedious, is not very complex once you get the hang of it.

2. Environment
Next, my decision to use EPD and IPython has also been helpful. Infact, I love Python more than ever now, and think that using the Notebook is a really god option when you are concerned with heavily documenting your work.

3. Test Results
Resolution : Contradictory to my initial hypotheses, tests suggest these do not seem to affect the outcome much. However, more extensive testing needs to be done. Also, this inspired me to focus harder on the image filters.

Image Filters : So far, Bilateral filters, and adaptive thresholding seem to be the most effective on all kinds of documents. For the final matrix, document-specific effect of the filters need to be sorted out.

WhiteWashing Algorithm : The tests show that the code works as intended. 

Box-Files and traineddata : Initial box files I generated were devastating, but with the work-around on using Fedora, they have improved. The traineddata I generated is not an improvement over the stock. I will continue to work on them.


Monday, July 22, 2013

Mid -Term Summary : Part 3 - working on the BookWorm

My working Methods.

This post probably needs a bit more structure, and hence,  I will use some formatting styles Blogger provides.
The work I have done, and how I have done it, during the previous weeks  can be summarised in the following steps : 

Objective A. Get practical with Tesseract

I started the project by getting a first-hand feel of Tesseract. From all the reading I had done by this point, I was familiar with the working theory, but actually trying out the software provided with me a better insight into the current scenario.
Another valuable lesson learnt through this was that all the reading and previous work was based on earlier versions of Tesseract, but Tesseract 3.02 has a major upgrade in terms of BookWorm, it already has some base support for Indic languages, and the training method has also changed a bit from the previous versions (Tesseract 2.x).
I updated my plan several times along the course, and finally arrived at this conclusion to form the matrix mentioned in my previous post. I also finalised the my version of shirorekha chopping algorithm, the WhiteWashing Algorithm.
Also, discussions with +Abhishek Gupta  made it clear that our projects are closely related, and his project is like a post-processor for OCR while mine is a pre-processor.

 Objective B. Decide on Imaging Libraries

After familiarising myself practically with Tesseract, I started trying different libraries in Python, and finally decided that I will be using PIL and Scikit-Image. Some entries about the same can be found here.

Objective C. WhiteWashing Algorithm

Now, having made sure that the chosen libraries were suitable and sufficient for my purpose, I moved on, and started working on the WhiteWashing  Algorithm.
Now that the coding for whitewashing an image is complete, after the midterm, I will turn my focus back to the filters, and start with forming the matrix.

Mid-Term Summary : Part 2 - Shaping BookWorm

Approach :
I decided to tackle the problem of shirorekha in connected scripts for the first half of the summer, and the result is the WhiteWashing Algorithm. This detects the shirorekha in a script, and removes it, making it easier to separate the "akkhars" (alhabets) in a "shabda" (word).
Next, I am working on developing a matrix to help us determine the best suited filtering method for making a document OCR-ready. It will have specific instructions for a document based on it's type. An early example of the same is here.

Tools Used :

  • Language : Python  2.7
  • Development Environment : 
    • most of the work is done on EPD 1.0.1 on Windows 7 (32-bit), using IPython notebooks.
      • However, I had to Switch to Linux ( Fedora 14 on VMware workstation 9.0 ) for a while as I was unable to make  pango work on my windows.
    • Notepad++ 6.3.2
  • Software : 
    • Tesseract 3.02 on command line (NOTE : 3.0 is available on Fedora 14, but it did not effect as I Switched to windows for the part to use Tesseract) .
    • Python Libraries :
  • Repository : GitHub

Thursday, July 18, 2013

some quick training

The last two days, I decided to go with my impulse and try generating some training data. Now I have a good grasp on the Tesseract commands for generating the required files, but still need deeper understanding about the clustering part. Amazingly, the long and tedious training procedure at the original documentation doesn't look so difficult after staring at it for almost 3 months.
However, after testing with the new data, no miracle happened, and while it managed to detect the language correctly, the accuracy wasn't worth mentioning.
Next step, I will generate some training data with the WhiteWashing algorithm and see how it fares.
But now, off to documentation.
So Long.

Monday, July 15, 2013

testing with close-typed document

As planned, I tested the algorithm with some image samples of bengali newspaper, found as a result of a simple Google Image search.
The original image i used had a lot of noise, here is a preview :

Here, we can see that it has a lot of salt-pepper style noise, ad the resolution is not particularly good.
However, trying to whitewash it as it is yielded poor results. 
It can be seen that due to the noise, the algorithm fails to detect the individual lines. S I appliead an adaptive thresholding filter on the image, and the denoised image looked like :
Applying whitewashing to this as input resulted as expected, 
This proves the generic working of the algorithm.
However, I still had to manually reset the padding values, which needs to be resolved.

As midterm approaches, i have a lot at hand and on my mind.
Here is my new plan, in brief, and in the order I plan to carry them out :
To Do : 
  1. Document Everything done so far. (2 notebooks - ImageTest with filters and WhiteWashing algorithm)
  2. Update and Publish the documents.
  3. Document effects of domain-dependency (like this post deals with close-typed documents) and useful filters.
  4. Document summarising what I learnt during this period, and what made me change my initial plan.
  5. Test with different resolutions. (After mid-term)
  6.  Merge the notebooks.
  7. Document. 
I think I will stop coding for a while and get started with the documentation now. I will have to discuss the same with my mentor.
So Long.


Sunday, July 14, 2013

WhiteWashing and box files

Finally, I have fixed the padding-values for the WhiteWash algorithm and it seems to be working nicely.
Here is a preview of the current output :
However, the padding uses integer numbers right now. It will be better if I could somehow relate this to the document statistics. It should be interesting to try out later.
This success with the algorithm allows me to focus on the box file generation again. Currently, I have managed to generate this using my workaround in the virtual machine, and after tweaking Debayan and Sayamindu's original algorithm using pango.
The box file generated now looks like :

Which is improvement over the last time. 
Now, I have to combine these two methods to try out my plan. 
Next, I will make an entry sometime this week about my updated plans and goals for the midterm evaluation period.
So Long.

Thursday, July 11, 2013

WhiteWashing Algo - Working

It took a bit longer than expected, but I have finally fixed the script to detect the shirorekha and whitewash over them.
I will write more about what I was doing wrong and how I fixed it later.
Sample Input :
 Sample Output : (NOTE : The black highlights show the marked coordinates)
Actual whitewashed Output :
On a Closer looks, we can see :
Here, we can see that the white-lines are too thin. Hence, next step to do for me is to find some appropriate values of padding around the coordinates when doing the whitewash.

So Long.