Re: Image reading program

khaleel.alyasini@xxxxxxxxx wrote:
Hello sirs & madams,

I'm currently working on DCT compression algorithm as my project. My
knowledge on C++ and DSP is rather weak/moderate. I was wondering if
any could help me and teach me the guidelines of DCT image compression.
Basically, this is my coding in C++ on extracting pixels values from a
RAW image file. It has errors, anyone could help me?

Nitpicking, but the .h headers suggest C or a very old C++ compiler.

#include <iostream.h>
#include <stdio.h>
#include <math.h>
#include <fstream.h>
#include <conio.h>
#include <malloc.h>
#include <iomanip.h>

#define pix 256
int v[pix][pix];

void main()
unsigned char pixelvalues[pix][pix];

/* READ */

ifstream rawimage("lena.raw");
cerr<<"Error in reading file\n";

for(int i=0; i<pix; i++)
for(int j=0; j<pix; j++)

for(int m=0; m<pix; m++)
for(int n=0; n<pix; n++)
cout<<pixelvalues[n][m]<<" ";

by the way, when i run this program, the output shows the values in
unsigned char, how to convert to decimal values in C++? anyway, what's
the next step in image compression by using DCT algorithm?

Sci.image.processing for the image processing part.

In these situations, my advice is always to create yourself a little
toolkit; maybe your time is short, but it will pay off. In fact, the
chance of you achieving anything the way you are going is slim. With
the toolkit you can divide up the problem; as it is, the required
program is large and complex and too difficult to think about and/or
implement and test in bits.

And you'll learn nothing.

If you can do it in C++, create a very simple Image class. Represent
the image as double or float; use set(value, row, col) to write; use
double get(row, col) to read. You probably need utility stuff like max,
min; and a constructor which creates an image and sets all pixels to

If you are in a big hurry, you might even get away with a
representation like


double image[MAXNR][MAXNC];

Then I would write a 'print' that prints to a stream.

And maybe a 'print' that prints to a simple graphics file format like
PGM; that gives you a method of display.

Maybe someone can suggest a lightweight image processing toolkit / API
that you can use.

A DCT shouldn't be hard to find.

Best regards,

Jon C.