Part 1 – Image reading
In part 1 you should write a program that reads and prints an image, where the input image is run-length encoded.
Run-length encoding is a way of coding image data that takes advantage of the fact that large areas of images are homogeneous, i.e. have similar brightness locally.
The image pixels are accessed in \raster-scan" order (ensure you understand raster scan order).
File Format:
The format of the run-length encoded image is:
<width> <height> <grey-levels> <pix1> <len1> <pix2> <len2>
.....
where all the <...>'s represent integer values. White-space (spaces) separate the values.
• <width> is the width of the image in pixels. The limit on width is 80 pixels.
• <height> is the height of the image in pixels. The limit on height is 100 pixels.
• <grey-levels> is the number of grey levels in the image, for instance 2 for a black and white image. The grey-level pixel values can only take the values 0, 1,...,
<grey-levels>-1. The maximum value for <grey-levels> is 4. The limits on
<width>, <height> and <grey-levels> apply to all parts of the assignment.
• <pix1> is the grey level pixel value of the first pixel on the first row of the image,
i.e. the top-left pixel.
• <len1> is the number of times that the first pixel is repeated, following the image pixels in raster-scan order.
• <pix2> is the grey level pixel value of the next pixel, i.e. the first pixel different from <pix1>.
• <len2> is the number of times that <pix2> is repeated.
..... the list of <pix>, <len> pairs continuing to the end of the image in the bottom-right hand corner.
The sum of the <len>'s is equal to <width>*<height>. Once you have read the image into your program, print it to standard output (the screen).
The format is as follows:
• One character per image pixel. Print a space (' ') for pixel value <grey-levels>-1 (\white"), and a \number" character ('#') for value 0 (\black"). If there are three grey levels, use a dot ('.') for value 1. If there are four grey levels, use a colon (':') for 1 and a dot for 2.
• Print a new-line character at the end of every line.
For example, the run-length encoding for the image shown in Figure 1 is 6 5 4 0 2 3 2 0 5 1 2 2 2 3 1 2 4 1 3 0 6 3 2 1 1
This is in the file Practice.run and the image is shown in Practise.img
## ## ###::.
. ....
:::### ### :
Figure 1: Example Image Result of run-length encoding
Your code should test the run length encoded file as an input when run for example
./Gilbert-image -i Practice.run -m display Or to save the image out too
./Gilbert-image -i Practice.run -m display -o OutputPractice.run Or to give an error when the incorrect commands are typed in
./Gilbert-image -i Practice.run or ./Gilbert-image -m display
You will need to send an argument to your program through the argv/argc commands. This means you will probably need to run your program from the terminal and command line.
Test your code using the encoded test examples thoroughly and you should obtain the same result as the original image in Figure 1. Note no other messages are required on the screen
Your code should use functions, arrays, io streams and all other items you learnt over the course so far. Then thoroughly debug and test your program and ensure you have written the comment blocks into the source code.
Submit through SurreyLearn Assignments for this part a single <SURNAME>-image.c file, where <SURNAME> is replaced with your surname. For example, if your surname is ``SMITH, you need to name the file as follows: SMITH-image.c
I would recommend writing your program in Visual studio code and compiling it through the command line using
clang -ansi -Wall Gilbert-image.c -o Gilbert-image
and running it with
Gilbert-image -i Practice.run -o display
This should display the image on the screen
Note the word after -i <FILENAME> is the input file and the word after -o is the function for the program to run (in this example display the image)
To debug your program you should call your program with
./Gilbert-image < Practice.run > Practice.new
Your program should provide the same output as the original and you can compare with the linux command diff
diff Practice.new Practice.img
Part 2 - Convert to a binary image
For this part you should adapt your code to convert the image into a binary image.
It is sometimes convenient to convert an image with multiple grey-levels into a binary image, based on a threshold t. t should be a user inputted via the command line variable that will need to checked is valid and acceptable.
To transform the runlength encoded image with 4 greylevels into a binary image, you would need to loop over the entire image and replace each gray values by 0 if image(i,j)<t and 1 if image (i,j)>=t.
• Print a space (' ') for pixel value 1 (\white"), and a \number" character ('#') for value 0 (\black").
The resulting binary image should be displayed on the standard output and if the -o option is specified in the command line, the resulting binary image should be saved as a text file to a specified file also.
To aid with this part given the same run-length encoding input of 6 5 4 0 2 3 2 0 5 1 2 2 2 3 1 2 4 1 3 0 6 3 2 1 1
Figure 2, indicates the desired result on the screen if t is set to 2, this result is shown in Practice2.img
t=2
## ## #####
###### ### #
Figure 3: Example Binary Image Result of run-length encoding, t=2
To run this program you can type
Gilbert-image -i Practice2.run -m binary 2 -o Output.runresult
The resulting run-length saved file should look like 6 5 2 0 2 1 2 0 7 1 7 0 9 1 2 0 1
This should be saved in a file called Output.runresult.
DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma
Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t
Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of