[Solved] Colour Bitmap - Grayscale - Height value?

Started by
3 comments, last by Smit 17 years, 11 months ago
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]
Advertisement
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.
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.
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 Jackrhino
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.


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

Jonathan
I just haven't got around to loading 8bit bitmaps yet, just 24bit.

LowRad: Works perfectly. Thanks!

This topic is closed to new replies.

Advertisement