By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,419 Members | 1,080 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,419 IT Pros & Developers. It's quick & easy.

Image reading program

P: n/a
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][i];
}
}
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.

Mar 1 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
kh**************@gmail.com 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.
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-lit...t.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-lit...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-lit....html#faq-29.3.
{
unsigned char pixelvalues[pix][pix];
Prefer std::vector to raw arrays
(http://www.parashift.com/c++-faq-lit...html#faq-34.1). For
multidimensional vectors, see
http://www.parashift.com/c++-faq-lit...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][i];
}
}
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

Mar 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.