Solved

Convert a 24bit video in a 8bit video ?

Posted on 1998-07-16
3
756 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
  • 2
3 Comments
 
LVL 2

Expert Comment

by:Slarti
Comment Utility
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
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now