PandA-2024.02
boxfilter.c
Go to the documentation of this file.
1 #define DIMENSION_X 1000
2 #define DIMENSION_Y 8
3 
4 #include <stdio.h>
5 #include "boxfilter.h"
6 
7 
8 // The values of the 3x3 box to filter with.
9 /*
10  * 1 2 3
11  * 4 5 6
12  * 7 8 9
13  */
14 //Constant to filter by
15 #define BOX1 3
16 #define BOX2 3
17 #define BOX3 3
18 #define BOX4 3
19 #define BOX5 3
20 #define BOX6 3
21 #define BOX7 3
22 #define BOX8 3
23 #define BOX9 3
24 
26 void filter (int y, int input[][DIMENSION_X] , int * output)
27 {
28  int x;
29  int checksum = 0;
30  for (x = 0; x < DIMENSION_X; x++)
31  {
32  int sum = 0;
33  //ex if at the top left corner of the image, we can only average
34  //the (y,x),(y+1,x),(y+1,x+1),(y,x+1). therefore pixelsAveraged = 4
35  // if we're not at an edge of the image, then pixels averaged is 3x3=9
36  int pixelsAveraged = 1;
37  // Sum them up
38  if (y - 1 >= 0 && x - 1 >= 0)
39  {
40  sum += input[y - 1][x - 1] * BOX1; //top left
41  pixelsAveraged++;
42  }
43  if (y - 1 >= 0 && x + 1 < DIMENSION_X)
44  {
45  sum += input[y - 1][x + 1] * BOX3; //top right
46  pixelsAveraged++;
47  }
48  if (y + 1 < DIMENSION_Y && x + 1 < DIMENSION_X)
49  {
50  sum += input[y + 1][x + 1] * BOX9; //bottom right
51  pixelsAveraged++;
52  }
53  if (y + 1 < DIMENSION_Y && x - 1 >= 0)
54  {
55  sum += input[y + 1][x - 1] * BOX7; //bottom left
56  pixelsAveraged++;
57  }
58  if (y - 1 >= 0)
59  {
60  sum += input[y - 1][x] * BOX2; //top
61  pixelsAveraged++;
62  }
63  if (x - 1 >= 0)
64  {
65  sum += input[y][x - 1] * BOX4; //left
66  pixelsAveraged++;
67  }
68  if (y + 1 < DIMENSION_Y)
69  {
70  sum += input[y + 1][x] * BOX8; //bottom
71  pixelsAveraged++;
72  }
73  if (x + 1 < DIMENSION_X)
74  {
75  sum += input[y][x + 1] * BOX6; //right
76  pixelsAveraged++;
77  }
78  sum += input[y][x]; //centre
79 
80  checksum += sum / pixelsAveraged;
81  }
82  output[y] = checksum;
83 }
84 
85 int main()
86 {
87 
88  int y, x;
89  int result = 0;
90 
91  #pragma omp simd
92  for (y = 0; y < DIMENSION_Y; y++)
93  {
95  }
96 
97  // check the result
98  for (y = 0; y < DIMENSION_Y; y++)
99  {
100  result += checksum_output[y] == checksum_expected[y];
101  }
102 
103  printf ("Result: %d\n", result);
104  if (result == DIMENSION_Y)
105  {
106  printf("RESULT: PASS\n");
107  return 0;
108  }
109  else
110  {
111  printf("RESULT: FAIL\n");
112  return 1;
113  }
114 }
void filter(int y, int input[][DIMENSION_X], int *output)
a 3x3 box filter. Filter an entire row of the matrix in one call.
Definition: boxfilter.c:26
#define BOX2
Definition: boxfilter.c:16
#define BOX6
Definition: boxfilter.c:20
int input[SIZE]
Definition: hash.h:1
int checksum_expected[DIMENSION_Y]
Definition: boxfilter.h:16
#define BOX9
Definition: boxfilter.c:23
#define BOX3
Definition: boxfilter.c:17
uint8_t checksum(uint64_t in1, uint64_t in2)
Definition: checksum.c:5
volatile int output[DIM_Y][DIM_X]
Definition: los.h:1
int sum
Definition: dotproduct.h:3
#define DIMENSION_X
Definition: boxfilter.c:1
#define BOX7
Definition: boxfilter.c:21
int checksum_output[DIMENSION_Y]
Definition: boxfilter.h:14
int result[SIZE]
Definition: adpcm.c:800
#define BOX4
Definition: boxfilter.c:18
#define BOX1
Definition: boxfilter.c:15
#define BOX8
Definition: boxfilter.c:22
int original[DIMENSION_Y][DIMENSION_X]
Definition: boxfilter.h:1
int main()
Definition: boxfilter.c:85
x
Return the smallest n such that 2^n >= _x.
#define DIMENSION_Y
Definition: boxfilter.c:2

Generated on Mon Feb 12 2024 13:02:50 for PandA-2024.02 by doxygen 1.8.13