IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 5, 2025, 3:30:24 PM (14 months ago)
Author:
tdeboer
Message:

updates to stats functions for 2D overscan correction

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psVectorSmooth.c

    r31660 r42888  
    11#ifdef HAVE_CONFIG_H
    2 # include "config.h"
     2#include "config.h"
    33#endif
    44
     
    1515#include "psAssert.h"
    1616#include "psConstants.h"
     17#include "psStats.h"
    1718
    1819#include "psVectorSmooth.h"
     
    122123psVector *psVectorBoxcar(psVector *output,
    123124                         const psVector *input,
    124                          int size
    125                         )
     125                         int size,
     126                         bool robust)
    126127{
    127128    PS_ASSERT_VECTOR_NON_NULL(input, NULL);
     
    136137    output = psVectorRecycle(output, num, input->type.type);
    137138    psVector *nums = psVectorAlloc(num, PS_TYPE_U32); // Number of elements in each bin
    138     psU32 *numsData = nums->data.U32;   // Dereferenced version
    139139
    140140    psVectorInit(output, 0.0);
     
    147147      ps##TYPE *outputData = output->data.TYPE; \
    148148      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;                                                                     \
    161187  }
    162188
Note: See TracChangeset for help on using the changeset viewer.