Skip to content

ZeinabTaghavi/Handwriting_Manuscript_Line_and_Segment_Setection_Then_Storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

handwriting-Manuscript-_line_and_segment_detection_and_storage

this project has 2 main parts: 1- line detection, 2- segment detection in manuscript

why should we do it?(Despite the presence of hOCR)

in Persian and Arabic texts hocr is not strong enough to detect lines and words(especially when vowels are written like مَخصوصاً) this is hocr result line detection:

this is our code result line detection:

this is hocr result segment detection:

this is our code result segment detection:

describing code:

source image:

1- line detection:

by using x projection and then y projection we can find lines, in image what does it mean? read below:

# 2 - find the high compression vertical area

  vertical_hist = [sum(gray_env[i,:]) for i in range(img.shape[0])]
  

this is result of vertical_hist:

  vertical_temp = gray_corrected_rotation.copy()
  vertical_limit = gray_env.shape[1] * 255 * vertical_percent *.01
  for i in range(len(vertical_hist)):
      if vertical_hist[i] > vertical_limit:
          vertical_temp[i,:] = 255
      else:
          vertical_temp[i,:] = 0
          

this is result of mapping high density parts to be main lines:

it would give us a multimodal histogram, gets us height of lines.

then in each line, with same way we can find correct location of lines.

for y1,y2 in vertical_lines_positions:
      temp_img_env = gray_corrected_rotation_env[y1:y2,:]
      horizontal_limit = (y2-y1) * 255 * horizontal_percent * .01
      for j in range(temp_img_env.shape[1]):
          if sum(temp_img_env[:,j]) > horizontal_limit:
              line_location_image[y1:y2, j] = 0

then draw rectangle to bound them, and this is result:

adn one of the stored lines:

and then, we will store them in folder.

2- segment detection

at first, detect contours, in this time, may detect many noises, so whot to removethem? this is the histogram based on contours contourAre(lowest part is min contourAre and highest is biggest contourAre, in 10 bins):

the first bin has highest count of contoursArea, they are noises or dots, and must be ignored, then to cover all parts of segments(dots(like ب چ ج), vowels(like سَلام or بعضاً), and some seprate parts of one segments(like ک or گ )) detect first and last of width(w1, w1) then cover all heigh of line (h1 = 0 , h1 = height of line) then result is this image

and store them in a seprate file, some of example segments are: