Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Nearest neighbour algorithm. Expands an 8x8 matrix into a 15x15 matrix.
- float n_map[8][8]; // Read the data from the sensor into this matrix.
- float e_map[15][15]; // Holds the resulting matrix data.
- int size = 8;
- int e_size = 15;
- // In the loop
- int r=0;
- int c=0;
- int i=0;
- int j=0;
- // Load the 8x8 data into the target matrix.
- // Data from even numbered rows are loaded into positions 0,2,4,6,8,10,12,14
- // Odd numbered rows remain empty.
- for (r=0; r < size; r++){
- for(c=0; c < size; c++){
- e_map[(r+j)][(c+i)] = (float)n_map[r][(c)];
- ++i;
- }
- i=0;
- j++;
- }
- // Fill in the blanks as the average of the nearest neighbours.
- // e_map will hold the expanded matrix. matrix holds the serialized data as a string.
- for (r=0; r<e_size; r++){
- for(c=0; c < e_size; c++){
- if ((c % 2 != 0) && (c < (e_size-1))) {
- e_map[r][c] = (float)((e_map[r][c-1] + e_map[r][c+1]) / 2);
- }
- if ((r % 2 != 0) && (r < (e_size-1))) {
- e_map[r][c] = (float)((e_map[r-1][c] + e_map[r+1][c] ) / 2);
- }
- // This section is only used to serialize the data into a string.
- if ((c==0) && (r == 0)){
- matrix = e_map[r][c];
- } else {
- matrix = matrix + ", " + e_map[r][c];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement