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

G

guassian

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
 
R

Richard Heathfield

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.
 
G

guassian

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

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


Please suggest.
Raj
 
V

Vladimir S. Oka

guassian said:
Can that will give the pixels values in the matrix form?

Can what give 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


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.
 
R

Richard G. Riley

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
 
B

Ben C

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


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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,500
Latest member
ArianneJsb

Latest Threads

Top