Monday, April 4, 2011

Horizontal histogram profiles of consonants with descending vowel signs

 #!/usr/bin/python  
#-*- coding:utf8 -*-
import Image,ImageDraw
import sys, os
def horizontalHistogram (input_image, image_name):
width = input_image.size[0]
height = input_image.size[1]
print "Width = %d and height = %d" %(width,height)
histoGram = []
for i in range (height):
blackPixelCount = 0
for j in range (width):
pixel = input_image.getpixel ((j, i))
if (pixel == 0):
blackPixelCount += 1
histoGram.append (blackPixelCount)
print histoGram
histogramImage = Image.new("L",(width,height),255)
pen = ImageDraw.Draw(histogramImage)
y = 0
for count in histoGram:
pen.line((0, y) + (count, y), fill=128)
y += 1
cumulativeImage = Image.new("L",(width * 2, height),255)
cumulativeImage.paste (input_image, (0, 0, width, height))
cumulativeImage.paste (histogramImage, (width, 0, width*2, height))
cumulativeImage.save(image_name+"_"+".png","PNG")
def verticalHistogram ():
pass
path = "/home/debayan/code/lower_descender_images/"
dirName = os.listdir (path)
for image_name in dirName:
input_image = Image.open(path + image_name)
horizontalHistogram (input_image, image_name)



The piece of code above takes a set of images (consonant + vowel) in the folder /home/debayan/code/lower_descender_images/ generated by http://code.google.com/p/tesseractindic/source/browse/trunk/tesseract_trainer/generate.py and generates tiny images with horizontal histogram profiles. The generated set can be found at https://picasaweb.google.com/debayanin/OCRStuff .
Observing the set thus generated can give us insights as to where the descender vowel sign begins. If we know this, we can separate the consonant and vowel sign. One general observation in this case is that the point where the vowel sign begins causes a local minima in the histogram profile.

Here are some examples. Note the red horizontal lines which mark the minima in the histogram:


Tthri in Bengali

Mu in Bengali

These are the exceptions:



Chhu in Bengali

Du in Bengali

With some fonts the above glyph might now show a local minima in the histogram

Jri in Bengali

Hri in Bengali


Hu in Bengali


Gu in Bengali



3 comments:

  1. Debayan,

    I wonder whether using the entire line would be better than segmenting out the individual characters and then trying to identify the vowel signs at the bottom. Not sure about Bengali, but in Devanagari, I would expect that each basic character is approx the same height and all the downward signs would start at approx the same y-index. So if we were to look at the local minima of the horizontal projection of an entire line of characters, it may be easier to find the vowel signs.

    I am just getting started setting up tesseract, etc, and will try to collect some data soon. I guess the code you have above could be easily modified to try out some test cases?

    Avinash

    ReplyDelete
  2. Nice work.
    I hope you get it to work soon.
    I am a non-programmer but occasionally I get ideas.
    If anything comes to mind I will let you know.

    ReplyDelete
  3. This is a dead link..
    https://picasaweb.google.com/debayanin/OCRStuff

    ReplyDelete