diff options
author | Leo Chan <leochanj@live.unc.edu> | 2020-10-22 01:53:21 -0400 |
---|---|---|
committer | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-22 01:56:35 -0400 |
commit | d17b33131c14864bd1eae275f49a3f148e21cf29 (patch) | |
tree | 0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/benchmarks/tracking/src/c/calcAreaSum.c | |
parent | 601ed25a4c5b66cb75315832c15613a727db2c26 (diff) |
Squashed commit of the sb-vbs branch.
Includes the SD-VBS benchmarks modified to:
- Use libextra to loop as realtime jobs
- Preallocate memory before starting their main computation
- Accept input via stdin instead of via argc
Does not include the SD-VBS matlab code.
Fixes libextra execution in LITMUS^RT.
Diffstat (limited to 'SD-VBS/benchmarks/tracking/src/c/calcAreaSum.c')
-rw-r--r-- | SD-VBS/benchmarks/tracking/src/c/calcAreaSum.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/tracking/src/c/calcAreaSum.c b/SD-VBS/benchmarks/tracking/src/c/calcAreaSum.c new file mode 100644 index 0000000..40f03dc --- /dev/null +++ b/SD-VBS/benchmarks/tracking/src/c/calcAreaSum.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include "tracking.h" | ||
6 | |||
7 | /** Compute the sum of pixels over pixel neighborhood. | ||
8 | Neighborhood = winSize*winSize | ||
9 | This will be useful when we compute the displacement | ||
10 | of the neighborhood across frames instead of tracking each pixel. | ||
11 | |||
12 | Input: src Image | ||
13 | # rows, cols, size of window | ||
14 | Output: windowed-sum image, ret. | ||
15 | |||
16 | Example: | ||
17 | |||
18 | winSize = 4, cols = 8, rows = 16 | ||
19 | nave_half = 2, nave = 4 | ||
20 | Say, the first row of the image is: | ||
21 | 3 8 6 2 4 8 9 5 | ||
22 | a1 = 0 0 3 8 6 2 4 8 9 5 0 0 (append nave_half zeros to left and right border) | ||
23 | asum = (sum the first nave # pixels - 0 0 3 8 ) = 11 | ||
24 | ret(0,0) = 11 | ||
25 | For ret(0,1), we need to move the window to the right by one pixel and subtract | ||
26 | from a1sum the leftmost pixel. So, we add value 6 and subtract value at a1(0,0), = 0 here. | ||
27 | ret(0,1) = 17 = a1sum | ||
28 | For ret(0,2), a1sum - a1(0,1) + a1(2+nave) = 17 - 0 + 2 = 19 = a1sum | ||
29 | For ret(0,3), a1sum - a1(0,2) + a1(3+nave) = 19 - 3 + 4 = 20 = a1sum | ||
30 | |||
31 | We proceed this way for all the rows and then perform summantion across all cols. | ||
32 | **/ | ||
33 | F2D* calcAreaSum(F2D* src, int cols, int rows, int winSize) | ||
34 | { | ||
35 | int nave, nave_half, i, j, k; | ||
36 | F2D *ret, *a1; | ||
37 | float a1sum; | ||
38 | |||
39 | nave = winSize; | ||
40 | nave_half = floor((nave+1)/2); | ||
41 | |||
42 | ret = fMallocHandle(rows, cols); | ||
43 | a1 = fSetArray(1, cols+nave,0); | ||
44 | |||
45 | for(i=0; i<rows; i++) | ||
46 | { | ||
47 | for(j=0; j<cols; j++) { | ||
48 | asubsref(a1,j+nave_half) = subsref(src,i,j); | ||
49 | } | ||
50 | a1sum = 0; | ||
51 | for(k=0; k<nave; k++) { | ||
52 | a1sum += asubsref(a1,k); | ||
53 | } | ||
54 | for(j=0; j<cols; j++) | ||
55 | { | ||
56 | subsref(ret,i,j) = a1sum; | ||
57 | a1sum += asubsref(a1,j+nave) - asubsref(a1,j); | ||
58 | } | ||
59 | } | ||
60 | fFreeHandle(a1); | ||
61 | |||
62 | a1 = fSetArray(1, rows+nave,0); | ||
63 | for(i=0; i<cols; i++) | ||
64 | { | ||
65 | for(j=0; j<rows; j++) { | ||
66 | asubsref(a1,j+nave_half) = subsref(ret,j,i); | ||
67 | } | ||
68 | a1sum = 0; | ||
69 | for(k=0; k<nave; k++) { | ||
70 | a1sum += asubsref(a1,k); | ||
71 | } | ||
72 | for(j=0; j<rows; j++) | ||
73 | { | ||
74 | subsref(ret,j,i) = a1sum; | ||
75 | a1sum += asubsref(a1,j+nave) - asubsref(a1,j); | ||
76 | } | ||
77 | } | ||
78 | fFreeHandle(a1); | ||
79 | |||
80 | return ret; | ||
81 | } | ||