Hi!
I have a program I'm working on for class (CSC 150). I have to read a pgm file into an array, copy it to a second array, manipulate the image and then output to a second file.

I'm having a heck of a time figuring out how to do the actual manipulation. The simplest of these is as follows:
................
Emboss Operation
The emboss operation takes the pixel at the lower right and subtracts the center pixel, then adds the value 8. If the result is < 0 the final result is 0. If the result is > 15, the result is 15. You must do this for every pixel that does not lie on the border.
i.e. -3 goes to 0, 18 goes to 15

Original data O (this is in a grid) Modified data M
collumns
rows a b c
d e f e
g h i


M(e) = O( i ) – O( e ) + 8
................

I have no idea how to express this. It seems I would have to start with the bottom right number in the file and work my way up (somehow). Any help would be very much appreciated!

Hello Ms. Christina,

Let me first say that I have never done any work with .pgm files. I've just looked at some .pgm examples though, and it doesn't look too terribly difficult. However, I think we might have to put our brains together to come up with the result that ye' be looking for.

With that said, I am unclear when it comes to "subtracting the lower right and subtracts the center pixel." If you can provide me a notepad example of a .pgm file, and show me what it means to perform the subtraction, I am sure I can help you on the file I/O, array and pixel manipulation.

-Dave W.

Comments
Fab! Thx!

Thank you Dave!

Here is a snippet of the txt version of the pgm file. I don't mean to be pedantic, I don't know what you know about pgm files, not that I don't know much :)) // comments

I have to read in the first three lines individually(which I have done, so the file is not corrupt), but the body of the image has to be read into an int array. I gather that some sort of string would be in order, as it would read the entire line & preserve the spaces.

Looking at the directions, I can see where it is ambiguous. Basically, you start with a pixel value(x), look up & over one(value = y). then x- y +8 = final result. It's described as; M(e) = O( i ) – O( e ) + 8. M is the manipulated value O is the original.

You should see the other formulae! This is the simplest. I'm going to attach the code I have thus far, so you can appreciate it in situ (and all its glory!). Perhaps you can help with the reading in, because I get trash out!

Thank you very much for your help!!

P2 // this is the "magic number"
256 256 //resolution (colls/rows)
15 // degree of white (0 = black, 15 = white)
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 1 1 1 3 3 2 3 3 3 4 4 4 4 5 5 5 4 5 5 6 6 7 6 6 7 8 6 8 9 8 8 7 8 9 9 9 10 10 10 10 11 12 11 10 11 12 12 13 13 12 12 13 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 13 14 13 13 14 13 13 13 13 14 13 13 13 13 13 13 13 13 12 13 13 13 13 13 14 13 13 13 14 13 14 13 13 13 14 14 14 14 13 13 14 13 13 13 14 13 13 14 13 14 13 13 13 13 13 14 13 11 12 12 13 13 14 14 14 15 13 14 14 14 14 14 14 14 14 14 14 14 13 13 14 14 14 13 12 13

It compiles and runs (or as I tell my kids- it runs but doesn't work!)

#include <fstream>
#include <iostream>
#include <cctype>
using namespace std;

// Declare functions................................
void  read_image (int inputArray[][257],int ROW, int COL, int image);
//int  read_image (int);   // read an image into an integer array.

//int duplicateImage (int inputArray[][colls], int dupeArray [][colls], int rows);
// copies the original image array to a new image array

//int smooth_image (int);   // calculates a new image using above equation to smooth the 
//  image doing only the interior pixels.

//int sharpen_image (int);   // calculates a new image using above equation to sharpen the 
// image doing only the interior pixels.

//int ebmoss_image (int);   // calculates a new image using above equation to smooth the 
// image doing only the interior pixels.

//int apply_border (int);  // puts a zero value in every border pixel.

// int write_image (int);   // Outputs the new image to a file using the same format as the 
//  input image file used. 
void Menu ();  // Displays menu of possible operations
void resArrIn (int resArray[7], int COL, int ROW);

int opChoice (int & choice);  // Switch runs choice of operation  

//int outRes(int resArray[]);
// fixpoint 


// Command line entry/ test.........................
//.................................................................

int main ( int argc, char * argv[] )
{
   ifstream catIn ;
   ofstream catOut ;
   int i ;


   if ( argc != 3 )	//test that two arguments are present
   {
      cout << "Program usage:  prog4.exe catIn catOut ";
      cout << endl;
      cout << "Exiting now." << endl << endl;
      // return -1;
   }

   for( i = 0; i < argc; i++ )	//list all the arguments, including
      cout << argv[i] << endl; 	//program name

   catIn.open( argv[1]);  		//open first argument–inputfile
   if( !catIn )
   {
      cout << "Error opening input file: " << argv[1] << endl;
      cout << "Exiting program now." << endl << endl;
      return -2;
   }

   catOut.open(argv[2]);	//open second argument – output file
   if( ! catOut )
   {
      cout << "Error opening output file: " << argv[2] << endl;
      cout << "Exiting program now. " << endl << endl;
      catOut.close();
      return -3;
   }

   catOut << "Test 1"  << endl;


   // Main Body of Program begins****************************
   //******************************************************

   //Declare variables

   const int rows = 257;  // array parameter
   const int colls = 257;   // array parameter
   int choice;
   int COL, ROW; // collumns & rows read in from file

   //Declare arrays

   int inputArray [257][257]; // input file array UNCHANGED 
   int dupeArray [rows][colls]; // working array for cat.pgm file
   int resArray [7];   // array containing resolution numbers
   //char magicArray [3];
   //char magicNmbrArray [magNum]; // array to store magic number  *** when 3, get stack corrup**

   //catIn >> magicNmbrArray[magNum];  // 4/3 works???

   char magic;
   int num, maxWhite, image;
   int j = 0;
   // array to store resolution
   catIn >> magic >> num; // read in magic number   

   catIn >> COL >> ROW; // read in resolution
   catIn >> maxWhite;
   catIn >> image;
   read_image (inputArray, ROW, COL,  image);


//XXXXXXXXXXXXXXtest pointXXXXXXXXXXXXXXXXX
   cout << magic <<  num << "\n"<< COL << " "<< ROW << " \n" << maxWhite;  
   // fixpoint
   //**opens, reads, write, but doesnt read & write correctly.


   //  for (int i = 1; i < 2; i++)



   //cout << COL << ROW;
   catOut << magic <<  num <<endl << COL << " " << ROW << endl << maxWhite;

   for (int i = 0; i < ROW; i++)
   {
      for (int j = 0; j < COL; j ++)
      {
         catOut << inputArray[i][j];
      }
   }




   // outRes (resArray);




   //duplicateImage (inputArray, dupeArray, rows);

   Menu();  // Display  choice of operations
   cin >> choice;  // Enter choice
   opChoice (choice);  // Function: Switch runs choice of operation  

   return (0);
}

//*******FUNCTIONS********************
//**************************************


void Menu () //Displays Operations Menu
{
   cout << "\n\n\nThe image file, cat.pgm has been loaded.\n\n\n\n";
   cout << "Please choose the operation you wish to perform:\n\n\n";
   cout << "1:  Store the original image to file. \n\n";
   cout << "2:  Smooth and store image to file. \n\n";
   cout << "3:  Sharpen and store image to file. \n\n";
   cout << "4:  Emboss and store image to file \n\n";
   cout << "5:  Exit program. \n\n\n\n";
   cout << "Choose from options 1-5: ";
}
//*****************************************************


int opChoice (int & choice)  // Switch runs choice of operation  
{
   switch (choice)
   {
   case 1: // original image
      cout << "\n\n1\n\n";
      // ofstream.catOut ("cat_original");
      //original (dupeArray);
      break;

   case 2: // smooth image
      cout << "    2\n";
      //ofstream.catOut ("cat_smooth");
      //smooth_image;
      break;

   case 3:  // sharpened image
      cout << "\n\n3\n\n";
      //ofstream.catOut ("cat_sharpen");
      //sharpen_image;
      break;

   case 4:  // embossed image
      cout << "\n\n4\n\n";
      //ofstream.catOut ("cat_emboss");
      //emboss_image;
      break;

   case 5:
      cout << "\n\n\nExiting program\n\n";
      return (0);
      break;

   default:
      cout << "Invalid entry.  Exiting program\n\n";
      return (0);
   }
}
/*



//Copies image from input array to working array
/*int duplicateImage (int inputArray[][colls], int dupeArray [][colls], int rows)
{
for ( int i = 0; i < rows; i++)
{
cin >> dupeArray [i];
}
}*/
void  read_image (int inputArray[][257],int ROW, int COL, int image)
{    
   for (int i = 0; i < ROW; i++)
      for (int j = 0; j < COL; j ++)
      {
         inputArray [i] [j]= i + j;

      }
}

I am still a little unclear on how to perform an 'emboss' operation.. I'd hate to give you wrong code based on my misunderstanding.

From what I understand, we first identify a (non-border) pixel to emboss. In this case, we'll attempt modify the "15" pixel:

P2
4 4
15
0  0   0  0
0 [b]15[/b]  10  0
0  7   5  0
0  0   0  0

Then we identify the pixel located to the 'lower-right', which in this case is the "5" pixel (which can be a border pixel):

P2
4 4
15
0  0   0  0
0 [b]15[/b]  10  0
0  7   [b]5[/b]  0
0  0   0  0

In this example, according to your emboss forumla, we have (5 - 15) + 8 = -2 which is < 0. Therefore, the 15 pixel when embossed becomes 0.

This is my understanding of the emboss operation thus far.. am I close?
(Doesn't make sense to me.. turning a white pixel to black)

-dw

Edited 6 Years Ago by Clinton Portis: n/a

Yup. That's it. Doesn't make sense to me either, but that's what the directions say (& have been repeated by our professor- obviously we are not the only ones to question the white to black thing)

Seems like I have to begin at the lower right of the file (excluding the border) and work my wa back. The size of the file is fixed at 256 x 256 (fortunately) so we don't have to allow for variations.

thx!

Very good then.. I was considering that where you start the emboss operation makes a difference as it affects pixels progressivley through the pgm file (starting at the upper-left corner would have a different effect than starting at the lower-right corner for example)

Having a fixed 256 256 file size is kinda cool, although it would be simple to account for pgm files of any size.

Give me a chance to grab a beer or 2 and I'll knock out some pseudo code for ye'.

Edited 6 Years Ago by Clinton Portis: n/a

1. When reading in your pgm file, I would recommend reading it into 2D array:

int pixels[256][256];

2. You could read in the pgm file like this:

//Get file type
catIn >> type;
//Get file dimensions
catIn >> length >> width;
//Get grayscale max value 
catIn >> grayscale_max;
//Get pixels
for(int i=0; i<256; i++)
{
     for(int j=0; j<256; j++)
     {
          catIn >> pixels[i][j];
     }
}

3. Now that you have a nicely packaged pgm file.. all you need is that almighty emboss function:

void emboss(int& pixels[][])
{
     int result = 0;

     //I am using loop conditions that will start the emboss operation at the lower-right non-border pixel 
     //and work backwards through the pgm file

     //backwards row traversal
     for(int i=254; i>0; i--)
     {     
          //backwards column traversal
          for(int j=254; j>0; j--)
          {
               //Perform 'emboss math'
               result = (pixel[i+1][j+1] - pixel[i][j]) + 8;
               
               if(result < 0)
               {
                    result = 0;
               }
               else if(result > 15)
               {
                    result = 15;
               }

               //Assign the new 'emboss' value 
               pixel[i][j] = result;   
          }
     }
}

4. All there is left to do now is to use your catOut object to open a new file and write the pgm file header info and pixels[][] to file. It will conveniently look similar (yet opposite) to step #2.

All of this code is untested. It is just an idea of how I'd probably go about doing this. There are probably many many ways to get this done. If anyone see's a better way to do this let me know. If you see errors in my code, feel free to correct them on your own.

Edited 6 Years Ago by Clinton Portis: n/a

Thank you so much! I have an exam tomorrow (later), but will then get right on this.

I did however, get the file read in and out (many thanks to you!). The out file has no spaces between the numbers. Did I do something wrong? Something with strings... and getfile...

Thank you again! Now I can go to sleep knowing my code compiles! (If not, I have strange, ominous dreams)

Christina

Comments

You will have to write the spaces between the numbers:

catOut << stuff << ' ' << more_stuff << ' ' << endl;

Edited 6 Years Ago by Clinton Portis: n/a

It seems Clinton has got you well covered, but just to correct something.. I'm 100% sure that for this emboss function, you need to start from the upper left corner such that you don't use modified pixel values. Say you start from the last non-bordering row of the image, when you get to the second-last row, you will be using the modified row of pixels in the calculation of the second-last row. I don't think that was the intent from the formula that specifically mentions the modified pixel as a function of the two _original_ pixels.

Also, for smoothing and sharpening, you will need a second image to put the result into (you cannot perform these operations "in-place" like you can with emboss).

Mike,
Thank you so much. I'm not sure what you mean by "creating a second image." I'll first read the file into an array, which will be copied. This is the array I'll work from. As the user choses subsequent operation, the dupeArray will be recopied for manipulation and then written to an outfile.

I have a feeling that you have a far better grasp of the process than I. (my brain is still bleeding from my exam today - high hopes, though).

The formulae for the smoothing and sharpening processes are far more involved than the embossing. (ex: M (e) = ( O(a) + O(b) + O(c) + O(d) + O(e) + O(f) + O(g) + O(h) + O( i ) ) / 9.0 :( )

Thank God I actually LIKE doing this!

What I meant by creating a second image is that you need to make one image to store the modified pixels and keep one image intact such that you can pick the original pixels from it. So you will need to traverse both images at the same time, picking values from the original image, computing the formula and storing the result in the modified (or filtered) image.

>>I have a feeling that you have a far better grasp of the process than I.
Sure, I've done my share of image processing work. This process is at the core of almost all image processing techniques (called "convolution filtering").

I hope your exam went well!

Dave!
I have a good file out, with neat collums, proper spacing*, aaannnndddd.....

a black border!!!! (*I was confusing character strings and the spacing thing)

Wooo Hooo!

Just wanted to let you know how much I appreciate your help!
I survived my exam (either very good, or very bad- I'm hoping for the latter!)

I'm going to move on to he ebmossing now. Today we had a clarification: we have to use the original image array, perform the manip operation and store it inthe second array.

Good to know, huh? So this makes it easier (as Mike said -thanks to Mike too!- I'd need a second array)

More to follow... I'm sure I'll

Ms. Christina it would be very lovely if you would post your completed program so i can find the few errors i have and correct them in mine before i fail csc 150!! It would be much appreciated

trashman319,
are you working on a similar program? Here is my completed program. i think it's good to go.

#include <fstream>
#include <iostream>
#include <cctype>
#include <iomanip>
using namespace std;

// Global Constants...
#define rows 256  // array parameters
#define colls 256  //

// Declare functions................................

void  read_image (int inputArray[rows][colls], ifstream & catIn); 
/* Reads an image into an integer array.                                    */

void duplicate_Image (int inputArray[rows][colls], int manipArray [rows][colls]);
/* Copies the original image array to a new image array        */

void smooth_image (int inputArray[rows][colls], int manipArray[rows][colls]);
/* Calculates a new image using above equation to smooth the 
     image doing only the interior pixels.                                        */

void sharpen_image ( int inputArray [rows][colls], int manipArray [rows][colls]);
   /* Calculates a new image using above equation to sharpen the 
      image doing only the interior pixels.                                        */

void emboss_image (int inputArray [rows][colls], int manipArray [rows][colls]);
/* Calculates a new image using above equation to smooth the 
     image doing only the interior pixels.                                          */
  
void apply_border (int manipArray[rows][colls]);
/* Creates a black border by putting a zero value in every border pixel.*/

void write_image (int manipArray [rows][colls], ofstream & catOut); 
 /* Outputs the new image to a file using the same format as the 
      input image file used.                                                                     */

void makeOutFile (int choice, ofstream & catOut, ifstream & catIn);
/* Creates the appropriate output file                                              */

void Menu (); 
/* Displays menu of possible operations */

int opChoice (int & choice, int inputArray[rows][colls], int manipArray[rows][colls],
              ifstream & catIn, ofstream & catOut);
/* Runs choice of operation & calls function to create ouptut file. */  



/*****************************************************
  .......................................MAIN..........................................
  *****************************************************/

// Command line entry/ test.........................
int main ( int argc, char * argv[] )
{
   ifstream catIn ;
   ofstream catOut ;
   int i ;

   if ( argc != 3 )	//test that two arguments are present
   {
      cout << "Program usage:  prog4.exe catIn catOut ";
      cout << endl;
      cout << "Exiting now." << endl << endl;
      // return -1;
   }

   for( i = 0; i < argc; i++ )	//list all the arguments, including
      cout << argv[i] << endl; 	//program name

   catIn.open( argv[1]);  		//open first argument–inputfile
   if( !catIn )
   {
      cout << "Error opening input file: " << argv[1] << endl;
      cout << "Exiting program now." << endl << endl;
      return -2;
   }

   // Main Body of Program begins****************************   

   //DECLARATIONS.....................................................  

   //Declare variables
   int choice;
   int COL, ROW; // collumns & rows read in from file
   char magic;
   int num, maxWhite;
   int j = 0;

   //Declare arrays
   int inputArray [rows][colls]; // input file array UNCHANGED 
   int manipArray [rows][colls]; // working array for cat.pgm file

   //OPERATIONS............................................................
   
   // Read in file information
   catIn >> magic >> num; // read in magic number from file

   catIn >> COL >> ROW; // read in resolution from file

   catIn >> maxWhite;  // read in max white value from file

   read_image (inputArray, catIn);  // read image from file to input array
   //*************************************************************************


  // Input operations.........................   
   Menu();  // Display  choice of operations

   cin >> choice;  // Enter choice

   while (choice < 0 || choice > 5)  //Check choice validity
   {
      cout << "\n\nInvalid entry.  Please choose from options 1-5.\n\n";
      cin >> choice;
   }

    // Open output file, begin image manip choice and operation
   opChoice (choice, inputArray, manipArray, catIn, catOut);     
   
   // output to file magic nmbr, resolution & max white value
   catOut << magic <<  num <<endl << COL << " " << ROW << endl << maxWhite << "\n";

   apply_border (manipArray);  // Apply black border to image in manipArray   

   write_image (manipArray, catOut);   // Write image to out file

   return (0);
}
/*******************************************
...........................END MAIN..................................
********************************************/



/*************************************************************************
**************************************************************************
..................................FUNCTIONS....................................................................
**************************************************************************
**************************************************************************/

 //Displays Operations Menu
void Menu ()
{
   cout << "    \n\n\n     Processing image file, \"cat.pgm\".\n\n\n\n";
   cout << "    ************************************\n";
   cout << "              OPERATIONS MENU\n";
   cout << "    ************************************\n\n";
   cout << "     1:  Store the original image to file. \n\n";
   cout << "     2:  Smooth and store image to file. \n\n";
   cout << "     3:  Sharpen and store image to file. \n\n";
   cout << "     4:  Emboss and store image to file \n\n";
   cout << "     5:  Exit program. \n\n\n";
   cout << "        Choose from options 1-5: ";
}
//*****************************************************


// Performs chosen operations
int opChoice (int & choice, int inputArray[rows][colls],
              int manipArray[rows][colls], ifstream & catIn, ofstream & catOut) 
{      
   switch (choice)
   {
   case 1: // original image
      makeOutFile (choice, catOut, catIn);  // makes output file
      duplicate_Image (inputArray, manipArray);  // duplicates original image
      cout << "\n\nYour image file, \"cat_original\" is ready...\n\n\n";
      break;

   case 2: // smooth image     
      makeOutFile (choice, catOut, catIn);   //makes output file
      smooth_image (inputArray, manipArray);   //smooth_image;
      cout << "\n\nYour image file, \"cat_smooth\" is ready...\n\n\n";
      break;

   case 3:  // sharpened image      
      makeOutFile (choice, catOut, catIn);  // makes output file
      sharpen_image ( inputArray, manipArray);
      cout << "\n\nYour image file, \"cat_sharpen\" is ready...\n\n\n";
      //sharpen_image;
      break;

   case 4:  // embossed image
      makeOutFile (choice, catOut, catIn);  // makes output file
      emboss_image (inputArray, manipArray); // emboss image
      cout << "\n\nYour image file, \"cat_emboss\" is ready...\n\n\n";
      break;

   case 5:
      cout << "\n\n\nExiting program\n\n";
      return (0);
      break;
   }    
}


// Reads image from file into array
void  read_image (int inputArray[rows][colls], ifstream & catIn)
{    
   for (int i = 0; i < rows; i++)
      for (int j = 0; j < colls; j ++)
      {
         catIn >>  inputArray [i] [j];

      }
}


//Copies image from input array to working array
void duplicate_Image (int inputArray[rows][colls], int manipArray [rows][colls])
{
   for (int i = 0; i < 256; i++)
      for ( int j = 0; j < 256; j++)
      {
         manipArray [i][j]= inputArray[i][j];
      }
}


// Writes image to out file
void write_image (int manipArray[rows][colls], ofstream & catOut)   // writes image to out file
{
   for (int i = 0; i < rows; i++)
   {
      for (int j = 0; j < colls; j ++)
      {
         catOut.width(2);
         catOut << manipArray[i][j] << " ";
         if (j ==255)
            catOut << "\n";      
      }
   }
}

// Applies a black border 
void apply_border (int manipArray[rows][colls])
{
   for (int i = 0; i < rows; i++)
      for (int j = 0; j < colls; j++)
      {
         if (i == 0 || i ==255)
         {
            manipArray[i][j] =0;
         }
         if (j == 0 || j == 255)
         {
            // Enter values into array
            manipArray[i][j] =0;
         }
      }
}

/*********************************************************************
.............Image Manipulation Functions............................................................
**********************************************************************

Note: All formula descriptions are based upon pixels labeled alphabetically
in a grid format:         a      b      c         with (e) the manipulated pixel. 
                                        d    (e)     f
                                        g      h      i          
              O(e) = original pixel     M(e) = manipulated pixel                       */


// Creates embossed image
void emboss_image (int inputArray [rows][colls], int manipArray [rows][colls])
{
   int value;
   for (int i = 0; i < rows; i ++)
   {
      for (int j = 0; j < colls; j ++)
      {
         // Original formula: M(e) = O(i) = O(e) +8
         value =  (inputArray[i+1][j+1] - inputArray[i][j]) + 8;      

         // Confine white value between 0-15
         if (value < 0)         
         {
            value = 0;
         }
         if (value > 15)
         {
            value = 15;
         }
         // Enter values into array
         manipArray [i][j] = value;
      }
   }
}


// Creates sharpened image
void sharpen_image ( int inputArray [rows][colls], int manipArray [rows][colls])
{
   float value;
   int value2;
   int x;
   for (int i = 0; i < rows; i ++)
   {
      for (int j = 0; j < colls; j ++)
      {
         /* Original formula:
         M(e) = 2 * O(e)  - [ O(b) + O(d) + O(f) + O(h) ]  /4.0                                 */
         value = inputArray [ i ][ j ] *2;
         x = inputArray[ i-1] [ j ] + inputArray [ i ] [ j +1 ] +  inputArray [ i - 1] [ j ] + inputArray [ i ] [ j - 1 ];
         value = value - ( x / 4.0);

         // Round value to nearest integer
         value = value + .5;
         value2 = value;

         // Confine white value between 0-15
         if ( value2 < 0)
         {
            value2 = 0;
         }
         if (value2 > 15)
         {
            value2 = 15;
         }
         // Enter values into array
         manipArray [i][j] = value2;
      }
   }
}


// Creates smoothed image
void smooth_image (int inputArray[rows][colls], int manipArray[rows][colls])
{
   float value;
   int value2;   
   for (int i = 0; i < rows; i ++)
   {
      for (int j = 0; j < colls; j ++)
      {
         /* Original formula:
         M(e) = [O(a) + O(b) + O(c) + O(d) + O(e) + O(f) + O(g) + O(h) + O(i) ] /9.0               */

         // 3 elements above center pixel (e)- a,b,c
         value  = inputArray[ i-1 ][ j-1] + inputArray[ i-1 ][ j ] + inputArray[ i-1 ][ j+1];  

         // Elements on either side of center pixel (e)- d,f
         value = value + inputArray[ i ][ j-1 ] + inputArray[ i ][ j ] + inputArray[ i  ][ j+1];

         // 3 elements below center pixel (e)- g,h, i
         value = value + inputArray[ i+1 ][ j-1] + inputArray[ i+1 ][ j ] + inputArray[ i+1 ][ j+1 ];
         // Total divided by 9 for average
         value = value / 9.0;

         // Round value to nearest integer
         value = value + .5;
         value2 = value;

         // Confine white value between 0-15
         if ( value2 < 0)
         {
            value2 = 0;
         }
         if (value2 > 15)
         {
            value2 = 15;
         }
         // Values into array
         manipArray [i][j] = value2;
      }
   }
}


// Creates appropriately named out file
void makeOutFile (int choice, ofstream & catOut, ifstream & catIn)
{
   switch ( choice)
   {
   case 1:
      catOut.open ("cat_original.pgm");	// Open output file cat_original.pgm
      if( ! catOut )
      {
         cout << "Error opening output file: " << " original_image" << endl;
         cout << "Exiting program now. " << endl << endl;
         catOut.close();
         catIn.close();
      }
      break;

   case 2:
      catOut.open ("cat_smooth.pgm");	// Open output file cat_smooth.pgm
      if( ! catOut )
      {
         cout << "Error opening output file: " << " original_image" << endl;
         cout << "Exiting program now. " << endl << endl;
         catOut.close();
         catIn.close();
      }
      break;

   case 3:
      catOut.open ("cat_sharpen.pgm");	// Open output file cat_sharpen.pgm
      if( ! catOut )
      {
         cout << "Error opening output file: " << " original_image" << endl;
         cout << "Exiting program now. " << endl << endl;
         catOut.close();
         catIn.close();
      }
      break;

   case 4:
      catOut.open ("cat_emboss.pgm");	// Open output file cat_emboss.pgm
      if( ! catOut )
      {
         cout << "Error opening output file: " << " original_image" << endl;
         cout << "Exiting program now. " << endl << endl;
         catOut.close();
         catIn.close();
      }
      break;

   }
}

***************************************************
***************************************************
T H A N K Y O U ! ! ! !
***************************************************
***************************************************

I want to say thank you to Dave & Mike who were wonderful in answering my questions and shoving me in the right direction. (last exam- 95%!!!!) I'm submitting my program later today.

You guys have been a Godsend. Thank you so much!

Happy Holidays!

Christina

Christina,

I am working on the same exact program and i was having similar problems as you. I really appreciate your help!!

Also christina, when you run your program and it says your new file is ready..is the image not supposed to show up..or where do you access the image

No Siree! it made it go alot smoother though. I wasn't closing my input and output files in my switch statment so i kept getting errors.

Hey Dave!

You know, you're probably right. I'm soooo gullible. Sorry Daniweb community!

Hey trashman!

If that's the case, you're going to fail CSC150 anyway. Sooner or later you're going to have to write your own code. (... really sucks to freeze during an exam...)

How's about you post what you have thus far?

Dave, thanks again for all your help! I really couldn't have done it without you!
Christina

I can post it when i finish in a little bit. But one thing on your program christina. I believe we are not supposed to have global variables or constants. My professor said we would get an automatic letter grade off for those if you wanted to know

Thank you Christina.

It's nice to see someone who can really pick up on this stuff and run with it. You actually required very little help on this project.

With that said, we should hook up sometime. Maybe talk some c++ over dinner. Add Dave Weirich on facebook. I am currently using a pic of Jim Mora as my profile pic.

Comments
LOL

Trashman,

We had no constraints on global constants. I ran the program by my instructor. He said it was fine. Global constants aren't always evil.

On the other hand, my daughter has a team of 7 working on a project and one guy (generic, non-gender specific pronoun) has a real thing for using global constants that are only constant on his side of the globe. As the consultant who simply rides heard on her clients (she's an IT headhunter, if you will, collecting people for the project, but not working on it herself), all she hears, "blah, blah, he won't play nice...blah, blah...global constants, blah, blah.... :)

Dave,

The best thing about the internet, is that one can "talk C++ over dinner" from opposite ends of the earth at 1 am!

And this is good, as I'm not dating until 2015(last kid graduates). :)

Perhaps we can dine sometime during Christmas break. Not sure though, I average about 6 hours of sleep/ day. Fa-la-la- zzzz...

Last week a guy asked me to coffee, I told him the 2015 thing, but he persisted, so I said I had time on Thursday, at about 3:30am. He thought I was joking.

No, not creepy, at all. And a good thing about the teeth! (you'd be surprised...)

Best regards,
Christina

if you hang with me, not only can you get your cup of coffee, but you'll also have someone to talk c++ with.. how easy is it to find a guy like that these days... i'm like the perfect guy :P

Edited 5 Years Ago by Clinton Portis: n/a

Yeah, yeah. :)

Perfection is over rated.

Got to get up in 4.5 hrs.

Night Dave... :)

This question has already been answered. Start a new discussion instead.