Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The primary goal of this assignment is to help you familiarize with Imperative Programming. You will learn to: use simple structures. Dynamically allocate memory. Write
The primary goal of this assignment is to help you familiarize with Imperative Programming.
You will learn to:
use simple structures.
Dynamically allocate memory.
Write functions.
Implement pointes and references.
Read from and write to files.
You can write your program either on EDORAS server or CLION IDE. CLION IDE is
recommended.
In this program, you will read and manipulate grayscale images. Download the given
startercode.c and implement the missing functions.
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
I would suggest you to open the file Lenna.pgm with your text editor available on your pc
to see how the headers look like. Please do not alter the file because in autograder it will
only use your code to alter the pgm file that we have on gradescope.
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 the provided functions.
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.
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.
f
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.
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started