PDA

View Full Version : Conversion of .BMP files to


Ed
18th January 2006, 08:35 AM
manipulable arrays.

A while back we had a discussion about pattern recognition here. It occured to me that if a .bmp file (b&w) could be converted to a vector containing 1's and 0's one might do simple correlations between an unidentified pattern and a library of identified patterns in order to identify the unidentified pattern. Awkward sentence, no?

As it turns out I might get involved with a project where I would be able to populate the "known" pattern database with some number of identified examples.

While my programming skills are creakey, it seems to me that a routine for making vectors of .bmp files has probably been done by someone somewhere.

Anybody know of such a utility?

The original thread is here

http://forums.randi.org/showthread.php?t=44200

Nick Bogaerts
18th January 2006, 10:23 AM
MATLAB springs to mind nearly immediately, since it has an excellent image processing toolbox. But it might be overkill.

Elind
18th January 2006, 10:44 AM
manipulable arrays.

A while back we had a discussion about pattern recognition here. It occured to me that if a .bmp file (b&w) could be converted to a vector containing 1's and 0's one might do simple correlations between an unidentified pattern and a library of identified patterns in order to identify the unidentified pattern. Awkward sentence, no?

As it turns out I might get involved with a project where I would be able to populate the "known" pattern database with some number of identified examples.

While my programming skills are creakey, it seems to me that a routine for making vectors of .bmp files has probably been done by someone somewhere.

Anybody know of such a utility?

The original thread is here

http://forums.randi.org/showthread.php?t=44200

Isn't that what OCR software does, not to mention script recognition?

That's available for different languages, so I suspect there will be a generic package somewhere that can be trained for new characters.

Chris Haynes
18th January 2006, 10:51 AM
I remember using that kind of utility in a program called "Micrografix Designer" back in the days of Windows 3.xx (over a decade ago). I used it to convert a scanned building site plan into a vector file to use with a CAD program.

I did a quick search and came up with this:
http://graphicssoft.about.com/od/bitmaptovector/

Edit to add... with the google search words of "trace vector bitmap graphics" I also found this:
http://autotrace.sourceforge.net/

(the command to create a vector file out of bitmap on Micrograhix Designer was "trace")

epepke
18th January 2006, 11:42 AM
manipulable arrays.

A while back we had a discussion about pattern recognition here. It occured to me that if a .bmp file (b&w) could be converted to a vector containing 1's and 0's one might do simple correlations between an unidentified pattern and a library of identified patterns in order to identify the unidentified pattern. Awkward sentence, no?

I wrote someone a program to do this a long time ago. She was studying children's drawings using SASS.

If you have access to an OSX Mac, it's less than a half page of simple code to read an image and extract the information.

I tried to do this not too long ago on a Windows machine. It rapidly got to the "not worth the effort" stage. I downloaded some packages that would have been great if they had run under XP.

You might be able to do something using Script Fu in the GIMP.

Ed
18th January 2006, 11:50 AM
Wondering if I should get an old executable of QBX and just hammer it out.

Ed
19th January 2006, 07:23 AM
I remember using that kind of utility in a program called "Micrografix Designer" back in the days of Windows 3.xx (over a decade ago). I used it to convert a scanned building site plan into a vector file to use with a CAD program.

I did a quick search and came up with this:
http://graphicssoft.about.com/od/bitmaptovector/

Edit to add... with the google search words of "trace vector bitmap graphics" I also found this:
http://autotrace.sourceforge.net/

(the command to create a vector file out of bitmap on Micrograhix Designer was "trace")

Does this provide one's and zero's?

cyborg
19th January 2006, 07:57 AM
I don't see how it couldn't?

Ed
19th January 2006, 08:04 AM
I don't see how it couldn't?

hahahaa

I mean what I need is an array of ones and zeros that represents the image.

cyborg
19th January 2006, 08:51 AM
Well getting such a representation from a BMP would be a fairly trivial programming task. You don't even have to worry if it's B&W 1bit already or not. You can just extract the luminance property via a simple colour space conversion equation and then threshold that value to produce a 1-bit monochome representation of the image.
The file format is simple enough and there's not any compression to consider.

Ed
19th January 2006, 09:12 AM
Well getting such a representation from a BMP would be a fairly trivial programming task. You don't even have to worry if it's B&W 1bit already or not. You can just extract the luminance property via a simple colour space conversion equation and then threshold that value to produce a 1-bit monochome representation of the image.
The file format is simple enough and there's not any compression to consider.

When I look at the file contents of a .bmp file, it appears that the representation is not ASCII though the format stuff I have read simply states that so many bytes are allocated to a particular value. Can you tell me the encoding scheme?

cyborg
19th January 2006, 09:57 AM
It's binary - the values in the BMP directly refer to the colour coding on screen, unless it's an 8-bit BMP in which case the values refer to a palette of colours, rather than a specific colour.

It's basically a dump of the information Windows would use to render that image through the GDI system.

Chris Haynes
19th January 2006, 04:22 PM
Does this provide one's and zero's?

I am an end user... I just assumed all binary files contain one's and zero's. I cannot tell you precisely how they are arranged.

But I do know that the end result from traces was not always readable to certain programs. Somewhere on my computer are old CAD files in about three different formats. Fortunately there is one that can read two of them. But I've not needed to do any CAD design for the past 10 years, so the programs are not even loaded on the machine (though I know where the load disks are... one consists of 5 floppy disks).

roger
19th January 2006, 04:32 PM
Ed, your wording confuses me. You are just looking for the 1/0 values for a b/w image? Your 'vector' references sounds like you are trying to do pattern recognition.

http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html documents the bmp file format. It's quite straightforward.

It's also easy to do in windows. I haven't read this particular article closely, but it looks like a good introduction (I like code guru in general, though there are often flaws/limits in the code).

http://www.codeguru.com/cpp/g-m/bitmap/article.php/c4909/

epepke
19th January 2006, 04:34 PM
Here's a description of BMP files:

http://astronomy.swin.edu.au/~pbourke/dataformats/bmp/

roger
19th January 2006, 04:42 PM
Oh ya, OpenGL in windows provides an auxilliary function to read a bmp file and provide it to you in a pointer.

AUX_RGBImageRec *pBitmap = NULL;
pBitmap = auxDIBImageLoad(FileName.c_str);


where the record structure is:

typedef struct _AUX_RGBImageRec {
GLint sizeX, sizeY;
unsigned char *data;
} AUX_RGBImageRec;


this is all in glaux.h

I haven't tried these functions without initializing the OpenGL engine, but I wouldn't be suprised that they would work fine without initializing the engine. Worth a try...

Ed
19th January 2006, 04:49 PM
Ed, your wording confuses me. You are just looking for the 1/0 values for a b/w image? Your 'vector' references sounds like you are trying to do pattern recognition.

http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html documents the bmp file format. It's quite straightforward.

It's also easy to do in windows. I haven't read this particular article closely, but it looks like a good introduction (I like code guru in general, though there are often flaws/limits in the code).

http://www.codeguru.com/cpp/g-m/bitmap/article.php/c4909/

"Vector" as in one dimensional array. Yes, pattern recognition.

If the image is say 100 x 100 I would like an array (I see where "vector" is causing a problem) 1 x 10000 consisting of 1's and 0's.

roger
20th January 2006, 10:20 AM
Well, here's a little utility to print out a file in binary (hexidecimal format). Make a tiny 20x20 b/w bmp in paint, save it, and inspect it with this program.


int _tmain(int argc, _TCHAR* argv[])
{
if (argc != 2)
return -1;

FILE* f = fopen (argv [1], "rb");
if (!f)
return -1;

unsigned char c;

int byte = 0;
while (!feof (f)) {
if (byte % 16 == 0)
printf ("\n%x: ", byte);
++byte;
fread (&c, 1, 1, f);

int i = c;
printf ("%x ", i);
}

fclose (f);
return 0;
}

With the articles given above, it should be trivial for you to take this and turn a b/w bmp into an bool array.

cyborg
20th January 2006, 02:39 PM
I have to say though I'm not entirely sure your scheme will work very well at all.

Ed
20th January 2006, 04:00 PM
I have to say though I'm not entirely sure your scheme will work very well at all.

Why?

Neither am I, but, why?

cyborg
20th January 2006, 05:39 PM
Well it would all depend on what you mean by 'correlate'. But generally the problem as I see it is that what you'd really be interested in doing for finding patterns is edge detection followed by vectorisation of the edges (by that I mean to generate some sort of vector representation of the image) and comparing these vectors against some in a library. The actual levels of each individual pixel in the image is therefore less important than how much these levels change: so you'd be analysing the wrong type of data and loosing a hell of a lot of the information that'd be useful by reducing the source image to 1-bit.