Collaboration

advertisement
Programming Assignment 1
Pictures From Space
Due: Monday, October 1st, 9:00 am
How are pictures sent from the Mariner spacecraft back to earth? The spacecraft records the
image internally as a sequence of 0's and 1's, and then sends the information back to earth. Even
at the speed of light, the data may take several minutes to reach earth, and during its journey the
signal gets somewhat garbled. By building redundancy into the signal, scientists back on earth
can recover the original image free of any errors. Error correcting codes are one technique for
ensuring Information System consistency and building in the appropriate redundancy.
Your goal is to write a program to correct errors in a transmission using the Hadamard error
correction code. Each pixel of the image is represented by one of 32 possible gray-scale levels
from 0 (white) to 31 (black). In real life, each pixel could be represented by three RGB color
values, each in the range from 0 to 255. We could represent each pixel in binary, using 5 bits.
For example, if the spacecraft observed the gray-scale level of a pixel to be 13, it could send the
signal:
01101.
Instead, for reasons that will become clear, we'll use the less obvious 32 bit encoding:
10100101010110101010010101011010.
When the pattern arrives at the telemetry receiving station on earth, the bit pattern might have
been mangled to:
10000101010101101010000001011010
*
**
* *
where the asterisks denote errors that have occurred during transmission. Because we encode
each gray scale value with 32 bits instead of 5, there is some hope of identifying the errors and
recovering the original message intact. A little bit of mathematical magic is needed.
Hadamard code. The N x N Hadamard matrix is an N x N table of 0's and 1's with a very
special property: every two rows differ in exactly N / 2 places. The Hadamard matrices for N =
1, 2, 4, 8, 16, and N = 32 are shown below, where white represents 0 and black represents 1.
Note that row 13 (start counting from 0 as usual) of the order 32 Hadamard matrix is
10100101010110101010010101011010
which explains why we chose that encoding for gray-scale level 13 above. In general, the 2N x
2N Hadamard matrix is constructed by aligning 4 copies of the N x N Hadamard matrix in the
form of a large square, and then inverting all of the entries in the lower right N x N copy.
Now, when a 32 bit codeword is received on earth, it is compared with each of the rows of the 32
x 32 Hadamard matrix until a "match" is found. If no errors were made in transmission, then the
codeword will perfectly match (exactly) one of the rows. Otherwise, we choose the row in the
Hadamard matrix that it most closely resembles, i.e., the number of bits the two have in
common. If there was one error made in transmission, then the codeword will differ from one of
the Hadamard rows in exactly one place. It will differ from every other row in at least 15 places,
so there is no mistaking a match! Why? The Hadamard property guarantees that every two rows
of the matrix differ in at least 16 places, so if the codeword is one bit away from one row, it must
be 15 (or more) away from every other row. A similar thing happens if there are two, three, or
even seven errors. However, if 8 errors occur, then the codeword may be 8 places away from an
"incorrect" row.
Copyright © 2000 Robert Sedgewick
Goals of the assignment
Programming language: Java or C++
Data set: Generate and store on computer your own “Picture from the Space” fo Hadamard 32by 32
matrix. First create correct original binary version [2p]. You input would look something like this:
Colour white- gray-scale level 0
Colour 1- gray-scale level 1
Colour black –gray-scale level 31
Colour 13 –gray-scale level 13
Or in a binary system:
11111111111111111111111111111111
10101010101010101010101010101010
10010110011010010110100110010110
10100101010110101010010101011010
Next, automatically invert some pixels (for simplicity, keeping the number of inversions/errors from 0 to
7) and use this as test data [2p]
Your program must [16]:
1. Read test binary file from an input [2p], apply Hadamard algorithm [4p] and produce a corrected
binary file, correcting all mistakes in each line (save it) [2p]
2. Use a 32-bit grey-color image as an input and produce a corrected image (for simplicity, the
image size could be relatively small) [3p]
3. Properly describe all data structure/use optimal algorithm if possible (not waste space or
running time) [3p]
4. Provide in-line documentation [2p]
What to submit
Submit code, named and prepared according to your TA specification, together with test data
description, sample data and images, and written part answers.
Bonuses for extra credit [up to 6p]:
1. Allow for 8 mistakes in the code and provide test data [1p]
2. Implement 256 to 256 matrix (i.e. allow true RGB colors) [2p]
3. Challenge for the bored: use any real NSSDC picture from web site below (one example is given
following the link) to test your system [3].
http://nssdc.gsfc.nasa.gov/imgcat/html/mission_page/MR_Mariner_9_page1.html
Written Report [6p]
Written report is an essential part of your assignment. Type and submit an electronic report (1-2 pages)
following submission instructions posted on the web site that includes the following:
1. Samples of input data, including both binary and test images generated by you [2p].
2. Estimate of your program performance: how much memory, how fast it works [2p]
4. Analysis (theoretical) of how going from 32 by 32 to 256 by 256 Hadamard matrix could impact
your program performance (significantly or not significant, memory and processing time
requirements) [2p].
Hand in
Submit your source code and the electronic report according to your TA instructions. Course late
assignment policy allows for up to 2 days late submission, based on the date and time it is received by
your TA, with 10% of your mark penalty for each late day.
Marking
Assignment grades will be based on the two submitted components as described in this assignment
and/or the marking sheet (maximum of 22 points plus possible 6 points bonus). Source code that does
not compile or produces run-time errors will receive maximum 3 points. Code that produces incorrect
output will receive a maximum grade of 5 points.
Collaboration
The assignment must be done individually so everything that you hand in must be your original work,
except for the code copied from the text. When someone else's code is used, you must acknowledge the
source explicitly. Copying another student's work is an academic misconduct. Contact your TA if you
have problems getting your code to work.
Download