2 ***********************************************************
3 $SNARK_Header: S N A R K 1 4 - A PICTURE RECONSTRUCTION PROGRAM $
4 $HeadURL: svn://dig.cs.gc.cuny.edu/snark/trunk/src/snark/bsmooth.cpp $
5 $LastChangedRevision: 85 $
6 $Date: 2014-07-02 16:07:08 -0400 (Wed, 02 Jul 2014) $
8 ***********************************************************
10 A NINE-POINT WEIGHTED, NON-LINEAR SMOOTHING PROCEDURE.
11 FOR DETAILS, SEE THE SNARK MANUAL.
22 void Blob_class::bsmooth(
24 INTEGER M, // number of rows
25 INTEGER H, // number of columns
26 REAL thresh, // treshold
27 REAL w1, // weight of center
28 REAL w2 // weight of horizontal and diag neighbous
31 REAL w3 = w2; // weight of diagonal neighbous
32 REAL* row1 = new REAL[M]; // row buffer 1
33 REAL* row2 = new REAL[M]; // row buffer 2
34 REAL* pres = row2; // current row before smooth
35 REAL* prev = row1; // previous row before smooth
42 BOOLEAN once = TRUE; // message flag
44 REAL centre; // curent grid point value
46 REAL smuth; // weighted sum of neighbours
47 REAL divide; // sum of weights
48 REAL value; // neighbour value
50 lhf = (INTEGER) (-1 * (INTEGER) (H / 2));
51 lhl = (INTEGER) ((H - 1) / 2);
53 lmf = -1 * (INTEGER) (M / 2);
54 lml = (INTEGER) ((M - 1) / 2);
56 for (h = lhl; h >= lhf; h--)
58 REAL* itemp = prev; // swap the buffers (necessary?)
62 for (m = lmf; m <= lml; m++)
63 { // m and h must have the same parity!!
78 { // if not first column
79 value = prev[m1 - 1]; // prev row prev column #1
81 if ((REAL) fabs(value - centre) <= thresh)
89 { // if not last column
90 value = prev[m1 + 1]; // prev row, next column #2
92 if ((REAL) fabs(value - centre) <= thresh)
101 { // if not first or second column
102 value = pres[m1 - 2]; // same row, two prev column #3
104 if ((REAL) fabs(value - centre) <= thresh)
112 { // if not last column or one before last one
113 value = a[ind + 2]; // same row, two next column #4
115 if ((REAL) fabs(value - centre) <= thresh)
125 { // if not first column
126 value = a[ind - M - 1]; // next row prev column #5
128 if ((REAL) fabs(value - centre) <= thresh)
136 { // if not last column
137 value = a[ind - M + 1]; // next row next column #6
139 if ((REAL) fabs(value - centre) <= thresh)
147 if ((REAL) fabs(divide) > Consts.zero)
149 a[ind] = smuth / divide;
155 fprintf(output, "\n *** warning - sum of weights=zero");
160 ((smuth - Consts.infin) > 0) ? (REAL) 1.0 :
161 (smuth == Consts.infin) ? (REAL) 0.0 : (REAL) -1.0;
169 delete[] row1; // bug 92 - Lajos - 03/02/2005
170 delete[] row2; // bug 92 - Lajos - 03/02/2005