Barcode Image Recognition
From SoftwarePractice.org
Barcode Recognition Methodology
Barcodes, as stated above, due to the differing widths of the bars and spaces can essentially be composed of binary code, i.e. 1s or 0s. Thinking about the notion of barcode recognition within MATLAB is probably much simpler as we need to determine a way to convert the barcode image of bars and spaces into perhaps a graph, with the vertical axis ranging from 0 to 1, corresponding to the bars and spaces, etc. To convert the image to a graph as such would then allow us to manipulate MATLAB to read the graph and determine the numbers involved.
Functions: EXTRACTION_D, readimage
Barcode Image Recognition is an important step within our program as it aims to determine the position and hence, extract the barcode image from the surrounding area.
readimage.m
The function initially converts the barcode image, into a 1 dimensional array of 1s and 0s. We have designed it such that the 1s correspond to the bars, and the 0s correspond to the spaces of the barcode.
Here is the flow chat of readimage.m
The next important step is to crop the barcode image. The function is designed such that it scans the image, both vertically and horizontally, determining the end values associated with the edge of the barcode. Once these edges are established, the imcrop function within the image processing toolbox is utilised to crop the image to only include the barcode, eliminating any space that surrounds it.
crop image flow chat:
Since it is known that a UPC-A barcode consists of 95 bits, we convert the found barcode array to the 95 bits, using mathematical formulation. This step is performed to ensure that all the barcodes are uniform and hence, allowing us to determine the widths of each bar and space so we can decode the image into its respective numeric code.
Analysis of readimage.m
1. Input Image
- Input image with white border
2. Convert image to 1 dimension
- As the figure show that the first 37 bit is 1, it indicates that the bar code should start from 38 bit from the figure
3. Convert image to 95 bit
- After convert to 95 bit, this is the output of readimage.m. Output from this function can go convert.m and get the result of the barcode.
4. Crop bar code from image
- This picture indicate that only necessary bar code area crop into new image. all unnecessary area(white border) are removed.
To view the corresponding Matlab code: readimage.m Code
Alternative Method
We had constructed an alternative method for barcode extraction from the whole image, and had written a partial code. We decided not to employ this technique as it did not operate as we had hoped, and therefore, had to determine extraction through another mean.
EXTRACTION_D.m
We have also created another function relating to barcode extraction. This function initially ensures that the image is greyscale, rather than RGB. Using the edge function, in conjunction with a sobel filter, we are able to determine the threshold value of the image. Using this type of filter within the edge function, the program locates the edges of the image where the derivative gradient of the image is at a maximum.
Within the calculation of the threshold value, a “fudgeFactor” is incorporated to allow for any discrepancies related to the barcode image. The edge function is employed again taking into account the determined threshold value and the fudgefactor.
We then create 2 structured elements of type line, which are then used to enlarge the barcode image. Once the image is expanded, the imfill function is used. This function fills any holes within the created binary image. The image is then eroded with another created structured element using the imerode function. This aims at extracting the barcode lines from the entire image.
To create an outline of the bars within the barcode, bwperim is executed to enable an outline of the original image.
To view the partial code for this method: Extraction_D.m Code
Back to Team F's Main Page Team F: Barcode Reading from Image






