Library - barcode

barcode is a library which implements encoding and decoding functions for EAN and UCS barcodes.

The following statement makes available functions defined in barcode:

use barcode

barcodeim2w

Barcode conversion from widths to 1D image.

Syntax

use barcode
w = barcodeim2w(im)

Description

barcodeim2w(im) converts a 1D image of boolean values whose true values correspond to bars and false values to spaces, to a vector of alternating bar and space widths.

See also

barcodew2im

barcodew2im

Barcode conversion from widths to 1D image.

Syntax

use barcode
im = barcodew2im(w)

Description

barcodew2im(w) converts bar and space widths to a 1D image of boolean values. Input argument is a vector of widths; the first element is the width of the initial bar, the second element is the width of the space between the first and the second bar, and so on. All elements must be positive integers. The resut is a logical row vector of length sum(w) which contains sequences of true value for bars and false values for spaces.

See also

barcodeim2w

eanencode

Encoding of EAN-13, EAN-8 or UCS barcode.

Syntax

use barcode
(b, g, num) = eanencode(code)

Description

eanencode(code) converts a code to a barcode represented as a bit pattern. Input argument code is either a character string of digits or a vector of numbers from 0 to 9. Its length is 8 to create an EAN-8 barcode, 12 to create a UCS barcode, or 13 to create an EAN-13 barcode. For UCS and EAN-13 barcodes, the last digit is a checksum based on the first digits. To let eanencode compute it, the last element (character or number) of the input argument should be a placeholder which is not a decimal digit, such as '?' or -1.

The first output argument of eanencode is the barcode as a vector of logical values, where true represents black and false white. The second output argument is a vector of logical values with the same size which represents the longer bars. The third output arguments is a string with the code where the checksum placeholder, if any, has been replaced by the actual checksum.

Example

Here is how to display an EAN-13 barcode with the image function. The barcode itself is stretched by a factor 10, and the whole image is inverted to match what image expects (true for white).

(b, g, num) = eanencode('123456789012?')
b =
  T F T F F T F F T T ...
g =
  T F T F F F F F F F ...
num =
  1234567890128
image(~[repmat(b,10,1);g], 'e');

See also

eandecode, barcodeim2w

eandecode

Decoding of EAN-13, EAN-8 or UCS barcode.

Syntax

use barcode
code = eandecode(im)

Description

eandecode(im) decodes the barcode represented as a bit pattern im. The bit pattern is a 1D vector of logical values, where each value is true for black or false for white, and stands for the minimum thickness of a bar. The position of the barcode in the vector is detected automatically: leading and trailing garbage is ignored. The result is a string of 8 digits (EAN-8), 13 digits (EAN-13 or UCS when the leading digit is 0), or empty (unrecognized barcode).

Example

b = eanencode('12345678901?');
eandecode(b)
  0123456789012

See also

eanencode, barcodew2im


Copyright 2006-2016, Calerga.
All rights reserved.