How can I read a 8 bit gray image using c ?

Discussion in 'C Programming' started by guassian, Mar 13, 2006.

  1. guassian

    guassian Guest

    Hi,
    I am new to C programming.
    Is there way to read a 8 bit gray image using C language?
    Thanks and best regrads,
    Raj
    guassian, Mar 13, 2006
    #1
    1. Advertising

  2. guassian said:

    > Hi,
    > I am new to C programming.
    > Is there way to read a 8 bit gray image using C language?


    Presumably the image is stored in a file of some kind, so you can open the
    file using fopen, and then (only if that operation succeeded) you can read
    the image data using fread. Don't forget to fclose the file when you're
    done.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
    Richard Heathfield, Mar 13, 2006
    #2
    1. Advertising

  3. guassian

    guassian Guest

    Thanks for the immediate reply.

    Can that will give the pixels values in the matrix form?
    I just want to relate the situation with the imread command
    of the maltab. If you use this syntax in matlab

    >>a=imread('test1.jpg');


    This yields a matrix a having the dimension of the image
    with the matrix element to be pixel value.


    Please suggest.
    Raj
    guassian, Mar 13, 2006
    #3
  4. guassian wrote:
    > Can that will give the pixels values in the matrix form?


    Can what give values in the matrix form?

    Please read <http://cfaj.freeshell.org/google/> before posting anything
    further.

    > I just want to relate the situation with the imread command
    > of the maltab. If you use this syntax in matlab
    >
    > >>a=imread('test1.jpg');

    >
    > This yields a matrix a having the dimension of the image
    > with the matrix element to be pixel value.


    There certainly is a way to achieve such functionality (otherwise it
    wouldn't be available in Matlab). If you're looking for ready made code
    to do that for you, you're in the wrong place (e.g., try
    comp.sources.wanted). If you're looking for hints how to decode JPEG
    encoded images, you've got the wrong address again (you could try
    comp.programming, or better yet a group dealing in graphics formats).

    If, however, you give it a go first, and encounter problems that you
    believe are C-specific (as in ISO Standard C), come back here, post a
    minimal compilable example and a good description of your problem, and
    soon enough someone will come along to help.

    --
    BR, Vladimir
    Vladimir S. Oka, Mar 13, 2006
    #4
  5. On 2006-03-13, guassian <> wrote:
    > Hi,
    > I am new to C programming.
    > Is there way to read a 8 bit gray image using C language?
    > Thanks and best regrads,
    > Raj
    >


    Almost certainly it will depend on the file format : they are all
    different. The fact that you mention it being 8 bit and grey suggests
    you then want to do something with that data.

    You have fopen() to read sequence of characters. There are many
    examples of fopen() available on the internet.

    The formats are varied and you need to find the relevant templates if
    you wish to do anything with them other than "pass on the info" or
    resave under a different name (even then you must be careful with JPG
    because of image compression issues if you save a JPEG save routine).

    http://www.library.cornell.edu/preservation/tutorial/presentation/table7-1.html

    is a good start.


    Good luck : there is little more fun than image manipulation in a
    high/low level language as C
    Richard G. Riley, Mar 13, 2006
    #5
  6. On 2006-03-13, Richard G. Riley <> wrote:
    >
    > You have fopen() *and fread* to read sequence of characters. There are many
    > examples of fopen() available on the internet.


    slight clarification.
    Richard G. Riley, Mar 13, 2006
    #6
  7. guassian

    Ben C Guest

    On 2006-03-13, guassian <> wrote:
    > Thanks for the immediate reply.
    >
    > Can that will give the pixels values in the matrix form?
    > I just want to relate the situation with the imread command
    > of the maltab. If you use this syntax in matlab
    >
    >>>a=imread('test1.jpg');

    >
    > This yields a matrix a having the dimension of the image
    > with the matrix element to be pixel value.
    >
    >
    > Please suggest.
    > Raj


    You can't do it with a one-liner the way you can in Matlab.

    If you need to read jpg or png files, you'll need to use libjpg or
    libpng and read the docs.

    Probably easier is to convert the files first to ppm, xpm or xbm (using
    ImageMagick for example) and then just either write the parser yourself
    in C because it will be fairly simple for these formats or find some
    sources to do it.

    xpm files can actually themselves be compiled as C files. Look at one
    and you'll see what I mean.
    Ben C, Mar 13, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leo Duran
    Replies:
    0
    Views:
    895
    Leo Duran
    Aug 6, 2003
  2. Oleg Ogurok
    Replies:
    0
    Views:
    778
    Oleg Ogurok
    Jan 27, 2005
  3. John Salerno
    Replies:
    9
    Views:
    738
    Neredbojias
    Feb 7, 2006
  4. Dev S Shrestha
    Replies:
    1
    Views:
    704
    Thomas Matthews
    Nov 11, 2003
  5. Replies:
    3
    Views:
    1,752
    Timothy Bendfelt
    Jan 19, 2007
Loading...

Share This Page