Anda di halaman 1dari 39

ME 5405 Machine Vision Term Paper Computing Project

FOONG YI WEN PANTUA,CONRAD ALLAN JAY

U076701Y A0065790X

INTRODUCTION
This paper aims to compare between different methods of image processing and between processing different images. It is organised according to the different processing required. Processing requirements in 8 parts. 1. Threshold the two image and convert it into binary image. 2. Display the original image on screen. 3. Determine the outline(s). 4. Segment the image to separate and identify the different characters. 5. Rotation of the characters about their own respective centroids by 90 degrees. 6. Determine a one-pixel thin image of the characters. 7. Scale and display the characters of Image 1 in one line in the secuence: A1B2C3. 8. Scale and display the characters of Image 2 in three lines: Line 1 SCF, Line 2 2093 and Line 3 Z. For each requirement, content is further broken down as follows

1. 2. 3. 4. 5.

6. 7.

Introduction to the problem, Actual function used in Matlab Description of algorithm Screen dumps of outcomes Discussion which include Explanation on choice of method Difficulties encountered Compare on how processing the 2 images are similar/different Flow chart of preferred methods algorithm M-codes of algorithms

PRE-PROCESSING Introduction
Since charact1.txt is not originally an image file, pre-processing is needed to turn it into one before storing into workspace. For charact2.bmp, the Matlab function imread was sufficient to store image2 into workspace.

Function
image1=text2im(charact1.txt); image2=imread(charact2.bmp);

Description of algorithm
Text file is opened and input into a string. This string is then stored into a double matrix, line by line. While storing, in order to determine whether end of line in text file is reached, check if carriage return is encountered. If encountered, storing cue moves to the next row in matrix and storing is skipped for carriage return. After storage is done, double matrix is converted into image file for output.

OUTCOME OF text2im ON charact1.txt = IMAGE1

charact2.bmp READ INTO WORKSPACE = IMAGE2

Discussion
One problem encountered was not knowing the cue to start inputting in the next line, since the text was first converted into a continuous string. At first, new line or char(10), was thought to be the cue for next line input. However, an error was produce and thus, a test function to return ascii value was done to identify the correct cue, char(13) or carriage return. Algorithm flow chart

Algorithm flow chart

Open and scan text into a string

Prepare double matrix mat to input text Skip storage for character Shift storing to next line Continue storage in current row

Yes Scan every character Check if character is char(13) No

When storage is done, convert mat into image uint8 for output

PART ONE
Threshold the two image and convert it into binary image.

Introduction
Thresholding is used to convert images into binary images, which consists of only black and white pixels. This is done so that clear distinction of characters can be observed against background of the images. Using various methods, a threshold value can be derived for an image. This threshold value sets the bar to switch pixels having gray levels lower or equal to this value to black 0 and those above to white 255. Two methods of thresholding were used here. First, manual thresholding based on lookup table from histogram and second, graythresh function from Matlabs image processing toolbox, using Otsus method.

1) Manual Thresholding from histogram lookup table


Function
[hist1 lookup1]=hist(image1); bin1L48=bin(image1,48); [hist2 lookup2]=hist(image2); bin2L254=bin(image2,254);

HISTOGRAM 1

HISTOGRAM 2

Description of algorithm
Based on lookup tables lookup1 and lookup2 generated from histogram of image1 and image2, hist1 and hist2, the pixel spike, which represents the background, occurs at level 48 and 255 respectively. For image1, pixels representing characters have gray levels higher than 48, thus 48 is considered the optimal threshold level to separate background by switching it to black 0. For image2, pixels representing characters have gray levels lower than 255, thus 254 is considered the optimal threshold level, when all pixels representing foreground are switched to black 0. MANUAL THRESHOLD OF IMAGE 1 AT OPTIMAL LEVEL 48 bin1L48

MANUAL THRESHOLD OF IMAGE 2 AT OPTIMAL LEVEL 254 bin2L254

For image1, if threshold level increases, details of the characters disappear and holes start to appear from the sides. Thresholding with levels 49 and 50 show the gradual loss in details. Similar to image1, details of the characters are lost as the threshold moves further away from the optimal threshold in image2. However, it is not as obvious in the case for image2, since the character pixels lie in a wider range of gray levels. Thus, samples of threshold levels 200 and 150, which are much further from 254, are used to illustrate this. Also important to note is that the loss in detail in image2 causes loss in connectivity. By threshold of 200, character Z needs a 8-connectivity in order to be considered whole. By threshold of 150, character Z is entirely disconnected. This causes problems in component labelling at a later stage.

MANUAL THRESHOLD IMAGE 1 LEVEL 49 with loss of details

MANUAL THRESHOLD IMAGE 1 LEVEL 50 with loss of details

MANUAL THRESHOLD IMAGE 2 LEVEL 200 with loss of details

MANUAL THRESHOLD IMAGE 2 LEVEL 150 with loss of details

2) Matlabs image processing toolbox: Graythresh function using Otsus method


Function
level1= graythresh(image1); gray1= im2bw(image1,level1); level2= graythresh(image2); gray2= im2bw(image2,level2);

Description of algorithm
Progressively from gray level 0 adding up to 255, calculate weight and mean of background and foreground to produce 4 variables, Wb, Wf, b and f for each case. Eg. Case1: 0 to 20 is background, 21 to 255 will be background. Case2: 0 to 21 is background, 22 to 255 will be background. Then calculate between-class variance, 2B, for each case. Compare all between-class variance, case which has the maximum will be the threshold level. In example case1 above, gray level 21 is the threshold. Formulae Weight = Number of pixels in ground / Total number of pixels Mean = (gray level*number of pixels for gray level) / Number of pixels in ground 2B = WbWf (b - f)2 OTSU THRESHOLD IMAGE 1

OTSU THRESHOLD IMAGE 2

Threshold levels generated were 0.2373 and 0.4490, for image 1 and 2 respectively. The red circles represent loss in detail in both images threshold by Otsus method, in comparison to manual thresholding. In fact, for image2, thresholding with Otsu causes a break in character Z which will also cause component labelling problem later on. The thinning of characters S and 2 also set a prerequisite of 8-connectivity for component labelling.

DISCUSSION
Since manual thresholding enables maximum recovery of details and does not pose problems for component labelling using 4-connectivity later on, it is the preferred method, using optimal gray levels of 48 and 254 for image 1 and 2 respectively. Outcome of thresholding image 1 and image 2 are different due to the distribution of gray levels. The gray levels of image 1 characters are distributed over a much smaller range compared to image 2. Thus, when loss in detail sets in due to non-optimal thresholding, characters in image1 are only able to maintain connectivity for a short range of threshold levels, unlike those in image 2 which can maintain their shape for a much longer range. However, the way in which loss in detail sets in for both images is similar. The loss starts from the outer pixels, gradually losing inward.

Algorithm flow chart


Apply hist function on image to obtain look up table

Note value of background gray level from lookup table to obtain optimal threshold

Threshold all pixels according to optimal threshold

Scan pixels to check if lower, equal or higher than threshold

Lower / equal

Higher

Convert pixel to 0 black

Convert pixel to 255 white

Display threshold image

PART TWO
Display the original image on screen.

Introduction / Description of algorithm


Display image1 and image2 based on reading charact1.txt and charact2.bmp from pre-processing

Function
Figure; imshow(image1); Figure; imshow(image2);

IMAGE 1

IMAGE 2

PART THREE
Determine the outlines

Introduction
The outlines of the image or its edges are just the boundaries between two regions with different gray level properties. In order to determine the edges, a local derivative operator will be used. The second derivative can be used to determine if an edge pixel lies on the dark or light side of an edge. The method used in this problem is the Sobel operator and Laplacian method. Matlab has a built in function in its image processing toolbox called edge(). The edge function takes a binary or grayscale image as input and outputs it as an outlined binary image. Matlab offers other methods for detecting edges other than the two methods mentioned such as Prewitt, Roberts and the zero cross method. In this project, Sobel's and Laplacian methods were implemented mainly for comparison purposes.

Function
Sobel sobeledge1 = edge(image1,'sobel'); sobeledge2 = edge(image2,'sobel');

Laplacian Logedge1 = edge(image1,log); Logedge2 = edge(image2,log);

Description of algorithm
Sobel The gradient of an image is given by two vectors Gx and Gy which corresponds to the x and y direction respectively. This gradient vector points in the direction of maximum rate of change, where Gx is a partial derivative of f with respect to x and Gy is the partial derivative of f with respect to y. The sobel operator utilizes a digital form of derivation.

The derivatives based on the Sobel mask are as follows:

Gx = (Z7 + 2Z8 + Z9) (Z1 + 2Z2 + Z3) Gy = (Z3 + 2Z6 + Z9) (Z1 + 2Z4 + Z7)

eq 1 eq 2

Where the mask is given by:

Z1 Z4 Z7

Z2 Z5 Z8

Z3 Z6 Z9

Sobel mask

The final value of the gradient(x,y) is given in this equation:

delta F = abs(Gx) + abs(Gy)

eq. 3

Matlab will then decide above or below what gradient level should a pixel be converted to background 0 or outline 1.

The process is repeated with the sobel mask moved to the next location. A gradient image highlighting the edges will be obtained with the same size as the original image.

Laplacian The laplacian method unlike the sobel uses a second derivative operator. In a 3 x 3 mask, the general equation to be implemented is:

d2f = 4Z5 (Z2 + Z4 + Z6 + Z8)

where:

1. Central pixel should be positive 2. The outer pixels should be negative 3. The sum of the coefficients must be zero.

In theory, this method is very sensitive to noise since it uses a second order derivative. It also produces double edges. Thus, it is inferior compared to Sobel's mask. A detailed comparison will be discussed in the succeeding sections.

SOBEL ON IMAGE1

SOBEL ON IMAGE2

LAPLACIAN ON IMAGE1

LAPLACIAN ON IMAGE2

Discussion
The outlines produced by the laplacian method seem to be larger than the original characters. With this in mind, the Sobel mask gives a more accurate representation of the original characters. Even though there are discontinuities in the outlines for the Sobel method, the threshold gradient could be changed to rectify this. An example below shows an improve outline of character A, by specifying the threshold gradient for image1 using Sobel method. As a result of larger outlines, the characters for image2 using the Laplacian method also overlap each other resulting in poor readability. Hence, the Sobel method is concluded to be more ideal in comparison to Laplacian in this application. sobeledge1 = edge(image1,'sobel',0.01); IMPROVED CHARACTER A OUTLINE WITH THRESHOLD GRADIENT 0.01

PART FOUR
Segment the image to separate and identify the different characters.

Introduction
Segmenting the image is important for many functions to be carried out after this step, such as rotation of characters about their own centroids, rearrangement of characters into one line. Segmenting allows all pixels belonging to a particular character to take on a particular gray level. In fact, properties such as centroid of character can only be identified with segmentation because calculation for each centroid will only apply to pixels belonging to character based on their unique gray level. Two methods used here were Two-Pass Algorithm using Local Equivalence Table and the classical Algorithm. By visual observation, both suffice with the use of 4-connectivity.

1) Two-Pass Algorithm using Local Equivalence Table


Function
[count1 numobj1] = numobj(bin1L48); [count2 numobj2] = numobj2(bin2L254); count = number of individual shapes numobj = labelled image

Description of algorithm
Binary image is called into the function. Background pixels are switched to 0 and characters pixels to 1. Scanning of whole image is done to analyse pixels which are non-zero. If a pixel is non-zero, comparison with its top and left pixel to adopt the smallest non-zero value of the two is done. If both left and top pixels are zero, a new gray level is given for the pixel. Once the first pass is completed, a second pass iteration from the bottom right corner of the image is done. Similarly, analysis is done only if pixel is non-zero. Pixel is compared with its right and bottom to adopt smallest non-zero value of the two. If both are zero, the pixel is left as it is. The labelled image is now done. To count the number of individual shapes in image, all pixels are scanned starting from the top left corner and count is increased by 1 for every new gray level encountered.

Labelled image1 = numobj1

Labelled image2 = numobj2

Since the new gray levels of the characters are now very close to the background of 0, the characters do not show up as obvious in the screen dumps. Segmentation serves more as a functional rather than display tool for further processing.

2) Classical Algorithm Function


[shape1 labobj1]=labobj(bin1L48); [shape2 labobj2]=labobj2(bin2L254); shape = number of individual shapes labobj = labelled image

Description of algorithm
Binary image is called into the function. Background pixels are switched to 0 and characters pixels to 1. First, matrix mat is prepared to input equivalent pairs. Scanning of whole image is done to analyse pixels which are non-zero. If a pixel is non-zero, comparison with its top and left pixel to adopt the smallest non-zero value of the two is done. If top and left pixels are both non-zero and different, a check is conducted to see if pair exists in mat. If it doesnt, pair is recorded in next empty column available in mat. If both left and top pixels are zero, a new gray level is given for the pixel. Another matrix class is prepared to input equivalent pairs into their respective classes. Minimum gray level for each class is determined to change pixels in image belonging to same class to

respective class minimum. The labelled image is now done. To count the number of individual shapes in image, all pixels are scanned starting from the top left corner and count is increased by 1 for every new gray level encountered. Labelled image1 = labobj1

Labelled image2 = labobj2

Due to the same reason cited in method 1, characters in labobj1 and labobj2 are not clearly observable.

Discussion
Two-pass iterative algorithm is the preferred method in segmentation, since the steps required are much lesser. For the classical algorithm, there is an extra need to input equivalence pairs in a table and then pick out equivalence pairs to input into respective equivalent classes again. Steps in doing so are tedious. For example, when a new pair is input into a class, all the elements belonging to that class needs to be checked against the entire equivalent pairs matrix again for a match to input. Processing for image 1 and 2 is the same, except for the front where background is turned into 0 and characters are turned into 1. Background for Image1 and 2 are black and white respectively. Similarly, image1 and 2s characters are white and black respectively. Outcome for two images differ, however. Since characters in image2 consist of only one line and have the same height, labelling for image2 turns out to be continuous. This means that labelling starts from left to right, 1 to 8, without skip. Whereas in image1, due to protruding pixels in character C higher than the height of A and B, C ends up having label 1 instead. Also, since characters 1, 2 and 3 are positioned at the

bottom tier of the image, when the second iterative pass is done, they take on labels of 17, 18 and 19 instead of successive 4, 5 and 6 labels. This creates inconvenience when translation needs to be done at step 7. The labels need to be specifically rearranged into a new matrix of 6 to match new destination points, before a loop can be done to translate the characters into one line.

CHARACTER C HAS PROTRUDING PIXELS ON TOP

Algorithm flow chart of Two-pass iterative


Scan all pixels to switch background to 0 and characters to 1

Scan all pixels and check if pixel is zero No

Yes

Ignore and skip to check next pixel

Both zero Check with top and left pixels and change pixel accordingly One non-zero Both non-zero Apply second analysis from bottom right corner

Assign new gray level Adopt non-zero new gray level Adopt smallest of two new gray level

Scan all pixels and check if pixel is zero No

Yes

Ignore and skip to check next pixel

Both zero Check with bottom and right pixels and change pixel accordingly One non-zero Both non-zero

Leave pixel untouched Adopt non-zero new gray level Adopt smallest of two new gray level

Labelled image is ready for output

Count flow chart


Assign index to zero and scan all pixels to see if it coincides with index No Yes Ignore and skip to check next pixel

Increase count by one

Scanning of all pixels done, output count

PART FIVE
Rotation of the characters about their own respective centroids by 90 degrees.

Introduction
Characters are rotated anticlockwise by 90degrees with respect to their centroids. The centroids here are calculated with respective weights of the characters, and not the centre of their height and weight. Since the centroids usually turn out to be non-integers, after calculation of a pixels new destination, rounding is done to determine the new position of a pixel.

CENTRE OF HEIGHT AND WEIGHT

CENTROID WITH WEIGHT

Function
rotated1 = rotate(bin1L48); rotated2 = rotate2(bin2L254);

Description of algorithm
Binary image is called into the function. A two-pass iterative component labelling algorithm is performed to count and label the different characters. After this, only for binary image2, a bigger blank image twice the image width is prepared, and the binary image is stored into it. Then in this bigger image, characters are spaced out by adding 5 more columns between every pair of characters. This is done by detecting characters from left to right, one by one, and shifting remaining characters on the right 5 columns to the right, for every new detection. For example, detect S, and shift CF2093Z 5 columns right. Detect C, and shift F2093Z 5 columns right. Now, for the next step in the general algorithm, an array is prepared for storing the different labels of characters. Another matrix cent is prepared for storing centroid of characters, calculated based on averaging distance of each character pixel from origin on top left corner of image. A new matrix is now prepared to store rotated characters. All pixels are scanned for detecting a new character. Whenever a pixel belonging to a new character is detected, scanning is halt, the pixel label is located in array and its index is used to detect matching centroid located in cent. Then, the image is rescanned to detect and process all pixels in image belonging to this character. Distances of each pixel from centroid are calculated. The new location of pixel is calculated based on switching distance in i-direction to negative j-direction and switching distance in j-direction to i-direction. The new position of pixel is rounded to integers and the label of pixel is now stored in this new position. Image is then output as

binary by switching all character pixels to white for image1 and black for image2, and by switching all background pixels to white for image2 and black for image1. ROTATED CHARACTERS IN IMAGE1

ROTATED CHARACTERS IN IMAGE2

Discussion
To complete rotation, component labelling in the previous step is done first. Rounding off new positions is also needed, since centroid is not an integer, resulting in new position being nonintegers too. The algorithm would be different for switching of distances if rotation is done clockwise. For a clockwise rotation, new position from centroid would require switching distance in i-direction to j-direction and switching distance in j-direction to negative i-direction. The implementation for image1 is much more straightforward compared to image2. Due to the fact that characters in image2 are much closer together, rotating them causes overlapping. The resulting orientation becomes unobservable. Hence, extra steps for spacing out characters in image2 were needed. Images before and after spacing are shown to illustrate the effect of spacing. Resultant image from rotating characters without spacing is also shown for illustrating unobservable orientation. BINARY IMAGE2

SPACED OUT CHARACTERS IN IMAGE2

ROTATING CHARACTERS WITHOUT SPACING = UNOBSERVABLE ORIENTATION

Algorithm flow chart


Perform two-pass iterative component labelling algorithm to count and label the different characters Only for image2

Store image into a bigger image, twice the width

Store labels of different characters into array

Space characters out by shifting 5 columns right between every adjacent pair

For each character, calculate centroid and store into cent with corresponding index from array

Prepare new matrix rot to store rotated characters

Halt scan

Scan all pixels to detect a new character pixel

Pixel detected

Locate pixel in array and note index

Rescan image to detect all pixels belonging to the character

Use index to locate matching centroid

For each pixel

Calculate distances from centroid

Redo process for all characters and all pixels belonging to these characters

Calculate new distances from centroid by switching accordingly

Calculate new position of pixel and round off to integers

Output binary image

Store label into new position

PART SIX
Determine a one pixel thin image of the characters

Introduction
The image is reduced to a one-pixel thick outline simplifying the character. Majority of the pixels will be eroded but a joined skeleton of the image must remain.

Function
Skeleton1=thin(bin1L48); Skeleton2=thin2(bin2L254);

Description of algorithm
This algorithm is valid only to binary images. Hence, the two images in grayscale will be converted first into a binary image before the actual thinning processing. The background pixels are 0 and region points to be 1. The image will pass into two consecutive passes utilizing two steps. A 8 neighbourhood mask will process each contour point. To determine if its contour point at P1, P1 should have a value of 1 and at least one of the 8 neighbours with a value of 0. Each contour point will be processed and if all of the conditions outlined in step 1 are satisfied, then the pixel (P1) will be flagged for deletion. After all of the contour points are processed, the flagged points will be deleted. A second pass will be conducted on the new contour points as a result of step 1. The same procedure will be applied and if P1 satisfies all conditions outlined in step 2 then the point will be flagged for deletion. After all the contour points are processed, the flagged points will be deleted or converted to 0.

8- Neighbourhood mask

P9 P8 P7

P2 P1 P6

P3 P4 P5

Step 1 conditions a) The number non-zero neighbours of P1 should be in the range from 2 to 6. b) S(p1) = 1. The no of transitions from P2 to P9 should be 1. c) p2*p4*p6=0 d) p4*p6*p8=0

Step 2 conditions a) The number non-zero neighbours of P1 should be in the range from 2 to 6. b) S(p1) = 1. The no of transitions from P2 to P9 should be 1. c') p2*p4*p8 = 0 d') p2*p6*p8 = 0

THINNED IMAGE OF CHARACT1.TXT

CHARACT2.BMP AFTER THINNING

Discussion
The result was more satisfactory for image2 as it is clearly one-pixel thin every character. Image 1 was also reduced but some parts of the characters still have thickness higher than one-pixel, since the input characters were in the first place non-uniform in thickness. There are was only a few minor hiccups in implementing the code. For condition (b), at first, 0-1 transition was mistaken to be transitions of 0-1 and 1-0. But later it was rectified to count only 0-1 transitions. Also, the last round in comparing p(2) and p(9) was missed out at first, which was later included. Other than that, the algorithm is straightforward.

PART SEVEN AND EIGHT


Scale and display the characters of Image 1 in one line in the sequence: A1B2C3. Scale and display the characters of Image 2 in three lines: Line 1 SCF, Line 2 2093 and Line 3 Z.

Overview
Content will be split into 2 main parts

1. Scaling of binary image1 and image2 2. Arranging characters in binary image1 into sequence A1B2C3 Arranging characters in binary image2 into sequence: Line 1 SCF, Line 2 , 2093 and Line 3 Z

1) Scaling of image1 and image2


Introduction
Scaling changes the images overall length and width. It can be done by specifying a factor where length and width maintain the same ratio after scaling. Alternatively, desired length and width after scaling can be specified. The gray levels of pixels in the new images are decided via brightness interpolation of the original image pixels.

Description of algorithm
The scaling of the image consists of utilizing the matlab command called imresize. The methods used in scaling the images are bicubic and nearest neighbour interpolation methods.

A discrete raster is used to determine interpolation reference points. The nearest neighbourhood algorithm just selects the value of the nearest point, where f(x,y)=g(round(x),round(y)), with g representing the discrete point brightness. For bicubic interpolation, the nearest 16 neighbourhood points are used, and the brightness of the pixel is approximated via a kernel factor. Thus, f(x,y)=h(xA)h(yA)g(A)+ h(xB)h(yB)g(B)+.

BICUBIC KERNEL Both images were scaled into three times its size. The two methods were used for comparison purposes.

Function
NEAREST NEIGHBOUR INTERPOLATION nearest1 = imresize(image1,3,'nearest'); nearest2 = imresize(image2,3,'nearest'); BI CUBIC INTERPOLATION cubic1 = imresize(image1,3,bicubic); cubic2 = imresize(image2,3,bicubic);

NEAREST INTERPOLATION ON IMAGE1

NEAREST INTERPOLATION ON IMAGE2

BICUBIC INTERPOLATION ON IMAGE1

BICUBIC INTERPOLATION ON IMAGE2

Discussion
Comparatively, the nearest neighbour method is mathematically easier to implement than the bicubic method. However, the characters processed with the nearest neighbour interpolation

appear to have more defined and abrupt edges compared to those that undergone bicubic interpolation. This is due to more reference points used in the bicubic method, thus the onset of smoothening edge effect. Generally the bicubic method is more favourable as it tries to adopt brightness levels closer to the original image. However, due to its smoothening effect, it is not recommended if clear outlines of objects in the image are of high importance.

2) Arranging characters in binary image1 into sequence: A1B2C3 Arranging characters in binary image2 into sequence: Line 1 SCF, Line 2 , 2093 and Line 3 Z
Introduction
Characters in binary image1 will be arranged into sequence A1B2C3, while characters in binary image2 will be arranged into line 1 SCF, Line 2 , 2093 and Line 3 Z. Many individual processing make up this step. Processing are such as two-pass iterative component labelling, detection of bottom left most pixel of character boundaries in terms of height and width, translation and shifting.

Function
seq1 = n7(bin1L48); seq2 = n8(bin2L254);

Description of algorithm
Binary image is called into the function. A two-pass iterative component labelling algorithm is performed to count and label the different characters. Then, an array is prepared for storing the different labels of characters. From here on, algorithm for image1 and image 2 is different. IMAGE1 The lowest input row is marked at two-third of the image from the i-direction. Labels of characters are input into the matrix form according to the desired formation A1B2C3. Thus, the form matrix have elements arranged in this manner, 217318119. Image new is created for storing characters in new sequence. For each character, based on the order in form, bottom left most pixel is identified by scanning row from bottom and column from left. Distances of it from destination (mark, next empty column) in new is calculated. Thereafter, all pixels belonging to character is translated into new according to these distances recorded. This is repeated for all characters based on the order in form. Lastly, detecting characters from left to right, one by one, shifting is done on remaining characters on the right. These characters are shifted one column to the right, for every new detection. For example, detect A, and shift 1B2C3 one column right. Detect 1, and shift B2C3 one column right. This is done so that the characters are not stuck together. Image is then output as binary by switching all character pixels to white and all background pixels to black. IMAGE2 The image is divided into 3 parts in the i-direction and its depth is recorded as mark. Then, a marks array is created for storing the upper and lower limits of each section. Image new is created for

storing characters in new sequence. From left to right, for each character, bottom left most pixel is identified by scanning row from bottom and column from left. Distances of it from destination in new according to section, (lower mark of section depending on character, next empty column in section) is calculated. Thereafter, all pixels belonging to character is translated into new according to these distances recorded. Lastly, shifting is done for each section by scanning pixels within upper and lower limits of section. Characters are detected from left to right, one by one, and shifting is done for remaining characters on the right of target character. Characters are shifted one column to the right, for every new detection. For example, in section one, detect S, and shift CF one column right. In section two, detect 0, and shift 93 one column right. Image is then output as binary by switching all character pixels to black and all background pixels to white.

CHARACTERS OF IMAGE1 IN SEQUENCE

CHARACTERS OF IMAGE2 IN SEQUENCE

Discussion
At first, translation was tried by taking centroid of characters as basis for calculating distances of pixels to destination. However, due to the hassle of measuring length of left pixels from centroid for accommodating purposes, this idea was abandoned. NEED TO MEASURE LENGTH OF LEFT PIXELS IF TRANSLATING WITH CENTROID

At first, new destinations of characters were also fixed on new image by dividing image into six equal parts. However, this method encountered problems as some characters have longer width than others. Thus equal space provided for all characters caused overlapping, exceeding of image boundaries and unequal spacing between characters. Besides, this method requires translation to be done using centre of character or centroid, which is too cumbersome.

EXCEEDING OF IMAGE BOUNDARIES AND UNEQUAL SPACING BETWEEN CHARACTERS

Lastly, bottom left most pixel was misinterpreted during the first trial translating with it. This caused overlapping as the wrong bottom left pixel was not representative of the characters left limit. It was subsequently rectified.

WRONG BOTTOM LEFT

CORRECT BOTTOM LEFT

Processing both images is similar in most parts. The biggest difference lies in the need to pre-arrange labels according to desired formation for image1 and preallocating labels for different sections for image2. Also, in locating new destinations to input the translated characters, only a mark in the i-direction two-third into the image is required for image1. Whereas for image2, each sections upper and lower limits needed to be defined so that characters can be input into different lines and shifting can be done later by only checking within limits of each section.

Algorithm flow chart of sequencing characters in image1


Perform two-pass iterative component labelling algorithm to count and label the different characters

Store labels of different characters into array

Mark at two-third of the image in the i-direction as new row destination

Obtain from array labels for the characters Re-arrange them according to desired formation A1B2C3 in form Outcome of elements in form 217318119

Create image new for storing characters in new sequence

For each character, based on the order in form, bottom left pixel identified

Left most column Bottom most row

Scan from left to right Scan from bottom to top

Determine next empty column in marked row for input

Calculate distances of left most pixel from destination (marked row, next empty column)

All pixels belonging to character is translated into new according to these distances recorded.

Process repeated for all characters based on the order in form.

Detecting characters from left to right, one by one, shifting of one column to the right is done on remaining characters on the right of target character.

For example, detect A, and shift 1B2C3 one column right. Detect 1, and shift B2C3 one column right.

new output as binary by switching all character pixels to white and all background pixels to black.