Jump to content
  • Advertisement
Sign in to follow this  
Smit

[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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
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 255
pHeightMap[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

Share this post


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

LowRad: Works perfectly. Thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!