Solved

Convert a 24bit video in a 8bit video ?

Posted on 1998-07-16
3
787 Views
Last Modified: 2012-06-27
I need to convert the format of the frames given by a digital camera, from 24 bits to 8 bits. So I can use them with
a Java applet. I tried the capGetVideoFormat and the capSetVideoFormat macros given by Visual C++ 5.0, but it doesn't work. How can I do?
0
Comment
Question by:jceline
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Expert Comment

by:Slarti
ID: 1167989
This might not totally answer you question since I am not familiar with video-capture functions, but I can tell you the algorithm for converting 24-bit to palletized (8-bit) color. Seeing as nobody has even left a comment yet although this question is getting old, this might be as good as you can get. However there may be a function which does that, and saves you the trouble of coding the algorithm. The algorithm is rather standard, but I don't think there is any Windows API which does it (I may be wrong).

In short, if you would accept such an answer, leave a comment to that effect. It is not a simple algorithm and I would hate to submit it and then have you fail it.
0
 

Author Comment

by:jceline
ID: 1167990
Thank you to answer me. I think I need to code it because I didn't find such a function and I'm in hurry...

0
 
LVL 2

Accepted Solution

by:
Slarti earned 200 total points
ID: 1167991
Let me state the problem more clearly: We have a 24-bit RGB picture, and we want to convert it to an 8-bit palettized picture. This means that, of the 16.7 million colors, we need to select 256 colors which are used most often, and use only those colors. Again, this is _not_ a simple process. You can get a feel for the complexity of the algorithm just by looking at the amount of time it takes a program like Photoshop to convert a single 24-bit picture to optimized 8-bit. This process has two stages:

1. Select the palette, i.e. the 256 colors which you will use. There are several ways of doing this, but a relatively simple method which gives pretty good results is as follows.
Look at the 24-bit color set as a three-dimensional space where the coordinates are R, G, B. Every pixel that is used has a certain value, represented as a point in this space. If, for example, this is a picture of the sky, the most of the points will be in the area of high B's and low R's and G's, so we want most of the palette to contain values with high B's and low R's and G's.
The way we do this is divide the 3-space into two separate sets, both of which have roughly the same number of points. We then say that the two sets shall each have 128 colors applied to them, and continue recursively into each of these sets, dividing them into four 64-color sets, and so on. Eventually we reach a very small set to which we need to assign just one color. This set might be, for example, the set R:23-25,G:10-14,B:11-12, in which case we can choose an average value of R:24,G:12,B:11 for the color which will be assigned to this set. So now we have 256 colors and we've assigned them in a fairly intelligent way, because X percent of the pixels in the picture will use up almost exactly X percent of the palette.

This is the most time-consumin part of the calculation. _IF_ this is too complicated for you, you could consider using a "fixed" palette: that is, choose the palette in advance, and go immediately to step 2. However, results will be much poorer. Most pictures with optimized palettes can be distinguished from true 24-bit color pictures only when looking closely at the details, whereas when you see a fixed-palette picture you will immediately recognize that it is lower-quality.

2. Convert all pixels to the nearest color in the palette. The "distance" between two colors can be defined pretty well as abs(r1-r2)+abs(g1-g2)+abs(b1-b2), where abs() is the absolute value function, and (r1,g1,b1) and (r2,g2,b2) are the two colors. What you do is, for a given pixel find the distance between that pixel and all colors in the palette. The color in the palette with minimum distance is the one you want for your pixel.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Better understanding on C++ Class serialization and formats 9 105
VS2015 Redefinition errors 4 104
Why  my code (program) build with old compiler? 11 146
Outlook 13 100
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question