image processing

Posted on 2006-04-18
Last Modified: 2010-04-01
Hi experts,

How do I convert an image to a matrix of numbers?

I have a image file image.bmp
I would like to convert it to a matrix of numbers,
say red = 255, lighter red = 252, white = 0........
I want to pixel the image into a matirx and then get a matrix of numbers.
Please show me some simple example codes that i can write

eg) int main( file image......)

Question by:oldb
    LVL 11

    Expert Comment

    You can simply read the whole data from the bmp file in one dimensional array. And since this is C language after that just index the array as two dimensional (matrix).

    Author Comment


    show me some example code
    LVL 11

    Expert Comment

    Try to write something by yourself (it's better this way) and post it here if it doesn't work.
    LVL 39

    Accepted Solution

    If you are on a Windows platform you should check the struct BITMAPINFO

    typedef struct tagBITMAPINFO { // bmi
        BITMAPINFOHEADER bmiHeader;
        RGBQUAD          bmiColors[1];

    which has a header and a variable number of RGB values. The biSize member of the header struct tells you the size of the bitmap (file).

    So, you might first read the header, get the size and read the rest to an appropriate buffer (you might allocate a properly sized array of RGBQUAD words).

    Regards, Alex

    Featured Post

    Live - One-on-One C++ Help from Top Experts

    Solve your toughest problems, fast.
    C++ experts are online now and ready to help you.

    Join & Write a Comment

    In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
    This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
    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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

    728 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

    24 Experts available now in Live!

    Get 1:1 Help Now