Changeset 42888 for trunk/psLib/src/math/psVectorSmooth.c
- Timestamp:
- Jun 5, 2025, 3:30:24 PM (14 months ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psVectorSmooth.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psVectorSmooth.c
r31660 r42888 1 1 #ifdef HAVE_CONFIG_H 2 # include "config.h"2 #include "config.h" 3 3 #endif 4 4 … … 15 15 #include "psAssert.h" 16 16 #include "psConstants.h" 17 #include "psStats.h" 17 18 18 19 #include "psVectorSmooth.h" … … 122 123 psVector *psVectorBoxcar(psVector *output, 123 124 const psVector *input, 124 int size 125 )125 int size, 126 bool robust) 126 127 { 127 128 PS_ASSERT_VECTOR_NON_NULL(input, NULL); … … 136 137 output = psVectorRecycle(output, num, input->type.type); 137 138 psVector *nums = psVectorAlloc(num, PS_TYPE_U32); // Number of elements in each bin 138 psU32 *numsData = nums->data.U32; // Dereferenced version139 139 140 140 psVectorInit(output, 0.0); … … 147 147 ps##TYPE *outputData = output->data.TYPE; \ 148 148 ps##TYPE *inputData = input->data.TYPE; \ 149 /* Smooth the vector */ \ 150 for (long i = 0; i < num; i++) { \ 151 for (long j = PS_MAX(0, i - size); j < PS_MIN(num, i + size + 1); j++) { \ 152 outputData[j] += inputData[i]; \ 153 numsData[j]++; \ 154 } \ 155 } \ 156 /* Normalisation */ \ 157 for (long i = 0; i < num; i++) { \ 158 outputData[i] /= numsData[i]; \ 159 } \ 160 break; \ 149 /* Smooth the vector */ \ 150 for (long i = 0; i < num; i++) \ 151 { \ 152 /* sample within the window size */ \ 153 int windowSize = PS_MIN(num, i + size + 1) - PS_MAX(0, i - size); \ 154 psVector *sample = psVectorAlloc(windowSize, PS_TYPE_##TYPE); \ 155 ps##TYPE *sampleData = sample->data.TYPE; \ 156 /* extract sample from inputData */ \ 157 for (long j = PS_MAX(0, i - size); j < PS_MIN(num, i + size + 1); j++) \ 158 { \ 159 sampleData[j - PS_MAX(0, i - size)] = inputData[j]; \ 160 } \ 161 /* find the desired statistic from the sample */ \ 162 psStatsOptions statistic; \ 163 psStats *stats; \ 164 if (robust) \ 165 { \ 166 statistic = PS_STAT_CLIPPED_MEDIAN; \ 167 stats = psStatsAlloc(statistic); \ 168 stats->clipSigma = 2.5; \ 169 } \ 170 else \ 171 { \ 172 statistic = PS_STAT_SAMPLE_MEDIAN; \ 173 stats = psStatsAlloc(statistic); \ 174 } \ 175 if (!psVectorStats(stats, sample, NULL, NULL, 0)) \ 176 { \ 177 psError(PS_ERR_UNKNOWN, false, "failure to measure stats"); \ 178 psFree(sample); \ 179 psFree(stats); \ 180 return NULL; \ 181 } \ 182 outputData[i] = psStatsGetValue(stats, statistic); \ 183 psFree(sample); \ 184 psFree(stats); \ 185 } \ 186 break; \ 161 187 } 162 188
Note:
See TracChangeset
for help on using the changeset viewer.
