Demonstrate in class on or before Thursday, October 29, 2009. No credit after that.

Write a C program that performs contrast enhancement on a PGM image, as described below:
  1. Have your program open and read a PGM file. As in previous projects, use input redirection (<) to read the file.
  2. Calculate the frequencies of the grayscale pixel intensities. That is, calculate how many pixels in the file have intensity 0, how many have intensity 1, ... all the way to how many have intensity 255. Use an integer array for this.
  3. Plot the pixel intensity frequencies calculated in the previous step as a histogram. Your output will have 256 lines, with each line having a number of * characters proportional to the corresponding count. For instance, if there are 500 pixels that have intensity 0 and you scale the output by, say, a factor of 10, the first line of your histogram will contain 50 stars.
  4. Calculate the cumulative pixel intensity frequencies. That is, determine how many pixels have intensities <= 0,<= 1, <= 2, ...., all the way to <= 255. Use a second integer array for this.
  5. Use the cumulative pixel intensity frequencies calculated above to calculate new pixel intensities for the image.
  6. Write the new pixel intensities to a file in PGM format. As in previous projects, use output redirection (>) for this.

Test your program on the following PGM image.