Reading rgb data in picture file


I need r,g,b data in a matrix format for each of the pixels in a picture file such as bmp, jpeg, tiff etc. How can I get that?

I am actually a Fortran programmer, but Fortran cannot do this. So I thought somebody in C++ forum may help me since C++ can access this data. If I could get a small windows executable that takes a picture file name and output rgb in some format like
nx, ny, r, g, b
that would be wonderful. I actually need this for my employer, so I could compensate you for the effort. However, payment may turn out to be problematic since I would need to write a PO.

I apologize for posting in a forum meant for C++ programmers, but I am somewhat helpless in this effort.
When you say matrix format, what exactly do you mean?
Are you looking to get the RGB triples for each pixel?
And is your goal to have a program that reads standard graphics formats and converts the data into a stream of RGB triples?
Since each file format is different, that's not a small order. And some formats are proprietary.
If money is not an issue, you can buy off the shelf software that will convert from one format to another.
I wouldn't mind helping out for one or two file formats, but that would be the extent of it.
Another issue is that many images might not consist of RGB data. Some images are composes of indexes into a color map or are black and white.
All of the above can be converted into RGB triples, but you need to specify exactly what your requirements are.
Yamex, Thanks for the offer.

Any format will be fine. If it is ok, let us pick jpeg. So say I need a program which is given the jpeg file name on command line. Then it reads all the pixels in the jpeg file. Each pixel contains r,g and b data which I need. The pixels must be arranged in x and y format in the picture where say nx is count of x location and ny is count of y loctaion. The executable outputs a data file which contains information on all the pixels, one pixel per line in a format such as
nx, ny, r, g, b
Here nx and ny will give the location information of the pixel and r, g and b the color information.

This is just a suggested format. Some other output method that lets me figure out the pixel location and color will also work. I can then read it using my Fortran file.
Let us not worry about images that do not have r,g,b data. A program that works on color jpeg files will be enough for me.

For example, the executable is called readrgb
C:>readrgb pic
reads pic.jpg and outputs pic.txt which contains the output.

Thanks again for the generous offer.
Last edited on
The JPEG standard is not free, so unless you purchase it, I don't think that that's a good place to start. PNG is free, if your okay with that.
No problem, yamex.

I will be happy with PNG also. The only reason I picked JPEG is because the camera generates JPEG files. I thought reading JPEG would also be free, just creating them would take a license. But you probably know much more than I do. Reading a PNG will require me to convert JPEG to PNG and then read. But that is fine.

Thanks for your continued interest in helping me.
AFAIK there is no cost to reading jpeg files, but I would still recommend against using them because they are compressed which will make them difficult to work with (without a library). Reading bmp files is pretty easy and there is a ton of documentation and examples on the net.
Last edited on
BMP files would also be no problem for me. Converting from one to another format is pretty simple anyway.

Will you please tell me if you are still planning to help or if you have lost interest.

I would help you but I wonder if text output is necessary or can you read binary files?

Thanks for the offer. I do not think I could read a binary file in Fortran. Would writing a text file be too much of a problem for you?


Looks like this was an exercise in futility. Nobody actually helped me get the code. Finally, I located somebody who for a nominal amount is writing the code for me. Your discussions were helpful, so I am happy. Thanks for your suggestions.
Topic archived. No new replies allowed.