Extracting RGB info from a jpeg

Jul 3, 2012 at 5:07pm
Hello, I'm a C++ beginner stuck on something I think may be easy.
I'm trying to write a program that uses a button to open a folder, displays the files inside that folder(which happen to be jpegs) and then allows you to select the files inside the folder. Then I want it to extract the RGB components of the jpegs. I have no idea how to extract the RGB component of a picture and none of the examples I've looked up have helped. Do any of you know of a way I could do this without downloading anything? I'm using visual C++ by the way. Thanks
Last edited on Jul 3, 2012 at 5:41pm
Jul 3, 2012 at 6:23pm
Decompressing jpeg files is very complex, and trying to do it without a library is a little ridiculous.

That's not to say it can't be done. It can certainly be done and it might even be a good experimental/education project. But it won't be easy.

If you're serious about it, google around for a technical doc that outlines the .jpeg file format. Get ready for some very dense reading.


Or if you don't really care about how jpegs are stored and just want your program to be able to read them -- do yourself a favor and just use an existing library. There are dozens available. One I know of is called "SOIL" but I've only heard of it being used with OpenGL.
Jul 3, 2012 at 6:29pm
Do any of you know of a way I could do this without downloading anything?

... Yes... read mountains of technical documents so that you get your JPEG decoder right.
I didn't call it JPEG "loader" because that would imply you simply load chunks of data and be done with it -- this isn't the case.

I suggest you try to use a pre-made library, unless of course implementing your own JPEG decoder is a project goal itself.

http://en.wikipedia.org/wiki/JPEG
http://en.wikipedia.org/wiki/Libjpeg

Edit: A wild Disch out of nowhere!
Last edited on Jul 3, 2012 at 6:31pm
Jul 3, 2012 at 6:39pm
Ah ok... Thanks for the replies, I'm trying to find a library now.
Jul 3, 2012 at 6:51pm
I'm going to push CImg again. The code I peddled in this thread

http://www.cplusplus.com/forum/general/71630/

will probably work without any change at all but for the name of the input file.
Jul 3, 2012 at 8:02pm
And I'm going to suggest opencv
1
2
3
4
5
6
7
8
9
#include <opencv2/opencv.hpp>
#include <vector>

int main(int argc, char **argv){
   cv::Mat image = cv::imread(argv[1], CV_LOAD_IMAGE_COLOR);
   std::vector<cv::Mat> channels;
   cv::split( image, channels );  //bgr
//...
}
Topic archived. No new replies allowed.