Public Group

# [Solved] Colour Bitmap - Grayscale - Height value?

This topic is 4600 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've got a 24bit bitmap which I load into a byte array. So now I have a byte array of size width * height * 3 in BGR order. I try to convert this to grayscale pixel value like so (BGR order):
m_pHeightMap[j] = pTemp/0.114f + pTemp[i+1]/0.587f + pTemp[i+2]/0.299f;

And then I want to get a height value between 0.0f and 1.0f. I'm probably doing the grayscale completly wrong though. How can I convert the BGR data into grayscale and then into a height value? Thanks! [Edited by - Smit on May 9, 2006 3:34:09 AM]

##### Share on other sites
why don't u just make a 24 bit number with the bgr and put it into integer, then u have a height to use. like r maybe lowest 8 bit, g the middle 8 bit and b the highest 8 bit. Then u just have to scale normalise it.

##### Share on other sites
Instead of dividing, you must multiply by each of those constants.

e.g. pTemp*0.114f + etc...

This is assuming that your problem is the output color, and not some other issue.

But anyway, doing it the way jack said is more efficient, and you get more data in the same space. Unless you have source images that have to be in rgb, you are better off just creating your images using one color channel, and reading that directly.

##### Share on other sites
I might be wrong, but the equation seems false to me...

It should be:
// this give a grayscale value between 0 and 255pHeightMap[j] = pTemp*0.114f + pTemp[i+1]*0.587f + pTemp[i+2]*0.299f; // Convert the value to the [0,1] range (dont forget to cast to float!!pHeightMap[j] = pHeightMap[j] / 255.0f;

Like i said, im not sure, but its looking better ;)

If you are doing a terrain engine, why not use a 8bit grayscale heightmap instead?

Quote:
 Original post by Jackrhinowhy don't u just make a 24 bit number with the bgr and put it into integer, then u have a height to use. like r maybe lowest 8 bit, g the middle 8 bit and b the highest 8 bit. Then u just have to scale normalise it.

Im not sure why he is doing this like that, but this equation is based upon human color perception.

Jonathan

##### Share on other sites
I just haven't got around to loading 8bit bitmaps yet, just 24bit.

1. 1
2. 2
3. 3
Rutin
14
4. 4
5. 5
khawk
11

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633671
• Total Posts
3013266
×