Part 1: Read and Print an Image (40 marks)
In part 1 you should write a program that reads and prints an image, where the input image is run-length encoded.
Firstly, cd to your eeclabs directory. Then download the input files for part 1 into this directory from SurreyLearn. This should include the run-length encoded image file panda.run and the original image panda.img.
Then write your program in the file image1.c. It should take the run-length encoded image from the standard input, and print the image to standard output. 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. Following the image pixels in ‘‘raster-scan’’ order, illustrated in Figure 1:
Figure 1: Raster scan order starts at the top-left of the image (row 1), and follows each row to the end, before dropping to the next row.
The format of the run-length encoded image is:
.....
where all the <...>’s represent integer values. White-space (spaces and/or new-line characters) separate the values.
is the width of the image in pixels. The limit on width is 80 pixels.
is the height of the image in pixels. The limit on height is 100 pixels.
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,..., −1. The maximum value for is 4. The limits on , and apply to all parts of the assignment.
is the grey level pixel value of the first pixel on the first row of the image, i.e. the top-left pixel.
is the number of times that the first pixel is repeated, following the image pixels in raster- scan order.
is the grey level pixel value of the next pixel, i.e. the first pixel different from .
is the number of times that is repeated.
...... the list of , pairs continuing to the end of the image in the bottom-right hand corner.
The sum of the s is equal to *. Once you have read the image into your program, print it to standard output. The format is as follows:
One character per image
Print a space (‘ ’) for pixel value −1 (white), and a number character (‘#) for value 0 (“black”).
If there are three grey levels, use a dot (‘.’) for value
If there are four grey levels, use a colon (‘:’) for 1 and a dot (‘.’) for
Print a new-line character at the end of every
For example, the run-length encoding for the image shown in Figure 2 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
Figure 2: Example image (see text).
Compile your program using the command
gcc -ansi -Wall image1.c -o image1
Test it using the encoded test image panda.run:
./image < panda.run
You should obtain the output shown in figure 3.
Figure 3: Output image for part 1 from file panda.run.
This corresponds to the same result as the original image in the file panda.img. To determine differences between your output and the correct output, perform the following test:
./image < panda.run > panda.new diff panda.img panda.new
This will compare the two files and print out any differences. If nothing is printed it means that the two files are identical, which is what you want.
When you have thoroughly debugged and tested your program (image1.c), re-name your file ac- cording to the following specification and then submit the code to SurreyLearn.
SPEC: The name of the submitted file MUST be proceeded with your surname and initial followed by the name of the program. For example, if your surname is “Brown”, and your first name is “Peter”, you need to name the file as follows:
BROWNP-image1.c
The first part is your surname and initial followed by a hyphen, and then followed by the original filename (image1.c). If you also have middle names, ignore them in the file name.
Similarly, if your surname is “Jackson”, and your first name is “Tony”, you need to name the file as follows:
JACKSONT-image1.c
Part 2: Edge detection (30 marks)
Download the input files for part 2 from SurreyLearn.
This should include the run-length encoded image file balloon.run, the original image bal- loon.img and the edge detected image (i.e. the gradient image) balloon.grad. Copy the program image1.c from part 1 into a new file image2.c and modify the new program to apply an image processing algorithm, edge detection to the image, which locates boundaries in the image. You will only have to implement the first part of the edge detector, which computes the gradient of the image.
We shall compute the gradient as follows:
Figure 4: Configuration of adjacent pixels for gradient computation.
Let p1, p2, p3, p4 be adjacent pixels with p2 to the right of p1, p3 below p1, and p4 below p2, i.e. to the right of p3, as in Figure 4. For each such set of four pixels, the gradient is computed along four directions: horizontal, vertical, positive diagonal (top-left to bottom-right) and negative diagonal (top-right to bottom-left). Then the gradient value is set to the highest of the gradient values computed along the four directions.
The formulae for the gradients is:
gh = abs((p1 − p2 + p3 − p4)/2), gp = abs(p1 − p4)
gv = abs((p1 − p3 + p2 − p4)/2), gn = abs(p2 − p3)
where abs() signifies the absolute value function.
Note that the resulting gradient “image” has one less row and column than the original image. For the sake of clarity, reverse the grey-levels when printing the result, so that ‘ ’ corresponds to pixel value zero, ‘.’ to one etc (this reversal applies only to this section). The original image (with 4 grey levels) is included in the file balloon.img so that you can check that you are decoding the image correctly. The gradient image is in balloon.grad. Check for differences using the diff command as above.
When you have thoroughly debugged and tested your program (image2.c), re-name your file ac- cording to the following specification and then submit the program to SurreyLearn.
SPEC: The name of the submitted file MUST be proceeded with your surname and initial followed by the name of the program. For example, if your surname is “Brown”, and your first name is “Peter”, you need to name the file as follows:
BROWNP-image2.c
The first part is your surname and initial followed by a hyphen, and then followed by the original filename (image2.c). If you also have middle names, ignore them in the file name.
Similarly, if your surname is “Jackson”, and your first name is “Tony”, you need to name the file as follows:
JACKSONT-image2.c
Part 3: antialiasing (30 marks)
Download the input files for part 2 from SurreyLearn.
This should include the files skull.run, skull.img, skull.double and skull.aa.
Copy the program from part 1 (image1.c) into a new file image3.c. The goal here is to write a program that doubles the size of an image while smoothing out the boundaries in the image. First modify it to double the size of the image, in the following way.
The new image width will be 2 ∗ − 1 and the new height will be 2 ∗ − 1. It will have four grey levels instead of the two in the input image, so firstly convert pixels with value 1 to have value 3 (zero values stay at zero). The new pixels are then introduced between the old ones as shown in Figure 5.
Figure 5: Arrangement of pixels in double-sized image.
The way the new pixels are computed is as follows:
If a new pixel coincides with an old pixel (e.g. pixel (1) in Figure 5, set the new pixel value to the corresponding old pixel
If a new pixel lies between two old pixels horizontally (e.g. pixel (2) in Figure 5) set the new pixel value to the average of the two corresponding old pixels. Here the “average” of two values a and b is defined as (a + b)/2 using the C language integer
If a new pixel lies between two old pixels vertically (e.g. pixel (3) in Figure 5) set the new pixel value to the average of the two corresponding old
If a new pixel lies between four old pixels (e.g. pixel (4) in Figure 5) set the new pixel value to the average of the four corresponding old pixels. Here the “average” of four values a, b, c and d is defined as (a + b + c + d + 1)/4 using the C language integer
Once this is done, compare the output with the correct version in the file skull.double. The original image is in skull.img.
Finally, change the program to smooth the double-sized image before printing it. Smoothing is performed by repeated local averaging of pixel values. Each pixel pij in the (double-sized) image is replaced by the pixel value
1 .pi−1 j−1 + 2pi−1 j + pi−1 j+1 Σsij = 16+ 2pi j−1 + 4pi j + 2pi j+1+pi+1 j−1 + 2pi+1 j + pi+1 j+1 + 7
(3)(NOTE: the term in brackets is not a vector or a matrix; merely the sum of ten numbers). Pixels at the edge of the image are copied directly into the smoothed image without smoothing. Finally the smoothed image pixels sij are copied back into the original pij, completing a single iteration of smoothing. Do three smoothing iterations in total. The output should be identical to the correct result in the file skull.aa.
When you have thoroughly debugged and tested your program (image3.c), re-name your file ac- cording to the following specification and then submit the program to SurreyLearn.
SPEC: The name of the submitted file MUST be proceeded with your surname and initial followed by the name of the program. For example, if your surname is “Brown”, and your first name is “Peter”, you need to name the file as follows:
BROWNP-image3.c
The first part is your surname and initial followed by a hyphen, and then followed by the original filename (image3.c). If you also have middle names, ignore them in the file name.
Similarly, if your surname is “Jackson”, and your first name is “Tony”, you need to name the file as follows:
JACKSONT-image3.c
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