title: Highlighting an image
body: <p>My instructor wrote 
  'One way to highlight objects in an image is to make all pixels below a threshold (T1) 0, and all pixels above a threshold (T2) 255. Write a function to highlight the image, using the following prototype:</p>
  
  <pre><code>void highlight(int image[][MAXHEIGHT],int width, int height, int t1, int t2)
  </code></pre>
  
  <p>Write a main program that inputs t1 and t2 from the user, highlights the image, and then writes the image. "</p>
  
  <p>I already have functions that can read and write an image but I have no idea how to change the pixels of an image.</p>
  
  <p>Code so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cassert&gt;
  #include &lt;cstdlib&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  const int MAXWIDTH = 512;
  const int MAXHEIGHT = 512;
  
  // reads a PGM file.
  void readImage(int image[][MAXHEIGHT], int &amp;width, int &amp;height) {
    char c;
    int x;
    ifstream instr;
    instr.open("city.pgm");
  
    cout &lt;&lt; "This is running " &lt;&lt; endl;
  
    // read the header P2
    instr &gt;&gt; c;  assert(c == 'P');
    instr &gt;&gt; c;  assert(c == '2');
  
    // skip the comments (if any)
    while ((instr&gt;&gt;ws).peek() == '#') { instr.ignore(4096, '\n'); }
  
    instr &gt;&gt; width; 
    instr &gt;&gt; height;
  
    assert(width &lt;= MAXWIDTH);
    assert(height &lt;= MAXHEIGHT);
    int max;
    instr &gt;&gt; max;
    assert(max == 255);
  
    for (int row = 0; row &lt; height; row++) 
      for (int col = 0; col &lt; width; col++) 
        instr &gt;&gt; image[col][row];
    instr.close();
    return;
  }
  
  // Writes a PGM file
  void writeImage(int image[][MAXHEIGHT], int width, int height) {
    ofstream ostr;
    ostr.open("outImage.pgm");
    if (ostr.fail()) {
      cout &lt;&lt; "Unable to write file\n";
      exit(1);
    };
  
    // print the header
    ostr &lt;&lt; "P2" &lt;&lt; endl;
    // width, height
    ostr &lt;&lt; width &lt;&lt; ' '; 
    ostr &lt;&lt; height &lt;&lt; endl;
    ostr &lt;&lt; 255 &lt;&lt; endl;
  
    for (int row = 0; row &lt; height; row++) {
      for (int col = 0; col &lt; width; col++) {
        assert(image[col][row] &lt; 256);
        assert(image[col][row] &gt;= 0);
        ostr &lt;&lt; image[col][row] &lt;&lt; ' ';
        // lines should be no longer than 70 characters
        if ((col+1)%16 == 0) ostr &lt;&lt; endl;
      }
      ostr &lt;&lt; endl;
    }
    ostr.close();
    return;
  }
  
  
  int main ()
  {
   int image[MAXWIDTH][MAXHEIGHT], width, height, t1, t2;
  
   readImage (image, width, height);
   writeImage (image, width, height);
  
   return 0;
  }
  </code></pre>