A tip for those of you new to using Leptonica to do image processing

334 views
Skip to first unread message

TP

unread,
Feb 20, 2012, 9:20:03 PM2/20/12
to tesser...@googlegroups.com
It been around since last summer, but you may be unaware of my
"Unofficial Leptonica v1.68 Documentation" website
(http://tpgit.github.com/UnOfficialLeptDocs/index.html). See that page
for its list of improvement over the Official Leptonica website.

In a previous post to this group
(http://groups.google.com/group/tesseract-ocr/msg/2bd90cdcb88f1cf3),
Will Hadden casually mentioned that he found the
pixBackgroundNormSimple() function surprisingly useful. Let me use
that function as an example of a feature you may not be aware of:

1) Open up the "Leptonica API" page
(http://tpgit.github.com/UnOfficialLeptDocs/leptonica/functions.html).

(At this point you could pick "Image Quantization/Depth Conversion"
from the table's Category dropdown menu to see all 145 function that
are very roughly related to this topic)

2) Enter in "norm" without the quotes in the Function textbox.

The table's 3rd row now says: "19 of 2046 rows match filter(s)", and
the table lists only liblept functions that contain "norm" in their name.

(other useful strings to look for are: thresh, morph, scale, gamma,
contrast, etc)

3) Scroll down a bit and click on the pixBackgroundNormSimple function
(it's a link, as is adaptmap.c, the file it's defined in).

4) You now find yourself at my Doxygen generated, hyperlinked version of
the Leptonica Source files, at the entry for
pixBackgroundNormSimple().

The main nice thing this does is show you what other functions are
called by pixBackgroundNormSimple(), so you can get a quick idea of
how it must work. In this case it only calls pixBackgroundNorm().

And, it also shows you who calls pixBackgroundNormSimple(), in this
case only main() from prog/dewarp_reg.c. Clicking on that link would
give you an example of how to call pixBackgroundNormSimple().

5) The Leptonica source files weren't written with Doxygen
commenting in mind so things like argument lists to functions look
better in the actual source. Therefore, find the line that says:

Definition at line 166 of file adaptmap.c.

And click on 166, to bring up the source for the function.

6) Scroll up a bit and you see Dan's typically pretty good documentation
for the pixBackgroundNormSimple() function.

We also see that it indeed just calls pixBackgroundNorm(). Don't do
this but notice you could click on that function to jump to *its*
documentation.

7) Scroll up to the very top of adaptmap.c.

The top of almost every file in Leptonica's src directory has a nice
overview of the techniques implemented in it. This makes it
relatively easy to decide which functions you might look further at.

Finally, once you find a function that looks interesting, use your
favorite file searching utility to search all the *.c files in the
Leptonica source directories. Most functions will be used somewhere in
the prog directory, and those files will have good examples of how to
use the function. Better yet, they sometimes give you insights into
other ways to accomplish the same thing and how those alternatives
compare with each other.

Additionally, you can do similar things for entire files at:

a) /src Directory Contents (API Implementation)
[http://tpgit.github.com/UnOfficialLeptDocs/leptonica/src-dir.html]
and

b) /prog Directory Contents (Examples)
[http://tpgit.github.com/UnOfficialLeptDocs/leptonica/prog-dir.html]

For example, there are six files in the prog examples directory that
have "norm" in their description.

Wil Hadden

unread,
Feb 21, 2012, 4:53:09 AM2/21/12
to tesseract-ocr
Superb work, I had recently found this myself though google and as I
had jumped in to specific pages I had thought I was looking at
official documentation!

Wil
Reply all
Reply to author
Forward
0 new messages