LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Does anyone know how to change a 24-bit bitmap to an 8-bit bitmap in LabVIEW?

I need to do a LabVIEW program that changes a 24-bit bitmap to an 8-bit bitmap. If there is a way to perform this task, please let me know.
0 Kudos
Message 1 of 15
(9,202 Views)
Are you sure? Why do you want to convert a 24 bit BMP to an eight bit BMP?

As you probably know - a 24 bit BMP pixel can be any of 16.7 million colours, an 8 bit BMP pixel can only be one of 256 colours.

There are no LabVIEW functions to convert between colour depths (bit depths) - you have to write your own routine.

It's quite easy to convert an 8 bit file to 24 bit format (although the image will look exactly the same), but it's a bit more work involved to convert down from 24 bit to 8 bit (and the image will most probably appear quite inferior too).
Message 2 of 15
(9,190 Views)
Since a 24-bit image has three bytes, Red, Green, and Blue the magnitude obviously can't be used to find an equivalent 8-bit representation. But the following site provides this equation to convert to grayscale, which is what you are trying to do.

Y = 0.3R + 0.59G + 0.11B

Where Y is the resulting value, R is the value of the Red byte, B for Blue byte, G for Green byte which is also the order of the bytes you are starting with (hence RGB). The details for why are found here.

http://gimp-savvy.com/BOOK/index.html?node54.html
Randall Pursley
Message 3 of 15
(9,184 Views)
I can also think of at least one pure LV use case - the PDA module only supports 8 bit color even though most devices support 16 bit color (I assume this is because there was no easy way to introduce 16 bit support into the picture VIs). There probably are other good reasons for wanting this.

___________________
Try to take over the world!
Message 4 of 15
(9,178 Views)
I don't think Argon said anything about converting to grey scale.

The 8 bit colour format uses a 256 colour palette (look up table). The colour palette contains 24 bit RGB values, but only 256 of them. The trick of converting from 24 to 8 bit format requires a palette to be created that best covers the full R,G,B gamut range using just 256 colours, then each pixels 24 bit colour value has to be replaced with an index into the 8 bit's 256 colour table, the indexed colour being the closest match to the original 24 bit colour.

I might have a go at this later, if I have any spare time.
Message 5 of 15
(9,166 Views)
Well, then it is trivial to take the upper byte of the 24-bit number and that is your scaled 8-bit number.
Randall Pursley
Message 6 of 15
(9,134 Views)
" Well, then it is trivial to take the upper byte of the 24-bit number and that is your scaled 8-bit number"

No, as far as I know it's not as simple as that.

24-bit colours are not stored as "normal" 24 bit numbers but are rather better thought of as clusters of 3 8-byte values, one each for Red, Green and Blue. Taking the upper byte of such a 24-bit number will basically give you one of the three colours. Your final picture will look different.

The skill in transferring 24-bit to 8-bit is deciding what pallette of 256 colours best represents the full range of 16.7 million colours possible in a 24-bit picture. Of course, if the original 24-bit picture actually only has 256 or less colours, then the conversion should be much easier.....

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 7 of 15
(9,129 Views)
Only if it is in RGB format, as I mentioned in a earlier response. If it is a straight 24-bit magnitude representation then my second response is correct.
Randall Pursley
Message 8 of 15
(9,119 Views)
Ah, you mean 24-bit monochrome.

Didn't catch that at all. I'm assuming it's in RGB format since these pictures are (AFAIK) more common.

Then you're correct, I agree. You mentioned yourself in your first post that a 24-bit pixel is componsed of three 8-bit numbers, and no-one mentioned monochrome. Hence the misunderstanding.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 9 of 15
(9,115 Views)
I assumed RGB at first, but I guess it doesn't have to be. The equation I showed in the first response (per the referenced web site) converts the RGB to Luminance (i.e. grayscale) and then you can apply any color palatte that is desired.
Randall Pursley
Message 10 of 15
(9,112 Views)