Question: Program outline: 1 . Your C program should read any given grayscale images in pgm format. Grayscale images have pixel values ranging from 0 -
Program outline:
Your C program should read any given grayscale images in pgm format. Grayscale
images have pixel values ranging from This pixel values can be treated as
unsigned characters.
The image data should be loaded as a D matrix.
The D matrix should be manipulated to threshold the given image and convert it to a
binary image.
The D matrix should be manipulated to rotate the given image left.
The manipulated D matrices should be converted back to grayscale image. This image
should be viewable.
Your tasks: READ CAREFULLY
DO NOT alter the main function. Four functions are declared and called in the given
program. Your task is to write the function definitions for those functions:
A PixelGray readPGMconst char filename, int width, int height;
a This function should open the file with provided file name.
i Note: If you use MacOS, it is okay to have the mode in r If you are using
Windows, you must have the mode to rb
b Handle errors!
c Get the dimensions of the image.
d DO NOT SKIP THIS STEP, figure out how to eat the newline character after
getting the last line of the headers.
e Dynamically allocate the storage D matrix for the image dimension.
f Read from the file and fill the D matrix.
g Close the file.
h Return the D matrix.
B void writePGMconst char filename, PixelGray matrix, int width, int height;
a This function should create a new file with the file name provided. This file should
be opened for writing.
b Remember there are headers from the original file. Think about how you will write
them to the file before passing the data from the matrix.
i Note: Autograder on gradescope will check line by line so I would leave no
space after passing your headers beside newline at the end of the last
header entry.
c Handle errors!
d Copy data from the provided D matrix to the file.
e Close the file.
C PixelGray thresholdPixelGray matrix, int width, int height;
a This function should create a new D matrix. Dynamically allocate the storage
D matrix for the new matrix.
b Thresholding
i If original value store
ii Otherwise store
c Return the new D matrix.
D PixelGray rotatePixelGray matrix, int width, int height;
a This function should create a new D matrix. Dynamically allocate the storage
D matrix for the new matrix.
b Rotate the original D matrix and store the result as the new matrix.
i Rotation can be achieved by matrix transpose swapping rows & column
c Return the new D matrix
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
