Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

bui.h File Reference

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

Go to the source code of this file.


Functions

void  cii (int m, int n, int init, int v, int ***pimg)
void  pii (int m, int n, int **img)
int  rii (const char *name, int *m, int *n, int ***img)
int  wii (const char *name, int m, int n, int **img)
void  pci (int b, int m, int n, int ***img)
void  rci (const char *name, int &b, int &m, int &n, int ****img)
int  ruci (char *name, int m, int n, int ***img)
void  wci (const char *name, int b, int m, int n, int ***img)
void  mpi (int b, int m, int n, int startRow, int startCol, int regionHeight, int regionWidth, int ***rgb_in, int ****rgb_out, int **img)
void  Alloc (int b, int m, int n, int ****img)
void  Alloc (int m, int n, int ***img)
void  deAlloc (int b, int m, int ***img)
void  deAlloc (int m, int **img)

Function Documentation

void Alloc ( int m,
int n,
int *** img )
 

Definition at line 464 of file bui.cc.

00467 {
00468   (*img) = new int*[m];
00469   for (int i=0; i<m; i++)
00470     {
00471       (*img)[i] = new int[n];
00472     }
00473 }

void Alloc ( int b,
int m,
int n,
int **** img )
 

void cii ( int m,
int n,
int init,
int v,
int *** pimg )
 

Definition at line 40 of file bui.cc.

Referenced by ruci().

00047 { int i,j;              //current pixel location
00048   //set up an pointer array for the rows
00049   (*pimg) = new int*[m];
00050 
00051   //set up space for each of the rows
00052      for (j = 0; j < m; j++)
00053           (*pimg)[j] = new int[n];
00054 
00055   //initialize?
00056   if(init)
00057     for (i = 0; i < m; i++)
00058       for (j = 0; j < n; j++)
00059         (*pimg)[i][j]=v;
00060 }

void deAlloc ( int m,
int ** img )
 

Definition at line 497 of file bui.cc.

00500 {
00501   //free allocated memory
00502   for (int i=0; i<m; i++)
00503     {
00504       delete img[i];
00505     }
00506   delete img;
00507 }

void deAlloc ( int b,
int m,
int *** img )
 

void mpi ( int b,
int m,
int n,
int startRow,
int startCol,
int regionHeight,
int regionWidth,
int *** rgb_in,
int **** rgb_out,
int ** img )
 

Definition at line 352 of file bui.cc.

00362 {
00363 
00364   int endRow = startRow + regionHeight;
00365   int endCol = startCol + regionWidth;
00366 
00367   //copy input image first
00368   for (int i=0; i<b; i++)
00369     {
00370       for (int j=0; j<m; j++)
00371     {
00372       for (int k=0; k<n; k++)
00373         {
00374           (*rgb_out)[i][j][k] = rgb_in[i][j][k];
00375         }
00376     }
00377     }
00378   
00379   //insert processed region
00380   for (int i=0; i<b; i++)
00381     {
00382       for (int j=startRow; j<endRow; j++)
00383     {
00384       for (int k=startCol; k<endCol; k++)
00385         {
00386           (*rgb_out)[i][j][k] = img[j][k];
00387         }
00388     }
00389     }
00390 }

void pci ( int b,
int m,
int n,
int *** img )
 

Definition at line 208 of file bui.cc.

00213 {
00214   //print out image
00215   for (int i=0; i<b; i++)
00216     { 
00217       for (int j=0; j<m; j++)
00218     {
00219       for (int k=0; k<n; k++)
00220         {
00221           cout << setw(4) << img[i][j][k];
00222         }
00223       cout << endl;
00224     }
00225       cout << endl;
00226     }
00227 }

void pii ( int m,
int n,
int ** img )
 

Definition at line 72 of file bui.cc.

00076 { int i,j;              //current pixel location
00077 
00078   //print out image
00079   cout<<endl;
00080   for (i = 0; i < m; i++)
00081     { 
00082       for (j = 0; j < n; j++)
00083     cout << setw(4) << img[i][j];
00084       cout<<endl;
00085     }
00086   cout<<endl;
00087 }

void rci ( const char * name,
int & b,
int & m,
int & n,
int **** img )
 

Definition at line 234 of file bui.cc.

00240 {
00241   int v;                //the pixel type data of the input image;
00242 
00243   //open the input stream for reading
00244   ifstream in(name);
00245 
00246   //check that the input stream is now open
00247   if (!in)
00248   { 
00249     cerr << "ERROR: the image file " << name
00250      << " could not be opened for reading\n";
00251     exit(1);          //exit with error
00252   }
00253 
00254   //input image header
00255   in >> v;
00256   in >> b;
00257   in >> m;
00258   in >> n;
00259 
00260   //check that the type of image date is integer
00261   if (v != 3)
00262   { 
00263     cerr << "ERROR: the image file " << name
00264      << " did not have integer valued data\n";
00265     exit(1);            //exit with error
00266   }
00267 
00268   //allocate memory for an image
00269   (*img) = new int**[b];
00270   for (int i=0; i<b; i++)
00271     {
00272       (*img)[i] = new int*[m];
00273       for (int j=0; j<m; j++)
00274     {
00275       (*img)[i][j] = new int[n];
00276     }
00277     }
00278 
00279   //read the image
00280   for (int i=0; i<b; i++)
00281     {
00282       for (int j=0; j<m; j++)
00283     {
00284       for (int k=0; k<n; k++)
00285         {
00286           in >> (*img)[i][j][k];
00287         }
00288     }
00289     }
00290   
00291 
00292   //close the input stream
00293   in.close();
00294 
00295   //It is calling module's responsbility to free the allocated memory
00296 }

int rii ( const char * name,
int * m,
int * n,
int *** img )
 

Definition at line 102 of file bui.cc.

00107 { int i,j;              //the current pixel location being output
00108   int v;                //the pixel type data of the input image;
00109 
00110   //open the input stream for reading
00111   ifstream in(name);
00112 
00113   //check that the input stream is now open
00114   if (!in)
00115   { cerr<<"ERROR: the image file "<<name
00116       <<" could not be opened for reading\n";
00117     exit(1);          //exit with error
00118   }
00119 
00120   //input image header
00121   in>>v;
00122   in>>(*m);
00123   in>>(*n);
00124 
00125   //check that the type of image date is integer
00126   if(v!=3)
00127   { cerr<<"ERROR: the image file "<<name
00128       <<"did not have integer valued data\n";
00129     exit(1);            //exit with error
00130   }
00131 
00132   //input the image
00133   (*img) = new int*[(*m)];
00134   for(i=0;i<*m;i++)
00135     {
00136       (*img)[i] = new int[(*n)];
00137       for (j=0;j<*n;j++)
00138     {
00139       in>>(*img)[i][j];
00140     }
00141     }
00142 
00143 /*  //check that the image size was correct
00144   if(!in.eof())
00145   { cerr<<"ERROR: the image file "<<name
00146       <<"did not have the correct amount of data\n";
00147     exit(1);            //exit with error
00148   }
00149 */
00150   
00151   //close the input stream
00152   in.close();
00153 
00154   return(0);          //finished successfully
00155 }

int ruci ( char * name,
int m,
int n,
int *** img )
 

Definition at line 405 of file bui.cc.

00410 { int i,j;              //the current pixel location being output
00411 
00412   FILE *infile;
00413   //check that the file if is now open
00414   if ((infile = fopen(name, "r")) == NULL)
00415   {
00416      fprintf(stderr, "Cannot open %s\n", name);
00417      //exit(1);
00418   }                 //exit with error
00419 
00420   unsigned ch;
00421   //input the image
00422    cii(m,n,0,0,img);         //create a integer array for int image
00423 
00424   for(i=0;i<m;i++)
00425     {
00426       for (j=0;j<n;j++)
00427     {
00428     fscanf(infile,"%c",&ch);
00429     (*img)[i][j]=ch;
00430     }
00431     }
00432 
00433 
00434   //close the input stream
00435   fclose(infile);
00436 
00437   return(0);          //finished successfully
00438 }

void wci ( const char * name,
int b,
int m,
int n,
int *** img )
 

Definition at line 303 of file bui.cc.

00309 {
00310   //open the output stream for writing
00311   ofstream out(name);
00312 
00313   //check that the output stream is now open
00314   if (!out) 
00315   { 
00316     cerr << "ERROR: the image file " << name
00317      << " could not be opened for writing\n";
00318     exit(1);          //exit with error
00319   }
00320 
00321   //output image header
00322   out << 3 << endl;         //3 -> image is of integer type
00323   out << b << endl;         //output # bands
00324   out << m << endl;         //output # rows
00325   out << n << endl << endl; //output # cols
00326 
00327   //output the image
00328   for(int i=0; i<b; i++)    //start outputing pixels
00329     { 
00330       for (int j=0; j<m; j++)
00331     {
00332       for (int k=0; k<n; k++)
00333         {
00334           out << img[i][j][k] << " ";
00335         }
00336       out << endl;   //put in an end of line after each row of image
00337     }
00338       out << endl;       //put in an end of line after each band of image
00339     }
00340   
00341   //close the output stream
00342   out.close();
00343 
00344 }

int wii ( const char * name,
int m,
int n,
int ** img )
 

Definition at line 163 of file bui.cc.

00168 { int i,j;            //the current pixel location being output
00169 
00170   //open the output stream for writing
00171   ofstream out(name);
00172 
00173   //check that the output stream is now open
00174   if (!out) 
00175   { cerr<<"ERROR: the image file "<<name
00176       <<" could not be opened for writing\n";
00177     exit(1);          //exit with error
00178   }
00179 
00180   //output image header
00181   out<<3<<endl;       //3 -> image is of integer type
00182   out<<m<<endl;       //output # rows
00183   out<<n<<endl;       //output # cols
00184 
00185   //output the image
00186   for(i=0;i<m;i++)    //start outputing pixels
00187     { 
00188       for (j=0;j<n;j++)
00189     out <<img[i][j]<<" ";
00190       out<<endl;        //put in an end of line after each row of image
00191     }
00192   out << endl;
00193   
00194   //close the output stream
00195   out.close();
00196 
00197   return(0);          //finished successfully
00198 }

Generated at Sun Mar 28 00:08:08 2004 for OSSIM - Open Source Image Map by doxygen1.2.6 written by , © 1997-2001