Page 1 of 1

Converting Datamatrix to binary string ?

Posted: 2012-05-15T10:46:14-07:00
by myicq
do anyone know if it is possible to convert a datamatrix (or similar) to a binary string ?

The following can be given:
Source is a 1 bit BMP image (B/W), square, f.ex 16x16 pixel, containing only a datamatrix barcode. Each dot in the matrix is 1 pixel in size. This is of course not printable, but to simplify the task.

As output I would like a binary string / binary text file containing just 2 different characters, f.ex 1 or 0 (could also be * or space), where one is for black the other for white. It does not matter if the characters are line by line, or all in one line.

I think I have heard that ImageMagick can convert images to text ?

Thanks for any input

Re: Converting Datamatrix to binary string ?

Posted: 2012-05-15T11:00:55-07:00
by fmw42
You can convert to text, but it will be characters, not binary.

Here is 2x2 block of black appended to a 2x2 block of white

convert -size 2x2 xc:black xc:white +append txt:

# ImageMagick pixel enumeration: 4,2,65535,srgb
0,0: ( 0, 0, 0) #000000000000 black
1,0: ( 0, 0, 0) #000000000000 black
2,0: (65535,65535,65535) #FFFFFFFFFFFF white
3,0: (65535,65535,65535) #FFFFFFFFFFFF white
0,1: ( 0, 0, 0) #000000000000 black
1,1: ( 0, 0, 0) #000000000000 black
2,1: (65535,65535,65535) #FFFFFFFFFFFF white
3,1: (65535,65535,65535) #FFFFFFFFFFFF white



It gives the coordinates, followed by a triplet rgb value in the quantum range of your IM compile (0 to 255) for 8-bit compile or (0 to 65535), followed by the hex value, followed by either a color name or rgb(...) with values in the range of 0 to 255.

The other way is to use -fx debug

convert -size 2x2 xc:black xc:white +append -fx "debug(i,j)" null:

black[0,0].red: i,j=0
black[0,0].green: i,j=0
black[0,0].blue: i,j=0
black[1,0].red: i,j=1
black[1,0].green: i,j=1
black[1,0].blue: i,j=1
black[2,0].red: i,j=2
black[2,0].green: i,j=2
black[2,0].blue: i,j=2
black[3,0].red: i,j=3
black[3,0].green: i,j=3
black[3,0].blue: i,j=3
black[0,1].red: i,j=0
black[0,1].green: i,j=0
black[0,1].blue: i,j=0
black[1,1].red: i,j=1
black[1,1].green: i,j=1
black[1,1].blue: i,j=1
black[2,1].red: i,j=2
black[2,1].green: i,j=2
black[2,1].blue: i,j=2
black[3,1].red: i,j=3
black[3,1].green: i,j=3
black[3,1].blue: i,j=3


see:
http://www.imagemagick.org/Usage/files/#txt
http://www.imagemagick.org/script/fx.php

You might also be able to convert the image to NetPBM binary or ascii formats (pbm). IM supports that format.

see
http://netpbm.sourceforge.net/doc/
http://www.imagemagick.org/Usage/formats/#netpbm
http://netpbm.sourceforge.net/doc/pbm.html