Ok, I need to know some methods(links, articles, etc.) regarding how to parse & comprehend 32-bit grayscale bitmaps on the basis of their data.
Suppose I have a black background & a white primitive of medium resolution is there any way I can identify the primitive as a Circle, Box, Triangle?

Thanks

P.S. Can someone show me a implementation of the method. One such is on Wikipedia. & the 4-byte alignment technique.

Edited 6 Years Ago by nbaztec: n/a

Yes you can.

Just use the isCircle() isBox() isTriangle() methods found under the:- #include <ai.h> header file. You have to write the ai.h file first though.

Edited 6 Years Ago by iamthwee: n/a

You have to write the ai.h file first though.

Means include prior to function calls or that I have to create the functions and the file myself.
If former, then I know that. If latter, that's what I am trying to do.
Actually I want to be able to identify the primitives based on the data & not some functions as I may need to make the algorithm much more complex as it builds up.

Thanks

First, you need to learn how to read in bitmap images. Find a tutorial with that.
Then when you know how to read in a bitmap image. You should have an array of int
values, which represents the color of the pixels in the images. For example :

black = 0x000000
white = 0xFFFFFF
Red = 0xFF0000
Green = 0x00FF00
Blue = 0x0000FF

Then you need an algorithm to detect from the array of pixels if the bitmap image
is a primitive shape. First learn how to read in the bitmap images. And get back
and we'll try to figure an algorithm out for this interesting problem.

First, you need to learn how to read in bitmap images.

black = 0x000000
white = 0xFFFFFF
Red = 0xFF0000
Green = 0x00FF00
Blue = 0x0000FF

I'm familiar with this & the 54-byte header. I open the image in binary mode ( a Black portion in Red background) & it is stored as
00 00 FF 00 00 FF 00 00 00 00 FF
I know Hex code for red is ff0000 but here the color information is rather being stored as BGR. As Blue is stored as FF 00 00. But why does it exclude a value when it stores black(See: The red part) It is stored as 00 00
Any ideas why?

when it stores black(See: The red part) It is stored as 00 00

I know this much that this is related to the byte padding. But how it works is rather beyond me at this point.

@Nick: I did, but OpenCV is a complex image mapping while I just need to be contented with how to
a) Read Bitmap Data
b) Devise an algorithm
After that I may look into OpenCV & the method it uses as I will then have my own viewpoint, rather than just blindly using functions.

Thanks.

>>But why does it exclude a value when it stores black(See: The red part) It is stored as 00 00

First why does what exclude it?
Second how are you reading in your image?
Are you throwing just random numbers out there, or is there more of that red
numbers in between the RGB?

It's just a trial run. I created a 32x32 image with Red background & Black box & opened it with a Binary Reader/Hex Editor. The 00 00 is part of Padding but I can't figure out when & how is it put.

Padding is done with 4 bit alignment. Here is how I calculated padding for a bitmap
image :

int padding =  (m_bmpInfo.imgWidth % 4);
if(padding != 0) padding = 4 - padding; //if its multiple of 4, then no padding else padding

Padding is done with 4 bit alignment. Here is how I calculated padding for a bitmap
image :

int padding =  (m_bmpInfo.imgWidth % 4);
if(padding != 0) padding = 4 - padding; //if its multiple of 4, then no padding else padding

But after how many bytes is padding introduced? There are 3 RGB values so after how many multiples of 3 will padding be prevalent.

You know if you haven't seen it, wiki has a article on it.
Padding is introduced, when you are done reading one image witdh. For example :

for(unsigned n = 0; n < m_bmpInfo.imgHeight; ++n){
	for(unsigned m = 0; m < m_bmpInfo.imgWidth; ++m){	
		//read in pixels
		imgFile.read( (char*) &rgb , sizeof(rgb) );
		std::swap(rgb.blue,rgb.red); 
		m_pixels.push_back( rgb );			
	}				
	imgFile.read(pad,padding); //read in padding	
}

Edited 6 Years Ago by firstPerson: n/a

You know if you haven't seen it, wiki has a article on it.
Padding is introduced, when you are done reading one image witdh. For example :

for(unsigned n = 0; n < m_bmpInfo.imgHeight; ++n){
	for(unsigned m = 0; m < m_bmpInfo.imgWidth; ++m){	
		//read in pixels
		imgFile.read( (char*) &rgb , sizeof(rgb) );
		std::swap(rgb.blue,rgb.red); 
		m_pixels.push_back( rgb );			
	}				
	imgFile.read(pad,padding); //read in padding	
}

I had seen it but could'nt make it out. Thanks I do now. Will try it.

This article has been dead for over six months. Start a new discussion instead.