#include #include //Histogram equalization of pgm images: Stage 1 int main ( ) { char c; char imageType[3]; int width, height, maxIntensity; int frequency[256]; int i,j; int gray = 0; //read magic number scanf ( "%s", imageType); //Stop if image type is not P5 if (strcmp(imageType,"P5") != 0) { printf("Bad image format. Check image format and run again\n"); exit(1); } //Read and discard characters till you see a newline do { c = fgetc(stdin); } while ( c != '\n'); c = fgetc(stdin); //Read next character. This may be the # character if ( c == '#') { //file has a comment //Read and discard characters till you see a newline do { c = fgetc(stdin); } while ( c != '\n'); } else {// file has no comment ungetc(c, stdin); } scanf("%d %d", &width, &height); scanf("%d", &maxIntensity); //Read and discard characters till you see a newline do { c = fgetc(stdin); } while ( c != '\n'); //end of header processing //initialize the frequency array for(i=0; i < 256; i++) { frequency[i] = 0; } //read grayscale image data and compute the histogram for ( i=0; i < width*height; i++ ) { scanf ( "%c", &gray); pixelIntensities[i] = gray; //save the pixel intensities in the array frequency[gray]++; } //Part 2: Print the histogram using * }