473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Image reading program

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
1 10708
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: PyPK | last post by:
Hi I am looking for a simple tiff Image reader/writer in python.Can anyone point me to the right one.
4
by: Csaba2000 | last post by:
I want to be able to programatically click on the center of an <INPUT type=image ...> element (I only care about IE 5.5+). This should work regardless of whether IE has focus. Normally you would...
4
by: Andy | last post by:
Hello All: I have a field in the database that is an Image. I have no idea how the data is stored in here (Image, compressed, encrypted, plain text, etc). I am trying to write the contents to...
3
by: dale zhang | last post by:
Hi, I am trying to read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp The article author is using PictureBox for windows...
2
by: Chucker | last post by:
Hi Community, I think I can store Binary Data in SQL Server but when I try to retrieve it, I always only get one byte. I think I stored my Binary Data in SQL Server in a Colum of Type Image....
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
3
by: Peter | last post by:
..NET 2.0 I have an Image on my form and I am trying to clear this image and re-load it with different image. Everything works fine, but once I load the image I can not delete this image until...
70
by: quickcur | last post by:
hi can anyone explain me to read image to memory from a url it is very easy in java but it is hard to find an complete solution in c/c++. Thanks,
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.