• Quick note - the problem with Youtube videos not embedding on the forum appears to have been fixed, thanks to ZiprHead. If you do still see problems let me know.

Conversion of .BMP files to

Ed

Philosopher
Joined
Aug 4, 2001
Messages
8,658
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://www.internationalskeptics.com/forums/showthread.php?t=44200
 
MATLAB springs to mind nearly immediately, since it has an excellent image processing toolbox. But it might be overkill.
 
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://www.internationalskeptics.com/forums/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.
 
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")
 
Last edited:
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.
 
Wondering if I should get an old executable of QBX and just hammer it out.
 
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?
 
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.
 
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?
 
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.
 
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).
 
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/
 
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, 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.
 
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.
 
I have to say though I'm not entirely sure your scheme will work very well at all.
 

Back
Top Bottom