Image optimization before tesseract

1,032 views
Skip to first unread message

ttutuncu

unread,
Apr 16, 2008, 3:45:56 AM4/16/08
to tesseract-ocr
Hi,

Can anybody recommend an optimization technique of a tiff file before
we pass it onto tess.

I am writing my code in JAVA. I'm currently using Java Advanced
Imaging (JAI) Library. I have done thresholding and sharpening for an
image.

But what I really want is to do a dynamic threshold operation meaning
different thresholding for each image.

What I am using right now is:

// Generate a histogram.
Histogram histogram =
(Histogram)JAI.create("histogram",
pi).getProperty("histogram");

// Get a threshold equal to the median.
double[] threshold = histogram.getPTileThreshold(0.2);

// Binarize the image.
PlanarImage dst = JAI.create("binarize", pi, new
Double(threshold[0]));
PI = dst;

As you can see this does a threshold of 0.2.
When I do this some text in images get really dark and some really
light.

Is there a way of doing an adaptive threshold using JAI or any other
method?

Thanks!

Hussein

unread,
Apr 16, 2008, 11:58:41 AM4/16/08
to tesser...@googlegroups.com
The median is not a good adaptive global threshold.  You need to find the valley between the potential two humps of the histrogram that represent the foreground and background assuming the background is kind of uniform and not a watershed.  In watershed areas, you need tile or stripe thresholding where the page is divided into tiles or stripes.  Or use regional segmentation.
 
Now, finding the humps is work and I do not know if Java library has it.  I do mine in C++ and every person writes his/her own binarization.
 
There is no good thresholding technique for all applications; you can tune your routine from application to another and from one kind of imaging to another.  The more robust the thresholding technique, the better your algorithm is.
 
Hussein Al-Hussein






> Date: Wed, 16 Apr 2008 00:45:56 -0700
> Subject: Image optimization before tesseract
> From: tarikt...@gmail.com
> To: tesser...@googlegroups.com

Scan...@gmail.com

unread,
Apr 16, 2008, 5:11:23 PM4/16/08
to tesseract-ocr
Good answers.

On Apr 16, 11:58 am, Hussein <al_om...@hotmail.com> wrote:
> The median is not a good adaptive global threshold.  You need to find the valley between the potential two humps of the histrogram that represent the foreground and background assuming the background is kind of uniform and not a watershed.  In watershed areas, you need tile or stripe thresholding where the page is divided into tiles or stripes.  Or use regional segmentation.
>
> Now, finding the humps is work and I do not know if Java library has it.  I do mine in C++ and every person writes his/her own binarization.
>
> There is no good thresholding technique for all applications; you can tune your routine from application to another and from one kind of imaging to another.  The more robust the thresholding technique, the better your algorithm is.
>
> Hussein Al-Hussein
>
> > Date: Wed, 16 Apr 2008 00:45:56 -0700> Subject: Image optimization before tesseract> From: tariktutu...@gmail.com> To: tesser...@googlegroups.com> > > Hi,> > Can anybody recommend an optimization technique of a tiff file before> we pass it onto tess.> > I am writing my code in JAVA. I'm currently using Java Advanced> Imaging (JAI) Library. I have done thresholding and sharpening for an> image.> > But what I really want is to do a dynamic threshold operation meaning> different thresholding for each image.> > What I am using right now is:> > // Generate a histogram.> Histogram histogram => (Histogram)JAI.create("histogram",> pi).getProperty("histogram");> > // Get a threshold equal to the median.> double[] threshold = histogram.getPTileThreshold(0.2);> > // Binarize the image.> PlanarImage dst = JAI.create("binarize", pi, new> Double(threshold[0]));> PI = dst;> > As you can see this does a threshold of 0.2.> When I do this some text in images get really dark and some really> light.> > Is there a way of doing an adaptive threshold using JAI or any other> method?> > Thanks!> >

ttutuncu

unread,
Apr 18, 2008, 9:55:50 AM4/18/08
to tesseract-ocr
Hi Hussein,

Thanks for your informative reply.

What I am OCRing are identity cards which are scanned at 200dpi.
What I want to receive with OCR is only the identity number which is
at a specific loacation on the scanned image.

But the problem is that I couldn't find the right thresholding for a
batch of identity cards. They all seem to come out different after the
threshold process.

What I need is an adaptive algorithm. I couldn't find anything on the
net.

What exactly does tile and stripe thresholding do?

Does anybody have a good adaptive thresholding algorithm for Java?

Thank You..


On 16 Nisan, 18:58, Hussein <al_om...@hotmail.com> wrote:
> The median is not a good adaptive global threshold.  You need to find the valley between the potential two humps of the histrogram that represent the foreground and background assuming the background is kind of uniform and not a watershed.  In watershed areas, you need tile or stripe thresholding where the page is divided into tiles or stripes.  Or use regional segmentation.
>
> Now, finding the humps is work and I do not know if Java library has it.  I do mine in C++ and every person writes his/her own binarization.
>
> There is no good thresholding technique for all applications; you can tune your routine from application to another and from one kind of imaging to another.  The more robust the thresholding technique, the better your algorithm is.
>
> Hussein Al-Hussein
>
>
>
> > Date: Wed, 16 Apr 2008 00:45:56 -0700> Subject: Image optimization before tesseract> From: tariktutu...@gmail.com> To: tesser...@googlegroups.com> > > Hi,> > Can anybody recommend an optimization technique of a tiff file before> we pass it onto tess.> > I am writing my code in JAVA. I'm currently using Java Advanced> Imaging (JAI) Library. I have done thresholding and sharpening for an> image.> > But what I really want is to do a dynamic threshold operation meaning> different thresholding for each image.> > What I am using right now is:> > // Generate a histogram.> Histogram histogram => (Histogram)JAI.create("histogram",> pi).getProperty("histogram");> > // Get a threshold equal to the median.> double[] threshold = histogram.getPTileThreshold(0.2);> > // Binarize the image.> PlanarImage dst = JAI.create("binarize", pi, new> Double(threshold[0]));> PI = dst;> > As you can see this does a threshold of 0.2.> When I do this some text in images get really dark and some really> light.> > Is there a way of doing an adaptive threshold using JAI or any other> method?> > Thanks!> >- Alıntıyı gizle -
>
> - Alıntıyı göster -

Hussein

unread,
Apr 18, 2008, 1:30:04 PM4/18/08
to tesser...@googlegroups.com
Tarek,

Send me some images to my email to see if they work with tile or stripe or even a good global adaptive thresholding that I developed
 
I will let you know if they work.
 
Hussein






> Date: Fri, 18 Apr 2008 06:55:50 -0700
> Subject: Re: Image optimization before tesseract
> From: tarikt...@gmail.com
> To: tesser...@googlegroups.com

Graham Chiu

unread,
Apr 18, 2008, 4:50:20 PM4/18/08
to tesser...@googlegroups.com
ttutuncu

Are you OCR'ing the whole card or just the region where the id is?

On Sat, Apr 19, 2008 at 1:55 AM, ttutuncu <tarikt...@gmail.com> wrote:
>
> Hi Hussein,
>
> Thanks for your informative reply.
>
> What I am OCRing are identity cards which are scanned at 200dpi.
> What I want to receive with OCR is only the identity number which is
> at a specific loacation on the scanned image.
>
> But the problem is that I couldn't find the right thresholding for a
> batch of identity cards. They all seem to come out different after the
> threshold process.
>

--
Graham Chiu
http://www.synapsedirect.com
Synapse - the use from anywhere EMR.

Hussein

unread,
Apr 18, 2008, 5:14:24 PM4/18/08
to tesser...@googlegroups.com
Hi Tarik,
 
Tile thresholding means you divide the page into rectangles or squares like tile or like a chessboard.   Then the background of each tile will most likely be uniform, in which case, it will possible to find an adaptive threshold between the foreground and background humps.  This is needed if the background changes in more than just the vertical or horizontal direction.
 
Stripe thresholding is when the background changes either horizontally or vertically as you go down or right; hence you divide the page into horizontal or vertical stripes where each stripe will have almost a uniform background.
 
Of course, the challenge here is how to automatically and dynamically detect the size of the tile or the stripe, and how not to go too big or too small so as no to cause damage.
 
Adaptive thresholding is one of the most difficult things in imaging and that is why I am able to make money via telecommuting :)
 
I asked for images from you to tell you what kind of solution you need for your images.  It may be simple and may be global thresholding would do it with no need for tile or stripes or other methods.
 
In some cases of watershed and different background levels and colors, none of the above will work, and you will need to other forms of segmentation to get all the text on the page.  You may need regional segmentation or other methods.
 
As for you, if you can detect the area where the number is on the card, you need not process the whole image and just focus on the ROI (region of interest) and you speed and accuracy will be boosted.

 
Hussein


> Date: Fri, 18 Apr 2008 06:55:50 -0700

> Subject: Re: Image optimization before tesseract
> From: tarikt...@gmail.com
> To: tesser...@googlegroups.com

Keith Beaumont

unread,
Apr 19, 2008, 9:25:49 AM4/19/08
to tesser...@googlegroups.com
Hussein,
Could you post your code here? I'd like to have a look.
KB

 

Hussein

unread,
Apr 19, 2008, 11:27:40 AM4/19/08
to tesser...@googlegroups.com
Actually, I never used any of the tesseract open source code for my imaging work.  I developed my own code for everything.  I joined this group for fun and learning new ideas and I am new here; only three months.  Much of my work has been proprietary and I cannot post it. 
 
I told Ray that if I develop anything for tesseract, I will make sure to post it.   I have been busy but if I get time I can add some of the components he suggested once for people to build.
 
Regards,
Hussein


Date: Sat, 19 Apr 2008 14:25:49 +0100
From: beaum...@gmail.com
To: tesser...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages