#include #include #include const int maxsize=1000; int main() { int image1[maxsize][maxsize]; int image2[maxsize][maxsize]; int rows, cols; int row, col; int maxpixel; int totallines; struct timeval tv; struct timezone tz; long starttimeSec, starttimeMicro; long endtimeSec, endtimeMicro; long totalSec, totalMicro; char *line = NULL; ssize_t inputline; size_t len=0; FILE *infile; FILE *outfile; /* if ((infile=fopen("ISS-four.pgm", "r")) == NULL) { printf("Could not open file\n"); exit(0); } */ if ((outfile=fopen("fig1Test.pgm", "w")) == NULL) { printf("Could not open file\n"); exit(0); } if ((infile=fopen("fig1.pgm", "r")) == NULL) { printf("Could not open file\n"); exit(0); } inputline = getline(&line, &len, infile); // read the format line inputline = getline(&line, &len, infile); // read the comment line fscanf(infile,"%d %d", &cols, &rows); fscanf(infile,"%d", &maxpixel); printf("Rows=%d Cols=%d Max pixel value=%d\n", rows, cols, maxpixel); totallines = rows*cols; printf("Totallines=%d\n", totallines); for(row=0; row 255) image2[row][col] = 255; */ /* // Horizontal differencing: image2[row][col] = abs(image1[row][col+1] - image1[row][col]); if (col == cols-1) image2[row][col] = 0; // Set the pixels in the last column equal to 0 */ // Robert's cross image2[row][col] = abs(image1[row][col-1] - image1[row][col+1]) + abs(image1[row-1][col] - image1[row+1][col]); if (row == 0 || row == rows-1 || col == 0 || col == cols-1) image2[row][col] = 0; // Set the first and last rows and cols to 0 } gettimeofday(&tv, &tz); endtimeSec = tv.tv_sec; endtimeMicro = tv.tv_usec; printf("End image processing\n"); printf("end (date_and_time): %d sec, %d microsec\n", endtimeSec, endtimeMicro); if (endtimeSec > starttimeSec) { totalSec = endtimeSec-starttimeSec; totalMicro = endtimeMicro + (1000000 - starttimeMicro); } else { totalSec = 0; totalMicro = endtimeMicro - starttimeMicro; } printf("Total time = %d sec, %d microsec\n", totalSec, totalMicro); fprintf(outfile,"P2\n"); fprintf(outfile, "# Test file\n%d %d\n%d\n", cols, rows, maxpixel); for(row = 0; row