Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -: 0:Source:calcAreaSum.c
- -: 0:Graph:calcAreaSum.gcno
- -: 0:Data:calcAreaSum.gcda
- -: 0:Runs:1
- -: 0:Programs:1
- -: 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:**/
- 3: 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;
- 3: 40: nave_half = floor((nave+1)/2);
- -: 41:
- 3: 42: ret = fMallocHandle(rows, cols);
- 3: 43: a1 = fSetArray(1, cols+nave,0);
- -: 44:
- 3243: 45: for(i=0; i<rows; i++)
- -: 46: {
- 6220800: 47: for(j=0; j<cols; j++) {
- 6220800: 48: asubsref(a1,j+nave_half) = subsref(src,i,j);
- -: 49: }
- -: 50: a1sum = 0;
- 155520: 51: for(k=0; k<nave; k++) {
- 155520: 52: a1sum += asubsref(a1,k);
- -: 53: }
- 6220800: 54: for(j=0; j<cols; j++)
- -: 55: {
- 6220800: 56: subsref(ret,i,j) = a1sum;
- 6220800: 57: a1sum += asubsref(a1,j+nave) - asubsref(a1,j);
- -: 58: }
- -: 59: }
- 3: 60: fFreeHandle(a1);
- -: 61:
- 3: 62: a1 = fSetArray(1, rows+nave,0);
- 5763: 63: for(i=0; i<cols; i++)
- -: 64: {
- 6220800: 65: for(j=0; j<rows; j++) {
- 6220800: 66: asubsref(a1,j+nave_half) = subsref(ret,j,i);
- -: 67: }
- -: 68: a1sum = 0;
- 276480: 69: for(k=0; k<nave; k++) {
- 276480: 70: a1sum += asubsref(a1,k);
- -: 71: }
- 6220800: 72: for(j=0; j<rows; j++)
- -: 73: {
- 6220800: 74: subsref(ret,j,i) = a1sum;
- 6220800: 75: a1sum += asubsref(a1,j+nave) - asubsref(a1,j);
- -: 76: }
- -: 77: }
- 3: 78: fFreeHandle(a1);
- -: 79:
- 3: 80: return ret;
- -: 81:}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement