473,799 Members | 3,390 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>>pixel values[j][i];
}
}
rawimage.close( );

/*************** *****/
/* DISPLAY */
for(int m=0; m<pix; m++)
{
for(int n=0; n<pix; n++)
{
cout<<pixelvalu es[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 10734
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.compressio n, comp.dsp, or
sci.image.proce ssing 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
multidimensiona l 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>>pixel values[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<<pixelvalu es[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
10045
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
17257
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 do myDomElement.click and the mouse doesn't matter, but in the case of an input image element, what happens is the submitted url has something like "?x=12&y=7" appended to it (the numbers vary per mouse position on the clicked element). If you hit...
4
7626
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 a text file, image file, etc so I can see if the data is stored in a way we can understand (we have been tasked to write an app and the app needs to read this field, but we don't know what it really contains). How would I go about reading the...
3
3638
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 application, while I am doing for web. I can only find Image from web forms control and HTML control. This may be the root cause of my problem. For read button, I converted his VB to the C#. But the compiler complains:
2
3754
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. At least when I execute the following code, I get some significant network traffic. When I check the database with query analyzer, I see 4 Hex Chars in the image colum. Like 0xe0 etc.
4
2757
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. It should put a blue and yellow box on the page with "This is a test" as part of the picture. But what I get is a broken Gif. The other problem is that I can't view the source???? The view source is disabled for this page. What causes this?
3
9224
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 I close the program. How can I clear the image so I can delete it. Here's my code: string imgFileName = @"C:\myImage.jpg";
70
1059
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
10785
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 inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9543
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7567
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4144
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.