Image reading program

  • Thread starter khaleel.alyasini
  • Start date
K

khaleel.alyasini

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?


#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");
if(!rawimage)
{
cerr<<"Error in reading file\n";
}

for(int i=0; i<pix; i++)
{
for(int j=0; j<pix; j++)
{
rawimage>>pixelvalues[j];
}
}
rawimage.close();

/********************/
/* DISPLAY */
for(int m=0; m<pix; m++)
{
for(int n=0; n<pix; n++)
{
cout<<pixelvalues[n][m]<<" ";
}
cout<<"\n";
}
}

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?

thanks in advance,
Khaleel alyasini
Final year student of KUTKM, Malaysia.
Electronic & Computer Engineering.
 
M

mlimber

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.

The DCT is off-topic here, where we concentrate on the C++ language and
libraries rather than specific applications of that language. See the
FAQ for what is on-topic:

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9

I'd recommend you try comp.compression, comp.dsp, or
sci.image.processing for details on the DCT. Also, remember that Google
is your friend.
Basically, this is my coding in C++ on extracting pixels values from a
RAW image file. It has errors, anyone could help me?


#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>

I reordered your includes for the purposes of my comments.

These three have been deprecated. Use <iostream>, <fstream>, and
<iomanip> instead. These headers may require that you add this line (or
use explicit namespace qualification):

using namespace std;
#include <stdio.h>
#include <math.h>
#include <malloc.h>

None of these are used.
#include <conio.h>

Non-standard and thus off-topic here. See the aforementioned FAQ.
#define pix 256

Prefer const to #define
(http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.7). If you
must use #define, use all upper-case macro names.
int v[pix][pix];

Unused and global. Both no-nos.
void main()

int main()

See http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.3.
{
unsigned char pixelvalues[pix][pix];

Prefer std::vector to raw arrays
(http://www.parashift.com/c++-faq-lite/containers.html#faq-34.1). For
multidimensional vectors, see
http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.17.
/********************/
/* READ */

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

Good, you checked for an error in opening the file, but if the open
fails, you just continue on! You probably meant to return on error.
for(int i=0; i<pix; i++)
{
for(int j=0; j<pix; j++)
{
rawimage>>pixelvalues[j];
}
}


This may or may not work, depending on the file format. I suspect you
probably want to open the file in binary mode and then use
ifstream::read rather than this for loop with the extraction operator.
rawimage.close();

Closing is not strictly necessary since the destructor will do it for
you.
/********************/
/* DISPLAY */
for(int m=0; m<pix; m++)
{
for(int n=0; n<pix; n++)
{
cout<<pixelvalues[n][m]<<" ";
}
cout<<"\n";
}
}

by the way, when i run this program, the output shows the values in
unsigned char, how to convert to decimal values in C++?

cout << int( pixelvalues[n][m] ) << ' ';
anyway, what's
the next step in image compression by using DCT algorithm?

Off-topic, as above. However, I'd suggest that your algorithm should
basically be: read, transform, compress, encode, write.

Cheers! --M
 

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

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,115
Latest member
JoshuaMoul
Top