logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

you should write a program that reads and prints an image, where the input image is run-length encoded.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

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

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

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. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

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

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

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

. 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 Sea Ports. Here are the classes and their instance variables we wish to define:

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

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

620 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

843 Answers

Hire Me
expert
Husnain SaeedComputer science

915 Answers

Hire Me
expert
Atharva PatilComputer science

907 Answers

Hire Me
April
January
February
March
April
May
June
July
August
September
October
November
December
2025
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
SunMonTueWedThuFriSat
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
00:00
00:30
01:00
01:30
02:00
02:30
03:00
03:30
04:00
04:30
05:00
05:30
06:00
06:30
07:00
07:30
08:00
08:30
09:00
09:30
10:00
10:30
11:00
11:30
12:00
12:30
13:00
13:30
14:00
14:30
15:00
15:30
16:00
16:30
17:00
17:30
18:00
18:30
19:00
19:30
20:00
20:30
21:00
21:30
22:00
22:30
23:00
23:30