FEATURE BASED INDEXING OF HAND-WRITTEN TEXT IMAGES NAGARAJAH KUNTHARSHAN This dissertation was submitted to the Department of Computer Science and Engineering of the University of Moratuwa in partial fulfillment of the requirement for the Degree of M Sc in Computer Science Department of Computer Science and Engineering University ofMoratuwa Sri Lanka March 2010 96425 Abstract Identity management system which is maintaining a manual database system to store its data is facing a big challenge of searching a particular entry from the database if a query rose where the date of birth of the person is not known. Person Identification department, as an example, the existing database is in the form of Pre-designed hand written physical cards with the details. The cards are served separated by sex and ordered by date of birth. In case of a person whose date of birth is not known, there is a challenge of going through the cards one by one to spot the exact record. So, person registration department decided to computerize the database and found out the following. Since the hand writing is very poor there is no chance of using character recognition software. The better option could be manually enter the data into a database, but quotations submitted for the tender called for this task was much higher than the potential level of the department. Finally, feature extraction method is found out as an ideal solution for this task. ln this approach all the cards are scanned and saved in the system using batch scanning. Each file is pre-processed and the number of characters in the name is saved to the database as index for the corresponding scanned image. The search operation on the database based on the number of characters of the name will list down the name of the possible card and the corresponding card also will be fetched from the saved location and previewed. Among the cards that arc identified, user needs to find the cards manually. This will narrow down the search. System will fail in counting the number of characters in the name if there is no space left between two characters or if one character is split "into two by mistake. To handle these challenges, a new intelligent algorithm should be generated with the ability to understand the order or the pattern of occurrences of the characters and make the decision based on them Declaration I, Nagarajah Kunatharshan hereby declare that the work included in this dissertation in part or whole has not been submitted for any other academic qualification at any institution. N-J~ Mr. N. Kunatharshan ,5.._Lb~\~ ~..,..., e-?<().~"'-o....~lC:.>IJ --------~~~~- DR. Chathura De Silva (Supervisor) ... -"':' 2 Acknowledgements Having completed the MSc. Degree program at the Department of Computer Science and Engineering, University of Moratuwa, I would like to take this opportunity to thank those who helped me a lot in completing it at this level. First of all. I would like to thank my supervisor, Dr. Chathura De Silva for the supervision and guidance despite his busy schedules. Also I would like to thank Ms. Visaka Nanayakkara, Dr. Gihan Dias and Dr. Sanath Jayasena for conducting the subject Research Seminar, which helped me a lot when browsing through the published research papers. 1 should be grateful to all the members of the staff of the Department of Computer Science and Engineering for giving valuable feed back during the progress review sessions. Finally, I would like to thank my family for supporting me in every aspect m completing my degree program and the research successfully. Thank you all! Kunatharshan N ... (06/8279) -.,.. 4 ·- Table of Contents Declaration ... ... ....................................................... .......... ... .. .. .... .. ................................. 2 Abstract .......................................................................................................................... 3 Acknowledgements ........................................................................................................ 4 'fable of Contents ........................................................................................................... 5 List of Figures ................................................................................................................ 7 1. Introduction ..... ........................................................................................................... 8 2. Literature Review .................................................................................................... 11 2.1 Edges Detection: ................................................................................................ 11 2.2 Lines Detection - Hough Transform: ................................................................ 12 2.3 Image Registration with Template matching ............. .. .. .. ... .. ... ... ... .................... 13 2.4 Cross-correlation ................................................................................................ 14 2.5 Open and Close .................................................................................................. 14 2.6 Erosion ............................................................................................................... 15 2.7 Dilation ..................................................... :-, ....................................................... 15 2.8 Opening .............................................................................................................. 16 2.9 Closing .......................................... : .................................................................... 16 2.1 0 Color Scale Conversion - gray scale" ............................................................... 17 3. Materials and Methods ....................................................... .... . ::~ ............................ 18 3 .1 Adding images to the system ................................. ... ......................................... 19 3.1.1 Templateimage: ............................................... : ............ ... ........................... 19 3.1.2 Printed Character Removal: ........................................................................ 20 3.1.3 Removal of lines: ...................................................... .. .. ............................... 2 1 3.1.4 Closing: ....................................................................................................... 23 3 .1.5 Character counting: ..................................................................................... 24 3.2 Finding images ................................................................................................... 24 4. Observations ............................................................................................................ 25 5 5. Analysis and Discussion of Results ......................................................................... 26 5.1 Binary image conversion: .................................................................................. 26 5.2 Closing: .............................................................................................................. 27 5.3 Line removal: ..................................................................................................... 28 6. Conclusions and Recommendations for Future Research ....................................... 29 7. References ................................................................................................................ 30 8. Annexure .................................................................................................................. 32 ... ---:'1 6 List of Figures Figure 3.1 : Flowchart of the model .................................. ... .... .. ... .. ............................. 18 Figure 3.2: Scanned image (Eyes and ID Numbers are masked in order to keep the confidentiality) ..................................................................................................... 19 Figure 3.3: Template image ......................................................................................... 20 Figure 3.4: Cropped Image .......................................................................................... 21 Figure 3.5: Name surroundings after the removal of printed characters ..................... 21 Figure 3.6: Generated line image ................................................................................. 22 Figure 3.7: Scanned image after the line removal ....................................................... 23 Figure 3.8: Name surroundings after the removal of lines .......................................... 23 Figure 3.9: After the closing operation ........................................................................ 23 Figure 3 .1 0: After the noise removal.. ......................................................................... 24 Figure 4.1: Processed segment of hand written characters .......................................... 25 Figure 4.2: Processed segment of printed characters ................................................... 25 Figure 5.1: Result with binary image .......................................................................... 26 .... Figure 5.2: Result with gray image .............................................................................. 27 Figure 5.3 close with 'disk' (radius 2) morphological structuring element ................ 27 Figure 5.4: close with 'line' (length 10, angle 90 degrees) morphological structuring element ................................................................................................................. 27 ...,... Figure 5.5: close with 'line' (length 3, angle 90 degrees) morphological structuring element .. .............................................................................. ... ... ........................... 28 7 .lo...- 1. Introduction Many Identity management systems of Sri Lanka need a system to filter or find the details of distributed identification documents. Currently their system is not automated and the searching is done manually. The details arc maintained in papers which is a predesigned printed card filled in hand written Sinhala characters. Name, address, date of birth, place of birth, sex and the photographs are important contents of the cards. Even though the cards (template) are regularly printed if the hand writing is poor then there are possibilities v.hcre even human wouldn't be able to read and understand them properly. Now these filled cards are separated by sex and sorted in Date of Birth (DOB) order. When a person is reapplying for an Identity Card due to some reasons, if he/she knows the Date of Birth then it would be easy to find the corresponding card otherwise it will be a challenging task to locate the correct one. But not everyone remember their DOB correctly due to not having proper record in place or forgetting it as time goes. Other than the difficulties in finding cards on request, another main thread for the manual database is getting damaged and losing information due to the expiration of the card material. When paper cards arc lasting for more than eighty or ninety years it's getting damaged little by little and causing tnore problems in search process. There were so man) ideas suggested and tried to automate database in order to make the search process easy and keep the data safe. Optical Character Recognition (OCR) scan or using character recognition softWare cannot be used because of the poor quality and irregularity of the hand written characters. Exact wlution for this scenario ""' could be entering data manually to a new database. However, the cost factor is found as the limitation for this suggestion after the evaluation of the quotation submitted against the tender called by the Persons Registration Department for this data entry task. Therefore it is finally concluded to go for a solution to narrow down the search by using possible features which could be extracted from the scanned text images (predesigned printed hand filled cards). Number of characters in the name was identified as a suitable feature to be extracted from the scanned card to narrow down the search. There were no related ideas or implementations for this particular scenario 8 were found during this study; however so many research works found related to feature extraction. Hough transform is one of the well known techniques for any parametric shape detection. Image registration is the process of aligning two or more images of the same scene. Typically, one image, called the base image, is considered the reference Image registration is often used as a preliminary step in other image applications. But in this project the template (printed portion of the card) should be removed from the card in order to analyze the hand written part efficiently. Here, the image registration is implemented using cross correlation technique. A template was created and certain parts (printed characters near to the name area) are selected and registered one after the other on the original cards. And the lines also detected and removed from the cards. Then the hand written characters arc treated as objects and object count surrounding the name area is taken as number of characters in the name. Some times the gap between two characters isn't sufficient to separate them ... as two objects and some times two parts of one character is left more gaps to identify as two objects. 'Open· and 'Close' preprocessing techniques also used in order to minimize the error in object count. The software has two major sections; one is addition of features of image to the database and the other is finding the card back from the database by using stored features. Above mentioned image processing techniques are used in the addition process. User will be allowed to add the cards to the database one by one or multiple cards at once. System will automatically find the number of characters in the name and store in the database with the name of the image. Since the database contains very few attributes, the search will be very faster. When a person ask the system to search based on the given number of characters, system will perform the search within the database and list out the image's name, based on the image's name the correct card will be fetched from the local directory \\-here all the cards are saved. 9 Since MATLAB has very useful image processing toolbox it is selected as the programming language. In addition to this it has the ability to connect the database and create the user interface. Microsoft Access is used as the backend database to store the extracted features. .... -..,.. 10 2. Literature Review Throughout the study, there were no works related to this problem domain found; however, the work related to the feature extraction is very wide and there are many researches and works which used the similar technologies in this work and proved their validity are found. Man y well known techniques are implemented in many research works. Feature extraction techniques return information about the structure of an image. For example, this technology can be used to find edges, locations, and attributes of objects. Some of the image processing tasks are kno"vn as preprocessing tasks, which are usually performed prior to the main image processing actions in order to produce the good and correct results by enhancing the images by reducing the noises. Close, Open, Color scale conversion (ROB to Binary or Grayscale) is some of the well-known preprocessing methods. Gray Image Reconstruction by Waheeb Abu Ulbeh, Akram Moustafa, and Ziad A. Alqadi paper proposed a methodology of eliminating the noise from the gray image and reconstructing the image in order to get the image without losing any piece of information from it. Morphological Operations such as Erosion, Dilation, Opening, and Closing which are explained below are suggested as the suitable methodologies to pre process the image in order to achieve thC' high quality result of this operation. [Erosion. dilation and related operators,by Mariusz Jankowski] There are suggestions on the usefulness and the suitability of the morphological operations mentioned above and the suitable order of performing them. [Separating Low Pass and High Pass Frequencies in the Image without_josing Information by .,.. Mohammed Abu Zalata and Ziad Alqadi] , I Morphological Image Processing by Ranga Rodrigo], [Application of Mathematical morphology operations for simplification and improvement of correlation of images in close range- photogrammetry by M.Kowalczyk, P.Koza, P.Kupidura, J.Marciniak] 2.1 Edges Detection: The goal of edge detection is to mark the points in a digital image at which the luminous intensity changes sharply. Sharp changes in image properties usually reflect important events and changes in properties of the world. These include (i) Discontinuities in dept h, 11 (ii) Discontinuities in surface orientation (iii) Changes in material properties (iv)Variations in scene illumination .... r,.A" c Edge detection is a research field within image processing and computer \'isionP,mY ~ particular within the area of feature extraction. Edge detection of an image reduces significantly the amount of data and filters out information that may be found as less relevant, while preserving the important structural properties of an image. There are many methods for edge detection, but most of them can be grouped into two categories. They are search-based and zero- crossing based. The search-based methods detect edges by looking for maxima and minima in the first derivative of the image, usually local directional maxima of the gradient magnitude. The zero-crossing based methods search for zero-crossings in the second derivative of the image in order to find edges, usually the zero-crossings of the Laplacian or the zero-crossings of a non-linear differential expression. Noises in the Scanned images are very significant (unwanted data), thus brightness changing very sharply. This technique is identified to play a big role in marking them in order to be removed during the image processing. [ 16] .., Various detection technologies have been analyzed, discussed and compared with each other. The zero-crossing method has been found as the efficient one among all the traditional methods and also the accuracy of it proven. [Comparison for Edge Detection of Colony Images by Wang Luo] -"'I" 2.2 Lines Detection - Hough Transform: The Hough transform is a feature extraction technique used in digital image processing. The classical transform identifies lines in the image, but it has been extended to identifying positions of arbitrary shapes. The transform universally used today was invented by Richard Duda and Peter Hart in 1972, who called it a "generalized Hough transform" after the related 1962 patent of Paul Hough. The transform was popularized in the computer vision community by Dana H. Ballard through a 1981 journal article titled "Generalizing the Hough transform to detect arbitrary shapes". As the images contain many lines, in order to minimize the error in the result it is necessary to remove all the printed lines from the scanned tmages. 12 Lines Detection technique is found to be very useful in achieving this. Hough transform is used and proved to be a useful technique in the paper. Use of the Hough transformation to detect lines and curves in pictures by Richard 0. Duda Peter E. Hart. 2.3 Image Registration with Template matching Template matching is a technique in Digital image processing for finding small parts of an image which match a template image. It can be used in manufacturing as a part of quality control, a way to navigate a mobile robot, or as a way to detect edges in Images. There are different approaches to accomplishing template matching. Some are more preferment than others, and some find better matches. The basic method is to perform template matching while looping through all the pixels in the search image and compare them to the pattern. While this method is simple to implement and understand, it is one of the slowest methods. This method is normally implemented firstly by creating a sub image (the template), if the sub image is 'w(x, y)' where x and y represent the coordinates of each pixel. Then move the center of this sub image w over each (x, y) point in the candidate image, which is 'o(x, y)' and calculate the sum of produCts between the coefficients in o and the corresponding neighborhood pixels in the area spanned by the filter mask. This method is sometimes referred to as 'Linear Spatial Filtering'. This type of spatial filtering is normally used only in dedicated hardware solutions because of the computational complexity of the operation, however this complexity .._. can be Jessen by filtering it in the frequency domain of the image, referred to as 'frequency domain filtering,' this is done through the use of the correlation theorem. Another way to make the matching faster is to reduce the image into smaller images, and then search the smaller sub images for a match to the template, these smaller images are often referred to as an image pyramid (i.e. a 128 x 128px image can have a pyramid of smaller images which are 64x64, 32x32, l6x16 etc). After finding matches in the smaller images, that information is used in the larger image as a center location. The larger image is then searched in a small window to 13 find the best location of the pattern. Other methods can handle problems such as translation, scale and image rotation. Image registration with template matching technique has been used and the accuracy of them is proven to determine the appropriate shift for single - polarized SAR images.[PROCESSING OF POLARAMETRJC SAR IMAGES by Pamela A. Delaney] and Computational methods for nonlinear image registration by Ulrich Clarenz, Marc Droske, Stefan Henn, Martin Rumpf, and Kristian Witsch. 2.4 Cross-correlation Cross-correlation is a very efficient tool to match images. It is quite robust to noise, and can be normalized to allow pattern matching independently of scale and offset in the images. It has serious drawbacks however, in the case images of faint sources. One approach to identifying a pattern within an image uses cross correlation of the image with a suitable mask. Where the mask and the pattern being sought are similar the cross-correlation will be high. The mask is itself an image which needs to have the same functional appearance as the pattern to be found. Issues may be, the process can be extremely time-consuming, and the 20 cross- correlation function needs to be computed for eve"ty point in the image. Calculation of the cross correlation function is itself a N2 operation. Ideally the mask should be chosen as small as practicable. In many image identification processes the mask may need to be rotated and/or scaled at each position. Printed characters in the scanned . image which are not the data to be processed should be removed in order to reduce the error; this technique is being used to remove them. -~ The correlation techniques have been used and the accuracy of them is proven to determine the appropriate shift for single - polarized SAR images.[ PROCESSING OF POLARAMETRJC SAR IMAGES by Pamela A. Delaney] 2.5 Open and Close Morphologic operators open and close are directly based on erosion and dilation. Operation open deletes "fuzzy" boundaries of an object, while close can be used to close small gaps within an object. Some of the hand written characters are split into 14 many and the parts are separated from each other and look like different characters. So this technique is being used to make them one and increase the accuracy. [1] 2.6 Erosion The fundamental operation of mathematical morphology is erosion. All mathematical morphology depends on this notion. The erosion of an input image A by a structuring element B is defined as follows in equation (2.1 ): AEJB = {:x · B + x C A}--------------------- (2.1) c - Subset or equivalent of e -Erosion This means that in order to perform the erosion of A by B we translate B by x so that this lies inside A. The set of all points x satisfying this condition constitutesA9B The erosion of an image can also be found by intersecting all translates of the input image by the reflection of the structuring clement: A8B = ()A+ b: bE -B} --------------------- (2.2) E - Element of ... n- Intersection e -Erosion [4, 13, 14, 15, 16] -..... 2. 7 Dilation The dual operation to erosion is dilation. Dilation of an input image A by a structuring clement B is defined as follows in equation (2.3): A® B = U{B +a : a e A}--------------------- (2.3) E - Element of U- Union (±) _ Dilation 15 This means that in order to perform the dilation of A by B we first translate B by all points of A. The union of these translations constitutes A EBB. [ 4, 13, 14, 15, 161 2.8 Opening A secondary operation of great importance in mathematical morphology is the opening operation. Opening of an input image A by a structuring element B is defined as follows in equation (2.4): A oB = (ASB) <±>B --------------------- (2.4) e -Erosion <±> - Dilation o -Opening An equivalent definition for opening is as in equation (2.5): A 0 B = U{ B + X : B + X ~ A} --------------------- (2. 5) o -Opening U- Union ... c - Subset or equivalent of This means that in order to open A by B we first translate B by x so that this lies inside A. The union of these translations constitutes, for instance, the opening of a triangle A by a disk B (the origin coincides with the centre of the disk) is the triangle A with rounded corners. In general, opening by a disk rounds or eliminates all peaks extending into the image background. [4, 14, 15, 16] -.... 2.9 Closing The other important secondary operation is closing. Closing of an input image A by a structuring element B is defined as follows in equation (2.6): A • B =(A (f)B)SB --------------------- (2.6) • -Closing e -Erosion <±> - Dilation 16 For instance, closing a triangle A by a disk B (the origin is on the centre of the disk) yields the same triangle A. Jn this case and we say that A is B-close. In general, closing by a disk rounds or eliminates all cavities extending into the image foreground. [4, 14, 15, 161 2.10 Color Scale Conversion- gray scale The grayscale processing method is also used in image processing to make the process easy and reduce the processing power. Some grayscale processing methods are based on the brightness graduation data of the image captured by the camera. The binary conversion method recognizes only white or black ( 1 or 0) data. The grayscale processing method divides the brightness graduation into 8 bits (256 levels), and obtains a differentiation result based on all the data. Therefore this method offers more shade resolution and therefore more accurate detection. [14] ... -..... 17 3. Materials and Methods Image registration (cross-correlation) Start Template image scanned image Generate line image Subtract line image from registered image Remove rroise· Count characters and index into the Database 1 --..... Find images using the stored index ( End ] Figure 3.1: Flowchart of the model 18 UNIVERSITY i»'18didd Card samples are collected from Persons Registration Department for this project. There are many preprocessing involved due to the poor quality of the samples which don't meet the requirements of the image processing task. Physical cards which are, printed and hand writing filled are batch scanned and saved as digital images. Since many cards are lasting for long years they became blurred over the years. During the batch scanning there is a thread of images affected with geometric distortion due to the poor alignment of the card. The other problem may be the poor quality of hand writing. In some cases, there could be a situation where longer space left between two .....,. Figure 3.2: Scanned image (Eyes and 10 Numbers are masked in order to keep the confidentiality) 3.1 Adding images to the system 3.1.1 Template image: Template image contains only the printed characters and this image will be used to identify and remove the printed characters from the image samples. gr{~1 19 Figure 3.3: Template image During the first preprocessing action, the image is converted to grayscale from RGB. This will eliminate the hue saturation information while retaining the luminance which will make processing easier and efficient. In the first attempt RGB images arc converted into Binary image. Since there are only two values in binary image, threshold application for noise removal wasn't a success ... as expected. 3.1.2 Printed Character Removal: Match or Register entire template at once with the scanned image is not practical because scanned images are geometrically destroyed and intensity of the images also differs. That means the pixel pattern of the template is not exactly same as the scanned ....... image. And the handwritten characters are treated as noise in this case, because template image contains only the printed characters and lines, and the other scanned images which need be registered with the template contains printed as well as the handwritten characters. So there arc no possibilities of matching the whole image at once with the template. For the entire template matching, cross-correlation fails with unacceptable noise level. The total offset or translation between images depends on the location of the peak in the cross-correlation matrix, and on the size and position of the sub images. 20 Therefore to overcome these problems, the small portions of template image is cropped and registered with the original image using cross-correlation technique. Figure 3.4: Cropped Image The cropped image will be the template, and it must be smaller than the scanned image. The peak of the cross-correlation matrix occurs where the cropped image is best correlated. This also gives unacceptable result for the binary images and better result for the grayscale images. Binary images show much deviation between template and the scanned image. Image registration (cross-correlation) locates the matching area for the sub image (Cropped image) in the scanned images. ,. ~ ~- ' "> Figure 3.5: Name surroundings after the removal of printed characters 3.1.3 Removal of lines: After removing the printed characters from: scanned image the remains are lines and the hand written characters. Printed lines always introduce some noise while giving ...,... incorrect results in character count. Removing Horizontal Lines: Entire image is horizontally traversed starting from the left top corner and the each pixel examined for their intensity values. Pixels which have the intensity more than 220 are considered as part of the printed lines or the hand written characters. If these pixels go on with more than 15 pixels then this is identified as a horizontal line and a new same size image is created with this pixel values. 21 Removing Vertical Lines: Same procedure is followed but this time traversal carried out vertically. Identified vertical lines also copied to the same new image which is created from horizontal lines. Now the new image contains only the lines (vertical and horizontal). This new image Figure 3.6: Generated line image """"' Problem!: It was tried to remove the lines without creating the line image for subtraction. However, there were problems found such as the remaining sectored vertical lines after removal of horizontal lines, i.e., dash lines. Hence it was much difficult to locate the vertical line. Therefore it was decided to create a same sized line image and subtract from the original image. Problem2: It was also tried to use the Hough transform to locate the lines. Hough transform can locate the lines correctly and measure the angle of rotation also. After the rotation it is 22 difficult to do the subtraction and get the good result, due to the noise left 111 subtraction process. Figure 3.7: Scanned image after the line removal a)oe-ri d ...; ,1 ~~ (1' ~ :i o 6~; ) ·. --- -· j .... ' . - - ... -····- ·- ·• . .. . . .... - - · ..... . . . - --- .... --· . - ...... - -· ··•·· --·· ...... _- .. ·····- Figure 3.8: Name surroundings after the removal of l ines 3.1.4 Closing: The Closing operation is used to shape up the discon tinuities in tflc characters in order to eliminate the possible errors. The figure 7 shows t he image before closing operation while the figure 8 shows the same image after the clo sing is performed. ;o.,.,-1 ~ ---~/. I file_ count= file_ count - 1; set(handles.popFileName,'Value' ,file_ count); set( handles. pbNext,'Enable' ,'on'); global file_ list; file_ name = strcat(' .II mages/' ,file _list( file_ count)); file_name = char(file name); image(imread(file _name)); axis off else sct(handles.pbPrev,'Enable','off); end autoposition.m function [im 1, im2, varargout] - autoposition(im I, im2) [y x z] = size(im2); [y I xI z2] = size(im I); c = normxcorr2(im2,im I); % offset found by correlation [max_c, imax] = max(abs(c(:))); [ypeak, xpeak] = ind2sub(siL:e(c),imax(l)); corr_offset = [(xpeak-size(im2,2)) (ypeak-size(illl,2, I))); offset = corr _offset; xoffsct = offset(l); yoffset = offset(2); % Images begin at (I, I), so add one to the offset values for coordinates xbegin = xoffset + I; xcnd = xoffset + size(im2,2); ybcgin = yoffset + 1; yend = yoffset + size(im2, I); im I = im I (ybegin:yend,xbegin:xend,:); if nargout > 2 varargout { 1} = offset; end find no of char.m function[n] = find_no_of_char(img_bw) roi = [226,14,442,77]; --:~ 36 f2=imcrop(img_ bw,roi); se 1 = strel('line' ,3 ,90); f2 = imclose(f2,se I); [labeled,numObj] = bwlabcln(f2,8); obj_data = regionprops(labeled,'basic'); all_obj = (obj_data.Arca]; small_obj = length(find(all_obj < 20)); n = numObj- small_obj; insert.m function[]= insert(no_of_char,file_name) conn= database('PersonDetails', ", "); exdata = {no_of_char,file_namc}; colnames = {'NoOfChar', 'FileName'}; insert(conn, 'Details', colnamcs, cxdata); remove _lines _gray .m function [im_temp] = remove_lines_gray(im) size im = size(im); im_temp = ones(size_ im); fori= I : size_im(2) b_count = 0; for j = 1 : size_im(l) if(im(j,i)< 220) b_count = b_count + I; else if(b _count > 1 5) fork= j-b_count: j-1 im_temp(k,i) = im(k,i); end end b_count = 0; end end end fori= 1: size_im(l) b_count = 0; for j = 1 : size_ im(2) if(im(iJ)< 220) b_count = b_count + 1; else if(b _count> 1 5) .., -.,.. 37 fork= j-b_count: j-1 im_temp(i ,k) = im(i,k); end end b count= o· - ' end end end remove _printed_ characters.m function [image] = remove _printed_ characters(image,im _ temp,roi) im temp= imcrop(im_tcmp,roi); [im3 im4 offset] = autoposition(image, im_temp); im5 = imabsdiff(im4,im3); xoffset = offset(l); yoffset = offset(2); % Images begin at (1, I), so add one to the offset values for coordinates xbegin = xoffset + 1; xend = xoffset + size(im4,2); ybegin = yoffset + 1; yend = yoffset + size(im4, 1 ); fori = 1 :size(im4, 1) for j = 1 :size(im4,2) if (im5(i,j) < 65) im5(i,j) = 250; end end end image(ybegin:yend,xbegin:xend,:) = im5; add.m function[] = add() .., ~ [fileName,pathName,Filterlndcx J - uigctfile('* .jpg','Select file','MultiSelect' , 'on'); ifFilterlndex = 1 fileNameChar =char( fileName); load tempelate _image_ data. mat; im_temp = rgb2gray(im_temp); if class(fileName) = 'char' 38 file_size = 1; else file_size = length(filcNamc); end hbar = waitbar(O,'Addition in progress - Please wait ... '); for I = 1 : file size img = irnread([pathName fileNameChar( l,:)]); img = rgb2gray(img); roi = [577,29,67,16); img = remove_printcd_characters(img,im_temp,roi); roi = [232,30,25,11]; img = remove _printed characters(img,im_temp,roi); roi = [556,74,21,15); img = remove_printed_characters(img,im_temp,roi); roi = [609,74,28, 15]; img = remove_printed_charactcrs(img,im_tcmp,roi); im_gray = uint8(remove_lines_gray(img)); im = -imabsdiff(im2bw(img,.85),im2bw(im_gray,.5)); n = find_no_of_char(im); insert(n,fileNamcChar(l,:)); waitbar(Vfile _size); end ' close(hbar); end 39