Answered step by step
Verified Expert Solution
Link Copied!

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
starter_code.c and implement the missing functions.
Program outline:
1. Your C program should read any given grayscale images in pgm format. Grayscale images
have pixel values ranging from 0-255. This pixel values can be treated as unsigned
characters.
2. The image data should be loaded as a 2D matrix.
3. The 2D matrix should be manipulated to threshold the given image and convert it to a
binary image.
4. The 2D matrix should be manipulated to rotate the given image left.
5. The manipulated 2D matrices should be converted back to grayscale image. This image
should be viewable.
Your tasks: (READ CAREFULLY)
1. 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.
2. 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.
3. PixelGray** readPGM(const 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 (2D matrix) for the image dimension.
f. Read from the file and fill the 2D matrix.
g. Close the file.
h. Return the 2D matrix.
4. void writePGM(const 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 2D matrix to the file.
e. Close the file.
f.
5. PixelGray** threshold(PixelGray** matrix, int* width, int* height);
a. This function should create a new 2D matrix. Dynamically allocate the storage (2D
matrix) for the new matrix.
b. Thresholding
i. If original value >80-- store 255
ii. Otherwise store 0
c. Return the new 2D matrix.
6. PixelGray** rotate(PixelGray** matrix, int* width, int* height);
a. This function should create a new 2D matrix. Dynamically allocate the storage (2D
matrix) for the new matrix.
b. Rotate the original 2D matrix and store the result as
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Why does sin 2x + cos2x =1 ?

Answered: 1 week ago

Question

What are DNA and RNA and what is the difference between them?

Answered: 1 week ago

Question

Why do living creatures die? Can it be proved that they are reborn?

Answered: 1 week ago