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/common/c/imageResize.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/common/c/imageResize.c')
| -rw-r--r-- | SD-VBS/common/c/imageResize.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/SD-VBS/common/c/imageResize.c b/SD-VBS/common/c/imageResize.c new file mode 100644 index 0000000..72c0881 --- /dev/null +++ b/SD-VBS/common/c/imageResize.c | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include "sdvbs_common.h" | ||
| 6 | |||
| 7 | F2D* imageResize(F2D* imageIn) | ||
| 8 | { | ||
| 9 | int m, k, rows, cols; | ||
| 10 | F2D *imageOut; | ||
| 11 | I2D *kernel; | ||
| 12 | float tempVal; | ||
| 13 | int kernelSize, startCol, endCol, halfKernel, startRow, endRow, i, j, kernelSum; | ||
| 14 | int outputRows, outputCols; | ||
| 15 | F2D *temp; | ||
| 16 | |||
| 17 | rows = imageIn->height; | ||
| 18 | cols = imageIn->width; | ||
| 19 | |||
| 20 | // level 1 is the base image. | ||
| 21 | |||
| 22 | outputRows = floor((rows+1)/2); | ||
| 23 | outputCols = floor((cols+1)/2); | ||
| 24 | |||
| 25 | temp = fSetArray(rows, outputCols, 0); | ||
| 26 | imageOut = fSetArray(outputRows, outputCols, 0); | ||
| 27 | kernel = iMallocHandle(1, 5); | ||
| 28 | |||
| 29 | asubsref(kernel,0) = 1; | ||
| 30 | asubsref(kernel,1) = 4; | ||
| 31 | asubsref(kernel,2) = 6; | ||
| 32 | asubsref(kernel,3) = 4; | ||
| 33 | asubsref(kernel,4) = 1; | ||
| 34 | kernelSize = 5; | ||
| 35 | kernelSum = 16; | ||
| 36 | |||
| 37 | startCol = 2; | ||
| 38 | endCol = cols - 2; | ||
| 39 | halfKernel = 2; | ||
| 40 | |||
| 41 | startRow = 2; | ||
| 42 | endRow = rows - 2; | ||
| 43 | |||
| 44 | for(i=startRow; i<endRow; i++) | ||
| 45 | { | ||
| 46 | m = 0; | ||
| 47 | for(j=startCol; j<endCol; j+=2) | ||
| 48 | { | ||
| 49 | tempVal = 0; | ||
| 50 | for(k=-halfKernel; k<=halfKernel; k++) | ||
| 51 | { | ||
| 52 | tempVal += subsref(imageIn,i,j+k) * asubsref(kernel,k+halfKernel); | ||
| 53 | } | ||
| 54 | subsref(temp,i,m) = tempVal/kernelSum; | ||
| 55 | m = m+1; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | m = 0; | ||
| 60 | for(i=startRow; i<endRow; i+=2) | ||
| 61 | { | ||
| 62 | for(j=0; j<outputCols; j++) | ||
| 63 | { | ||
| 64 | tempVal = 0; | ||
| 65 | for(k=-halfKernel; k<=halfKernel; k++) | ||
| 66 | { | ||
| 67 | tempVal += subsref(temp,(i+k),j) * asubsref(kernel,k+halfKernel); | ||
| 68 | } | ||
| 69 | subsref(imageOut,m,j) = (tempVal/kernelSum); | ||
| 70 | } | ||
| 71 | m = m+1; | ||
| 72 | } | ||
| 73 | |||
| 74 | fFreeHandle(temp); | ||
| 75 | iFreeHandle(kernel); | ||
| 76 | return imageOut; | ||
| 77 | |||
| 78 | } | ||
