void rnlfiltblock_sum( const double *A, double *B, const int d, const int mrows, const int ncols )
{
    int i;
    double m;
    
    int Aoffset, Boffset;
    int coli, blocki;
    int nblocks;
    
    /* get dimensions of blocks */
    nblocks = mrows / d;

    /* scan over all columns */
    for( coli=0; coli<ncols; coli++ ) {
        Aoffset = mrows * coli;
        Boffset = nblocks * coli;
        
        /* for each column, scan over all blocks */
        for(blocki=0; blocki<nblocks; blocki++ ) {
            arraysum( A, m, Aoffset, Aoffset+d-1, i ); 
            B[Boffset] = m;
            Aoffset += d;
            Boffset += 1;
        }
     }
}
        int maxSubArray2(const int * A, int b, int e) {
            if (b == e) return A[b];

            int m = b+(e-b)/2;
            int mleft  = maxSubArray2(A, b, m);
            int mright = maxSubArray2(A, m+1, e);
            int mcross = arraysum(A, b, m, e);
            return mleft>mright?(mleft>mcross?mleft:mcross):(mright>mcross?mright:mcross);
        }
Beispiel #3
0
/*******************************************************************************
* Row non-linear seperable filter - sum (see nlfiltersep.m)
*  x = nlfiltersep_sum( [ 1 9; 5 9; 0 0; 4 8; 7 3; 2 6], 1, 1 )
*  y = [6 18; 6 18; 9 17; 11 11; 13 17; 9 9]; x-y
* B(i,j) is the sum of A(i-r1:i+r2,j). It has the same dims as A.
* This can be implemented effiicently because:
*  B[i] = B[i-1] + A[i+r2] - A[i-r1-1];
* Does not work for initial (r1+1) and final r2 values in each row.
*******************************************************************************/
void nlfiltersep_sum( const double *A, double *B, int r1, int r2, int mRows, int nCols ) {
  int i, row0, e, s, r, c; double m;
  for( c=0; c<nCols; c++ ) {
    row0 = mRows * c;
    /* leading border calculations */
    for(r=0; r<=mini(r1, mRows-1); r++) {
      e = mini( r+r2, mRows-1 );
      arraysum( A, m, row0, row0+e, i );
      B[r+row0] = m;
    }
    /* main caclulations */
    for(r=r1+1; r<mRows-r2; r++) {
      B[r+row0] = B[r+row0-1] + A[r+row0+r2] - A[r+row0-r1-1];
    }
    /* end border calculations */
    for(r=maxi(mRows-r2, 0); r<mRows; r++) {
      s = maxi( r-r1, 0 );
      arraysum( A, m, s+row0, mRows-1+row0, i );
      B[r+row0] = m;
    }
  }
}