24-bit bmp to 8-bit bmp image conversion

Started by
8 comments, last by Alberth 7 years, 4 months ago

Hello All,

I have read a topic on this forum about the conversion from 24 bit to 16 bit bmp image. And it is very informative.

I want to know about how a 24 bit bmp image is converted to 8 bit (3R - 3G - 2B) bmp color image. @big

Please Do Reply.
Thank You.

Advertisement

Usually, "8bit image" means paletted image, while you seem to suggest blindly discarding 16 bits instead.

Do you mean to make a paletted image?

If so, construct a palette of 256 entries, with your colours, then convert the image to the palette indices.

Your method is not so difficult, but it may give bad quality, in some cases.

Have you already read about 8bit paletted images?

What part are you stuck on?

Thanx for reply.

Yes, i m talking about pelleted image.
but my task is to read 24 bit bmp image and then convert it to 8bit bmp.

As a reference i have converted one image from paint (windows) , and studied color table of it.


but i am not able to decode that algorithm by which it take color of 24 bit then decide its particular range and index it accordingly.

so ,
can you please provide me what the color table shoud be and how to index color of 24 bit image as input file and get 8 bit color image.


Usually, "8bit image" means paletted image, while you seem to suggest blindly discarding 16 bits instead.

Do you mean to make a paletted image?

If so, construct a palette of 256 entries, with your colours, then convert the image to the palette indices.

Your method is not so difficult, but it may give bad quality, in some cases.

Have you already read about 8bit paletted images?

What part are you stuck on?

Thank you for your reply.
But please guide me for this que.
and if you can spend some of your valuable time to describe this scenario is would very appreciable.


This forum is for learning how to program, in particular games. If you want to learn to program, you're welcome. If you just want a solution, sorry, but you're at the wrong site, we don't give solutions.

For programming your problem, I would suggest you start with understanding what "(3R - 3G - 2B)" exactly means. Can you tell us? If not, try to figure it out, then tell us.

This forum is for learning how to program, in particular games. If you want to learn to program, you're welcome. If you just want a solution, sorry, but you're at the wrong site, we don't give solutions.

For programming your problem, I would suggest you start with understanding what "(3R - 3G - 2B)" exactly means. Can you tell us? If not, try to figure it out, then tell us.

Yes i know what it means.

It means, if size of the pixel is 8 bit then first 3 bit stands for red, next 3 for green and rest are for blue.

i am trying to develop a program for conversion.
so if you can help by making me understand how things happens or you can straight away help me with c code.
thank you

The simple way would be to find all unique colors in the original image and their counts.

Now you have a nice distributed data blob of three axes (R,G,B) with weights.
While the count of unique data points is higher than 256 find the two points that are closest to each other and collapse them.
There's countless ways to decide if two data points are "near" each other; It all depends what you value more.
Once you have the number of data points down you have a mapping from original color to 256 colors. That's your resulting palette.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

The simple way would be to find all unique colors in the original image and their counts.

Now you have a nice distributed data blob of three axes (R,G,B) with weights.
While the count of unique data points is higher than 256 find the two points that are closest to each other and collapse them.
There's countless ways to decide if two data points are "near" each other; It all depends what you value more.
Once you have the number of data points down you have a mapping from original color to 256 colors. That's your resulting palette.

can you help us with c code?
or some more information , because i m getting what to do but not getting how to do

3 bit stands for red

Ok, that would give you 2^3 = 8 different red colours, right?

In a 24bit image, you have 8 bit red, ie 256 colours.

So how would you reduce 256 red colours to 8?

Now 256 is a bit large, make it easier, say 15 colours, from high intensity to lo intensity red. Reduce it to 5 colours, Make a table of length 15, where each value is a colur of the 5.

Edit: If that's too large, go from 2 colours to 1 colour, then from 3 colours to 1 colour

Can you see a general pattern you can apply to the big table?

3 bit stands for red

Ok, that would give you 2^3 = 8 different red colours, right?

In a 24bit image, you have 8 bit red, ie 256 colours.

So how would you reduce 256 red colours to 8?

Now 256 is a bit large, make it easier, say 15 colours, from high intensity to lo intensity red. Reduce it to 5 colours, Make a table of length 15, where each value is a colur of the 5.

if we have 8 bit of red then by just shifting it right side for 5 times we can get 3 bit color.
here we are shifting right because we have to contain MSbs as they containing highest values.

Ok, so you know how to do it for red, the other colours should not be a problem.

What stops you from doing the conversion?

Edit: If it is colour mapping, try the colour conversion above, or consider 4 -> 2 colours

Input colour values (for red, for example)

0x00 (0)

0x40 (64)

0x7F (127)

0xC0 (192)

0xFF (255)

become 2 colours

0

1

What 'red' values (from 0 to 255) are good to use for colour 0 and colour 1 here?

How do you compute these from the above 4 colour values?

This topic is closed to new replies.

Advertisement