SoftwarePractice.org: Home | Courseware | Wiki | Archive

Step 4

From SoftwarePractice.org

Interpretation and Barcode Extraction using the 'Name' function


The section describes the technique used to decode the barcode once it has been accounted for distorions, noise and clarity and rotations. 'imread' and 'imwidth' were the two main image processing tools of Matlab that were used in this stage.Apart from that, we also used various kinds of loops such as 'if' and 'while' in the code.

imWidth and imheight were used in order to find the middle vector of the barcode.It then finds the values of two rows above and two rows below.These values are then averaged out and stored into another vector. In Matlab,the Color value - 255 represents white (space)and 0 represents black(bar).Then, the mid-point between these two values was assigned as the threshold value. The values of the vector were compared to this threshold value. If the value was greater than threshold it was assigned 1 (bar) else it was assigned a 0 (space). This got rid of the gray parts in the image.These values were then assigned to a new vector named the BinaryVector.The values of the 'BinaryVector' were then assigned to the 'DecodeVector'.Odd locations in the 'DecodeVector' represented black bars and even locations in this vector represented white spaces.

A Codabar barcode always starts with a single bar and is then followed by a single or a double space.Recalling the Codabar standards mentioned earlier it is not possible to have more than two bars or more than two spaces in a barcode. These rules enabled us to use the following technique to decode the barcode.The width of a single black bar is equal to the width of a single white space.The first black position(first 1),which denoted the start of the barcode, was found.This was then subtracted with the first white position(first 0).This value represented the width of every single bar or single space of the barcode image.This value was then assigned as 'singleWidth'.

Next, we find the position of the next black.This value is then subtracted with the position of the firstWhite.The difference value is then compared with the value stored in 'singleWidth'.If the difference is greater than the 'singleWidth' then the binary numbers '00' is assigned to it.Otherwise it is assigned a single '0'.These values are sent to the 'DifferenceVector'.Similar strategy is further applied to the rest of the code.This means that if a double bar is encountered, then it is assigned '11'.Single bars are assigned'1'.These values are also stored in the DifferenceVector. This gave a set of binary values with 0s and 1s stored in the DifferenceVector.Next, this vector was scanned with a counter. After every 9 values, the code checks for the number '101' This would indicate the end of one chacter and beginning of a new character. Since barcode characters are separated with a space and they always start with a '1' and end with a '1'.

Each set of 9 binary values that were obtained, are compared with the their corresponding ASCI characters listed in the 'name' function.This function contains the equivalent values for each set of binary numbers.This information corresponds to the table listed in the Codabar section. If the length is 10 then the values are compared with the start/stop characters A-D, X and special characters ':' '.' and '/'. If the length is 9, vector is compared with numbers from 0-9 and special charcters like '-' '$' and alphabet 'Z'.

On the completion of Step 4, the final output in GUI box is displayed below

Fig 9. Final Output

Image:output.jpg

Some sample output snapshots are displayed below:

Image:test1.jpg

Image:test2.jpg

Image:test3.jpg

Return to Barcode Recognition Main Page

Personal tools